Alex | 51c8ad4 | 2021-04-15 16:45:15 +0200 | [diff] [blame] | 1 | varnishtest "JSON Query converters Test" |
| 2 | #REQUIRE_VERSION=2.4 |
| 3 | |
| 4 | feature ignore_unknown_macro |
| 5 | |
| 6 | server s1 { |
| 7 | rxreq |
| 8 | txresp |
| 9 | } -repeat 8 -start |
| 10 | |
| 11 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 12 | global |
| 13 | # WT: limit false-positives causing "HTTP header incomplete" due to |
| 14 | # idle server connections being randomly used and randomly expiring |
| 15 | # under us. |
| 16 | tune.idle-pool.shared off |
| 17 | |
Alex | 51c8ad4 | 2021-04-15 16:45:15 +0200 | [diff] [blame] | 18 | defaults |
| 19 | mode http |
| 20 | timeout connect 1s |
| 21 | timeout client 1s |
| 22 | timeout server 1s |
| 23 | option http-buffer-request |
| 24 | |
| 25 | frontend fe |
| 26 | bind "fd@${fe}" |
| 27 | tcp-request inspect-delay 1s |
| 28 | |
| 29 | http-request set-var(sess.header_json) req.hdr(Authorization),json_query('$.iss') |
| 30 | http-request set-var(sess.pay_json) req.body,json_query('$.iss') |
| 31 | http-request set-var(sess.pay_int) req.body,json_query('$.integer',"int"),add(1) |
| 32 | http-request set-var(sess.pay_neg_int) req.body,json_query('$.negativ-integer',"int"),add(1) |
| 33 | http-request set-var(sess.pay_double) req.body,json_query('$.double') |
| 34 | http-request set-var(sess.pay_boolean_true) req.body,json_query('$.boolean-true') |
| 35 | http-request set-var(sess.pay_boolean_false) req.body,json_query('$.boolean-false') |
| 36 | http-request set-var(sess.pay_mykey) req.body,json_query('$.my\\.key') |
| 37 | |
| 38 | http-response set-header x-var_header %[var(sess.header_json)] |
| 39 | http-response set-header x-var_body %[var(sess.pay_json)] |
| 40 | http-response set-header x-var_body_int %[var(sess.pay_int)] |
| 41 | http-response set-header x-var_body_neg_int %[var(sess.pay_neg_int)] |
| 42 | http-response set-header x-var_body_double %[var(sess.pay_double)] |
| 43 | http-response set-header x-var_body_boolean_true %[var(sess.pay_boolean_true)] |
| 44 | http-response set-header x-var_body_boolean_false %[var(sess.pay_boolean_false)] |
| 45 | http-response set-header x-var_body_mykey %[var(sess.pay_mykey)] |
| 46 | |
| 47 | default_backend be |
| 48 | |
| 49 | backend be |
| 50 | server s1 ${s1_addr}:${s1_port} |
| 51 | } -start |
| 52 | |
| 53 | client c1 -connect ${h1_fe_sock} { |
| 54 | txreq -url "/" \ |
| 55 | -hdr "Authorization: {\"iss\":\"kubernetes.io/serviceaccount\"}" |
| 56 | rxresp |
| 57 | expect resp.status == 200 |
| 58 | expect resp.http.x-var_header ~ "kubernetes.io/serviceaccount" |
| 59 | |
| 60 | txreq -url "/" \ |
| 61 | -body "{\"iss\":\"kubernetes.io/serviceaccount\"}" |
| 62 | rxresp |
| 63 | expect resp.status == 200 |
| 64 | expect resp.http.x-var_body ~ "kubernetes.io/serviceaccount" |
| 65 | |
| 66 | txreq -url "/" \ |
| 67 | -body "{\"integer\":4}" |
| 68 | rxresp |
| 69 | expect resp.status == 200 |
| 70 | expect resp.http.x-var_body_int ~ "5" |
| 71 | |
| 72 | txreq -url "/" \ |
| 73 | -body "{\"integer\":-4}" |
| 74 | rxresp |
| 75 | expect resp.status == 200 |
| 76 | expect resp.http.x-var_body_int ~ "-3" |
| 77 | |
| 78 | txreq -url "/" \ |
| 79 | -body "{\"double\":4.5}" |
| 80 | rxresp |
| 81 | expect resp.status == 200 |
| 82 | expect resp.http.x-var_body_double ~ "4.5" |
| 83 | |
| 84 | txreq -url "/" \ |
| 85 | -body "{\"boolean-true\":true}" |
| 86 | rxresp |
| 87 | expect resp.status == 200 |
| 88 | expect resp.http.x-var_body_boolean_true == 1 |
| 89 | |
| 90 | txreq -url "/" \ |
| 91 | -body "{\"boolean-false\":false}" |
| 92 | rxresp |
| 93 | expect resp.status == 200 |
| 94 | expect resp.http.x-var_body_boolean_false == 0 |
| 95 | |
| 96 | txreq -url "/" \ |
| 97 | -body "{\"my.key\":\"myvalue\"}" |
| 98 | rxresp |
| 99 | expect resp.status == 200 |
| 100 | expect resp.http.x-var_body_mykey ~ "myvalue" |
| 101 | } -run |