diff --git a/integration/hurlfmt/tests_export/filter.html b/integration/hurlfmt/tests_export/filter.html index 05b9701cf79..7d01a1b5d32 100644 --- a/integration/hurlfmt/tests_export/filter.html +++ b/integration/hurlfmt/tests_export/filter.html @@ -4,6 +4,8 @@ [Captures] count: jsonpath "$.books" count [Asserts] +jsonpath "$.data" base64Decode == hex,48656c6c6f; # base64Decode +bytes base64Encode == "SGVsbG8=" # base64Encode jsonpath "$.books" count == 12 # count certificate "Expire-Date" daysAfterNow > 15 # daysAfterNow certificate "Start-Date" daysBeforeNow < 100 # daysBeforeNow diff --git a/integration/hurlfmt/tests_export/filter.hurl b/integration/hurlfmt/tests_export/filter.hurl index 1ee475fac31..b85c325fbf1 100644 --- a/integration/hurlfmt/tests_export/filter.hurl +++ b/integration/hurlfmt/tests_export/filter.hurl @@ -4,6 +4,8 @@ HTTP 200 [Captures] count: jsonpath "$.books" count [Asserts] +jsonpath "$.data" base64Decode == hex,48656c6c6f; # base64Decode +bytes base64Encode == "SGVsbG8=" # base64Encode jsonpath "$.books" count == 12 # count certificate "Expire-Date" daysAfterNow > 15 # daysAfterNow certificate "Start-Date" daysBeforeNow < 100 # daysBeforeNow diff --git a/integration/hurlfmt/tests_export/filter.json b/integration/hurlfmt/tests_export/filter.json index 2464c1bdaa5..f55b2ae4c12 100644 --- a/integration/hurlfmt/tests_export/filter.json +++ b/integration/hurlfmt/tests_export/filter.json @@ -1 +1 @@ -{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/dummy"},"response":{"status":200,"captures":[{"name":"count","query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"count"}]}],"asserts":[{"query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"count"}],"predicate":{"type":"equal","value":12}},{"query":{"type":"certificate","expr":"Expire-Date"},"filters":[{"type":"daysAfterNow"}],"predicate":{"type":"greater","value":15}},{"query":{"type":"certificate","expr":"Start-Date"},"filters":[{"type":"daysBeforeNow"}],"predicate":{"type":"less","value":100}},{"query":{"type":"bytes"},"filters":[{"type":"decode","encoding":"iso-8859-1"}],"predicate":{"type":"equal","value":"café"}},{"query":{"type":"cookie","expr":"LSID[Expires]"},"filters":[{"type":"format","fmt":"%a, %d %b %Y %H:%M:%S"}],"predicate":{"type":"equal","value":"Wed, 13 Jan 2021 22:23:01"}},{"query":{"type":"jsonpath","expr":"$.text"},"filters":[{"type":"htmlEscape"}],"predicate":{"type":"equal","value":"a > b"}},{"query":{"type":"jsonpath","expr":"$.escaped_html[1]"},"filters":[{"type":"htmlUnescape"}],"predicate":{"type":"equal","value":"
Hello
"}},{"query":{"type":"variable","name":"books"},"filters":[{"type":"jsonpath","expr":"$[0].name"}],"predicate":{"type":"equal","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"nth","n":2}],"predicate":{"type":"equal","value":"Children of Dune"}},{"query":{"type":"body"},"filters":[{"type":"regex","expr":{"type":"regex","value":"Hello ([0-9]+)!"}}],"predicate":{"type":"equal","value":"Bob"}},{"query":{"type":"jsonpath","expr":"$.ips"},"filters":[{"type":"replace","old_value":", ","new_value":"|"}],"predicate":{"type":"equal","value":"192.168.2.1|10.0.0.20|10.0.0.10"}},{"query":{"type":"jsonpath","expr":"$.ips"},"filters":[{"type":"split","sep":", "},{"type":"count"}],"predicate":{"type":"equal","value":3}},{"query":{"type":"header","name":"Expires"},"filters":[{"type":"toDate","fmt":"%a, %d %b %Y %H:%M:%S GMT"},{"type":"daysBeforeNow"}],"predicate":{"type":"greater","value":1000}},{"query":{"type":"jsonpath","expr":"$.pi"},"filters":[{"type":"toFloat"}],"predicate":{"type":"equal","value":3.14}},{"query":{"type":"jsonpath","expr":"$.id"},"filters":[{"type":"toInt"}],"predicate":{"type":"equal","value":123}},{"query":{"type":"jsonpath","expr":"$.encoded_url"},"filters":[{"type":"urlDecode"}],"predicate":{"type":"equal","value":"https://mozilla.org/?x=шеллы"}},{"query":{"type":"jsonpath","expr":"$.url"},"filters":[{"type":"urlEncode"}],"predicate":{"type":"equal","value":"https%3A//mozilla.org/%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"}},{"query":{"type":"bytes"},"filters":[{"type":"decode","encoding":"iso-8859-1"},{"type":"xpath","expr":"string(//p)"}],"predicate":{"type":"equal","value":"Hello"}}]}}]} +{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/dummy"},"response":{"status":200,"captures":[{"name":"count","query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"count"}]}],"asserts":[{"query":{"type":"jsonpath","expr":"$.data"},"filters":[{"type":"base64Decode"}],"predicate":{"type":"equal","value":"SGVsbG8=","encoding":"base64"}},{"query":{"type":"bytes"},"filters":[{"type":"base64Encode"}],"predicate":{"type":"equal","value":"SGVsbG8="}},{"query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"count"}],"predicate":{"type":"equal","value":12}},{"query":{"type":"certificate","expr":"Expire-Date"},"filters":[{"type":"daysAfterNow"}],"predicate":{"type":"greater","value":15}},{"query":{"type":"certificate","expr":"Start-Date"},"filters":[{"type":"daysBeforeNow"}],"predicate":{"type":"less","value":100}},{"query":{"type":"bytes"},"filters":[{"type":"decode","encoding":"iso-8859-1"}],"predicate":{"type":"equal","value":"café"}},{"query":{"type":"cookie","expr":"LSID[Expires]"},"filters":[{"type":"format","fmt":"%a, %d %b %Y %H:%M:%S"}],"predicate":{"type":"equal","value":"Wed, 13 Jan 2021 22:23:01"}},{"query":{"type":"jsonpath","expr":"$.text"},"filters":[{"type":"htmlEscape"}],"predicate":{"type":"equal","value":"a > b"}},{"query":{"type":"jsonpath","expr":"$.escaped_html[1]"},"filters":[{"type":"htmlUnescape"}],"predicate":{"type":"equal","value":"Hello
"}},{"query":{"type":"variable","name":"books"},"filters":[{"type":"jsonpath","expr":"$[0].name"}],"predicate":{"type":"equal","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.books"},"filters":[{"type":"nth","n":2}],"predicate":{"type":"equal","value":"Children of Dune"}},{"query":{"type":"body"},"filters":[{"type":"regex","expr":{"type":"regex","value":"Hello ([0-9]+)!"}}],"predicate":{"type":"equal","value":"Bob"}},{"query":{"type":"jsonpath","expr":"$.ips"},"filters":[{"type":"replace","old_value":", ","new_value":"|"}],"predicate":{"type":"equal","value":"192.168.2.1|10.0.0.20|10.0.0.10"}},{"query":{"type":"jsonpath","expr":"$.ips"},"filters":[{"type":"split","sep":", "},{"type":"count"}],"predicate":{"type":"equal","value":3}},{"query":{"type":"header","name":"Expires"},"filters":[{"type":"toDate","fmt":"%a, %d %b %Y %H:%M:%S GMT"},{"type":"daysBeforeNow"}],"predicate":{"type":"greater","value":1000}},{"query":{"type":"jsonpath","expr":"$.pi"},"filters":[{"type":"toFloat"}],"predicate":{"type":"equal","value":3.14}},{"query":{"type":"jsonpath","expr":"$.id"},"filters":[{"type":"toInt"}],"predicate":{"type":"equal","value":123}},{"query":{"type":"jsonpath","expr":"$.encoded_url"},"filters":[{"type":"urlDecode"}],"predicate":{"type":"equal","value":"https://mozilla.org/?x=шеллы"}},{"query":{"type":"jsonpath","expr":"$.url"},"filters":[{"type":"urlEncode"}],"predicate":{"type":"equal","value":"https%3A//mozilla.org/%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"}},{"query":{"type":"bytes"},"filters":[{"type":"decode","encoding":"iso-8859-1"},{"type":"xpath","expr":"string(//p)"}],"predicate":{"type":"equal","value":"Hello"}}]}}]} diff --git a/integration/hurlfmt/tests_export/filter.lint.hurl b/integration/hurlfmt/tests_export/filter.lint.hurl index 1ee475fac31..b85c325fbf1 100644 --- a/integration/hurlfmt/tests_export/filter.lint.hurl +++ b/integration/hurlfmt/tests_export/filter.lint.hurl @@ -4,6 +4,8 @@ HTTP 200 [Captures] count: jsonpath "$.books" count [Asserts] +jsonpath "$.data" base64Decode == hex,48656c6c6f; # base64Decode +bytes base64Encode == "SGVsbG8=" # base64Encode jsonpath "$.books" count == 12 # count certificate "Expire-Date" daysAfterNow > 15 # daysAfterNow certificate "Start-Date" daysBeforeNow < 100 # daysBeforeNow diff --git a/packages/hurl/src/runner/filter/eval.rs b/packages/hurl/src/runner/filter/eval.rs index 2a3d79864d0..d898bba1dd0 100644 --- a/packages/hurl/src/runner/filter/eval.rs +++ b/packages/hurl/src/runner/filter/eval.rs @@ -68,6 +68,8 @@ pub fn eval_filter( in_assert: bool, ) -> Result