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 { |
| 12 | defaults |
| 13 | mode http |
| 14 | timeout connect 1s |
| 15 | timeout client 1s |
| 16 | timeout server 1s |
| 17 | option http-buffer-request |
| 18 | |
| 19 | frontend fe |
| 20 | bind "fd@${fe}" |
| 21 | tcp-request inspect-delay 1s |
| 22 | |
| 23 | http-request set-var(sess.header_json) req.hdr(Authorization),json_query('$.iss') |
| 24 | http-request set-var(sess.pay_json) req.body,json_query('$.iss') |
| 25 | http-request set-var(sess.pay_int) req.body,json_query('$.integer',"int"),add(1) |
| 26 | http-request set-var(sess.pay_neg_int) req.body,json_query('$.negativ-integer',"int"),add(1) |
| 27 | http-request set-var(sess.pay_double) req.body,json_query('$.double') |
| 28 | http-request set-var(sess.pay_boolean_true) req.body,json_query('$.boolean-true') |
| 29 | http-request set-var(sess.pay_boolean_false) req.body,json_query('$.boolean-false') |
| 30 | http-request set-var(sess.pay_mykey) req.body,json_query('$.my\\.key') |
| 31 | |
| 32 | http-response set-header x-var_header %[var(sess.header_json)] |
| 33 | http-response set-header x-var_body %[var(sess.pay_json)] |
| 34 | http-response set-header x-var_body_int %[var(sess.pay_int)] |
| 35 | http-response set-header x-var_body_neg_int %[var(sess.pay_neg_int)] |
| 36 | http-response set-header x-var_body_double %[var(sess.pay_double)] |
| 37 | http-response set-header x-var_body_boolean_true %[var(sess.pay_boolean_true)] |
| 38 | http-response set-header x-var_body_boolean_false %[var(sess.pay_boolean_false)] |
| 39 | http-response set-header x-var_body_mykey %[var(sess.pay_mykey)] |
| 40 | |
| 41 | default_backend be |
| 42 | |
| 43 | backend be |
| 44 | server s1 ${s1_addr}:${s1_port} |
| 45 | } -start |
| 46 | |
| 47 | client c1 -connect ${h1_fe_sock} { |
| 48 | txreq -url "/" \ |
| 49 | -hdr "Authorization: {\"iss\":\"kubernetes.io/serviceaccount\"}" |
| 50 | rxresp |
| 51 | expect resp.status == 200 |
| 52 | expect resp.http.x-var_header ~ "kubernetes.io/serviceaccount" |
| 53 | |
| 54 | txreq -url "/" \ |
| 55 | -body "{\"iss\":\"kubernetes.io/serviceaccount\"}" |
| 56 | rxresp |
| 57 | expect resp.status == 200 |
| 58 | expect resp.http.x-var_body ~ "kubernetes.io/serviceaccount" |
| 59 | |
| 60 | txreq -url "/" \ |
| 61 | -body "{\"integer\":4}" |
| 62 | rxresp |
| 63 | expect resp.status == 200 |
| 64 | expect resp.http.x-var_body_int ~ "5" |
| 65 | |
| 66 | txreq -url "/" \ |
| 67 | -body "{\"integer\":-4}" |
| 68 | rxresp |
| 69 | expect resp.status == 200 |
| 70 | expect resp.http.x-var_body_int ~ "-3" |
| 71 | |
| 72 | txreq -url "/" \ |
| 73 | -body "{\"double\":4.5}" |
| 74 | rxresp |
| 75 | expect resp.status == 200 |
| 76 | expect resp.http.x-var_body_double ~ "4.5" |
| 77 | |
| 78 | txreq -url "/" \ |
| 79 | -body "{\"boolean-true\":true}" |
| 80 | rxresp |
| 81 | expect resp.status == 200 |
| 82 | expect resp.http.x-var_body_boolean_true == 1 |
| 83 | |
| 84 | txreq -url "/" \ |
| 85 | -body "{\"boolean-false\":false}" |
| 86 | rxresp |
| 87 | expect resp.status == 200 |
| 88 | expect resp.http.x-var_body_boolean_false == 0 |
| 89 | |
| 90 | txreq -url "/" \ |
| 91 | -body "{\"my.key\":\"myvalue\"}" |
| 92 | rxresp |
| 93 | expect resp.status == 200 |
| 94 | expect resp.http.x-var_body_mykey ~ "myvalue" |
| 95 | } -run |