From: Alan T. DeKok Date: Sat, 1 Feb 2025 14:20:13 +0000 (-0500) Subject: remove '&' again X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1a5e02201f95cc7e6df19686b0e6cb7e5360a4a;p=thirdparty%2Ffreeradius-server.git remove '&' again now that the server and tmpl code have been double checked --- diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index 8cc447c7d89..ee88610cb94 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -243,7 +243,7 @@ static xlat_action_t json_encode_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, .attr = { .list_def = request_attr_request, .allow_wildcard = true, - .dict_def = request->dict + .dict_def = request->dict, } }); if (slen <= 0) { diff --git a/src/tests/modules/json/encode.unlang b/src/tests/modules/json/encode.unlang index d84b09ff05b..c5a0f294679 100644 --- a/src/tests/modules/json/encode.unlang +++ b/src/tests/modules/json/encode.unlang @@ -6,53 +6,53 @@ string test_string5 # # json.encode tests # -&request -= &Packet-Type[*] +request -= Packet-Type[*] # # HACK: the edit code does not currently support deleted by parent -# when doing &request -= &Net[*] -# or even &request -= &Net.[*] +# when doing request -= Net[*] +# or even request -= Net.[*] # which returns an error? # -&request -= &Net.Src.IP -&request -= &Net.Src.Port -&request -= &Net.Dst.IP -&request -= &Net.Dst.Port -&request -= &Net.Timestamp -&request -= &Net[*] +request -= Net.Src.IP +request -= Net.Src.Port +request -= Net.Dst.IP +request -= Net.Dst.Port +request -= Net.Timestamp +request -= Net[*] # 0. Check basic xlat parsing -&test_string1 := %json.encode("&request.[*]") -&test_string2 := %json.encode("&request.[*] ") -&test_string3 := %json.encode(" &request.[*]") -&test_string4 := %json.encode(" &request.[*] ") +test_string1 := %json.encode("request.[*]") +test_string2 := %json.encode("request.[*] ") +test_string3 := %json.encode(" request.[*]") +test_string4 := %json.encode(" request.[*] ") -if (!(&test_string1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}')) { +if (!(test_string1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}')) { test_fail } # Check xlat input formats -if (!(&test_string1 == &test_string2) || - !(&test_string1 == &test_string3) || - !(&test_string1 == &test_string4)) { +if (!(test_string1 == test_string2) || + !(test_string1 == test_string3) || + !(test_string1 == test_string4)) { test_fail } # Check defaults are the same as output_mode "object": -&test_string2 := %json_object.encode("&request.[*]") -&test_string3 := %json_object_no.encode("&request.[*]") -if (!(&test_string1 == &test_string2) || - !(&test_string1 == &test_string3)) { +test_string2 := %json_object.encode("request.[*]") +test_string3 := %json_object_no.encode("request.[*]") +if (!(test_string1 == test_string2) || + !(test_string1 == test_string3)) { test_fail } -&test_string1 := %json.encode(" &request.[*] !&Filter-Id ") -if !(&test_string1 == '{"User-Name":{"type":"string","value":"john"},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') { +test_string1 := %json.encode(" request.[*] !Filter-Id ") +if !(test_string1 == '{"User-Name":{"type":"string","value":"john"},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') { test_fail } -&test_string1 := %json.encode("&request.[*] ! ") -if &test_string1 { +test_string1 := %json.encode("request.[*] ! ") +if test_string1 { test_fail } @@ -60,98 +60,98 @@ if &test_string1 { # These are unsorted dictionaries. Hopefully json-c doesn't suddenly # decide that it's going to use a different ordering of the keys... -&test_string1 := %json_object.encode("&request.[*]") -&test_string2 := %json_object_ex.encode("&request.[*]") +test_string1 := %json_object.encode("request.[*]") +test_string2 := %json_object_ex.encode("request.[*]") -if !(&test_string1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') { +if !(test_string1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') { test_fail } "%{test_string2}" -if !(&test_string2 == '{"pf:User-Name":{"type":"string","value":["john"]},"pf:Filter-Id":{"type":"string","value":["f1","f2"]},"pf:NAS-Port":{"type":"uint32","value":["999"]},"pf:Service-Type":{"type":"uint32","value":["1"]}}') { +if !(test_string2 == '{"pf:User-Name":{"type":"string","value":["john"]},"pf:Filter-Id":{"type":"string","value":["f1","f2"]},"pf:NAS-Port":{"type":"uint32","value":["999"]},"pf:Service-Type":{"type":"uint32","value":["1"]}}') { test_fail } # 1b. "object" empty inputs -&test_string1 := %json_object.encode("!&request.[*]") +test_string1 := %json_object.encode("!request.[*]") -if !(&test_string1 == '{}') { +if !(test_string1 == '{}') { test_fail } # 2a. Output mode "object_simple" tests -&test_string1 := %json_object_simple.encode("&request.[*]") -&test_string2 := %json_object_simple_ex.encode("&request.[*]") +test_string1 := %json_object_simple.encode("request.[*]") +test_string2 := %json_object_simple_ex.encode("request.[*]") -if !(&test_string1 == '{"User-Name":"john","Filter-Id":["f1","f2"],"NAS-Port":999,"Service-Type":"Login-User"}') { +if !(test_string1 == '{"User-Name":"john","Filter-Id":["f1","f2"],"NAS-Port":999,"Service-Type":"Login-User"}') { test_fail } -if !(&test_string2 == '{"pf:User-Name":["john"],"pf:Filter-Id":["f1","f2"],"pf:NAS-Port":["999"],"pf:Service-Type":["1"]}') { +if !(test_string2 == '{"pf:User-Name":["john"],"pf:Filter-Id":["f1","f2"],"pf:NAS-Port":["999"],"pf:Service-Type":["1"]}') { test_fail } # 2b. "object_simple" empty inputs -&test_string1 := %json_object_simple.encode("!&request.[*]") +test_string1 := %json_object_simple.encode("!request.[*]") -if !(&test_string1 == '{}') { +if !(test_string1 == '{}') { test_fail } # 3a. Output mode "array" tests -&test_string1 := %json_array.encode("&request.[*]") -&test_string2 := %json_array_ex.encode("&request.[*]") +test_string1 := %json_array.encode("request.[*]") +test_string2 := %json_array_ex.encode("request.[*]") -if !(&test_string1 == '[{"name":"User-Name","type":"string","value":"john"},{"name":"Filter-Id","type":"string","value":"f1"},{"name":"Filter-Id","type":"string","value":"f2"},{"name":"NAS-Port","type":"uint32","value":999},{"name":"Service-Type","type":"uint32","value":"Login-User"}]') { +if !(test_string1 == '[{"name":"User-Name","type":"string","value":"john"},{"name":"Filter-Id","type":"string","value":"f1"},{"name":"Filter-Id","type":"string","value":"f2"},{"name":"NAS-Port","type":"uint32","value":999},{"name":"Service-Type","type":"uint32","value":"Login-User"}]') { test_fail } -if !(&test_string2 == '[{"name":"pf:User-Name","type":"string","value":["john"]},{"name":"pf:Filter-Id","type":"string","value":["f1","f2"]},{"name":"pf:NAS-Port","type":"uint32","value":["999"]},{"name":"pf:Service-Type","type":"uint32","value":["1"]}]') { +if !(test_string2 == '[{"name":"pf:User-Name","type":"string","value":["john"]},{"name":"pf:Filter-Id","type":"string","value":["f1","f2"]},{"name":"pf:NAS-Port","type":"uint32","value":["999"]},{"name":"pf:Service-Type","type":"uint32","value":["1"]}]') { test_fail } # 3b. "array" empty inputs -&test_string1 := %json_array.encode("!&request.[*]") +test_string1 := %json_array.encode("!request.[*]") -if !(&test_string1 == '[]') { +if !(test_string1 == '[]') { test_fail } # 4a. Output mode "array_of_names" tests -&test_string1 := %json_array_names.encode("&request.[*]") -&test_string2 := %json_array_names_ex.encode("&request.[*]") +test_string1 := %json_array_names.encode("request.[*]") +test_string2 := %json_array_names_ex.encode("request.[*]") -if !(&test_string1 == '["User-Name","Filter-Id","Filter-Id","NAS-Port","Service-Type"]') { +if !(test_string1 == '["User-Name","Filter-Id","Filter-Id","NAS-Port","Service-Type"]') { test_fail } -if !(&test_string2 == '["pf:User-Name","pf:Filter-Id","pf:Filter-Id","pf:NAS-Port","pf:Service-Type"]') { +if !(test_string2 == '["pf:User-Name","pf:Filter-Id","pf:Filter-Id","pf:NAS-Port","pf:Service-Type"]') { test_fail } # 4b. "array_of_names" empty inputs -&test_string1 := %json_array_names.encode("!&request.[*]") +test_string1 := %json_array_names.encode("!request.[*]") -if !(&test_string1 == '[]') { +if !(test_string1 == '[]') { test_fail } # 5a. Output mode "array_of_values" tests -&test_string1 := %json_array_values.encode("&request.[*]") -&test_string2 := %json_array_values_ex.encode("&request.[*]") +test_string1 := %json_array_values.encode("request.[*]") +test_string2 := %json_array_values_ex.encode("request.[*]") -if !(&test_string1 == '["john","f1","f2",999,"Login-User"]') { +if !(test_string1 == '["john","f1","f2",999,"Login-User"]') { test_fail } -if !(&test_string2 == '["john","f1","f2","999","1"]') { +if !(test_string2 == '["john","f1","f2","999","1"]') { test_fail } # 5b. "array_of_values" empty inputs -&test_string1 := %json_array_values.encode("!&request.[*]") +test_string1 := %json_array_values.encode("!request.[*]") -if !(&test_string1 == '[]') { +if !(test_string1 == '[]') { test_fail } diff --git a/src/tests/modules/json/encode_error.unlang b/src/tests/modules/json/encode_error.unlang index 58cf49dfa18..69adac27db9 100644 --- a/src/tests/modules/json/encode_error.unlang +++ b/src/tests/modules/json/encode_error.unlang @@ -3,8 +3,8 @@ string test_string # json xlat input parsing test - error with no input # -&test_string := %json_object_ex_encode() # ERROR -if (&test_string) { +test_string := %json_object_ex_encode() # ERROR +if (test_string) { test_fail } diff --git a/src/tests/modules/json/eval.unlang b/src/tests/modules/json/eval.unlang index f44402055cc..a7427d8e150 100644 --- a/src/tests/modules/json/eval.unlang +++ b/src/tests/modules/json/eval.unlang @@ -5,18 +5,18 @@ uint32 test_integer int64 test_int64 string test_string -&Filter-Id := "{\"foo\":\"bar\"}" +Filter-Id := "{\"foo\":\"bar\"}" # 0. Simple field access -map json &Filter-Id { - &Callback-Id := '$.foo' +map json Filter-Id { + Callback-Id := '$.foo' } -if !(&Callback-Id == 'bar') { +if !(Callback-Id == 'bar') { test_fail } -&Filter-Id := "\ +Filter-Id := "\ {\ \"my_array\": [0, 1, 2, 3, 4, 5], \ \"my_object\": { \ @@ -30,309 +30,309 @@ if !(&Callback-Id == 'bar') { \"bool_false\": false \ }" -&request -= &Callback-Id[*] +request -= Callback-Id[*] # Check conversion of all JSON types to strings -map json &Filter-Id { - &Callback-Id += '$.*' +map json Filter-Id { + Callback-Id += '$.*' } # 1. Array type -if !(&Callback-Id[0] == '[ 0, 1, 2, 3, 4, 5 ]') { +if !(Callback-Id[0] == '[ 0, 1, 2, 3, 4, 5 ]') { test_fail } # 2. Object type -if !(&Callback-Id[1] == '{ "foo": "bar", "num": 42 }') { +if !(Callback-Id[1] == '{ "foo": "bar", "num": 42 }') { test_fail } # 3. Integer type -if !(&Callback-Id[2] == '99') { +if !(Callback-Id[2] == '99') { test_fail } # 4. Double type -if !(&Callback-Id[3] == '5.9') { +if !(Callback-Id[3] == '5.9') { test_fail } # 5. null type -if !(&Callback-Id[4] == 'null') { +if !(Callback-Id[4] == 'null') { test_fail } # 6. Boolean true -if !(&Callback-Id[5] == 'yes') { +if !(Callback-Id[5] == 'yes') { test_fail } # 7. Boolean false -if (&Callback-Id[6] != 'no') { +if (Callback-Id[6] != 'no') { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] # # Now check array slicing operates correctly # # 8. String form -map json &Filter-Id { - &Callback-Id := '$.my_array' +map json Filter-Id { + Callback-Id := '$.my_array' } -if !(&Callback-Id == '[ 0, 1, 2, 3, 4, 5 ]') { +if !(Callback-Id == '[ 0, 1, 2, 3, 4, 5 ]') { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] # 9. Simple index -map json &Filter-Id { - &NAS-Port := '$.my_array[0]' +map json Filter-Id { + NAS-Port := '$.my_array[0]' } -if !(&NAS-Port == 0) { +if !(NAS-Port == 0) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 9a. All of the array -map json &Filter-Id { - &NAS-Port += '$.my_array.*' +map json Filter-Id { + NAS-Port += '$.my_array.*' } -if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 1) || !(&NAS-Port[2] == 2) || !(&NAS-Port[3] == 3) || !(&NAS-Port[4] == 4) || !(&NAS-Port[5] == 5)) { +if (!(NAS-Port[0] == 0) || !(NAS-Port[1] == 1) || !(NAS-Port[2] == 2) || !(NAS-Port[3] == 3) || !(NAS-Port[4] == 4) || !(NAS-Port[5] == 5)) { test_fail } -&NAS-Port := 9 +NAS-Port := 9 # 9b. All of the array using prepend, places the array before the existing value -map json &Filter-Id { - &NAS-Port ^= '$.my_array.*' +map json Filter-Id { + NAS-Port ^= '$.my_array.*' } -if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 1) || !(&NAS-Port[2] == 2) || !(&NAS-Port[3] == 3) || !(&NAS-Port[4] == 4) || !(&NAS-Port[5] == 5) || !(&NAS-Port[6] == 9)) { +if (!(NAS-Port[0] == 0) || !(NAS-Port[1] == 1) || !(NAS-Port[2] == 2) || !(NAS-Port[3] == 3) || !(NAS-Port[4] == 4) || !(NAS-Port[5] == 5) || !(NAS-Port[6] == 9)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 10. End of the array -map json &Filter-Id { - &NAS-Port := '$.my_array[5]' # Past the end of the array (should be skipped) +map json Filter-Id { + NAS-Port := '$.my_array[5]' # Past the end of the array (should be skipped) } -if !(&NAS-Port == 5) { +if !(NAS-Port == 5) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 11. Past end of the array -map json &Filter-Id { - &NAS-Port := '$.my_array[6]' # Past the end of the array (should be skipped) +map json Filter-Id { + NAS-Port := '$.my_array[6]' # Past the end of the array (should be skipped) } -if (&NAS-Port) { +if (NAS-Port) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 12. Simple slice -map json &Filter-Id { - &NAS-Port += '$.my_array[0:2]' # A single value +map json Filter-Id { + NAS-Port += '$.my_array[0:2]' # A single value } -if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 1)) { +if (!(NAS-Port[0] == 0) || !(NAS-Port[1] == 1)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 13. Slice with negative start -map json &Filter-Id { - &NAS-Port += '$.my_array[-1:6]' # A single value (last eelement of the array) +map json Filter-Id { + NAS-Port += '$.my_array[-1:6]' # A single value (last eelement of the array) } -if !(&NAS-Port == 5) { +if !(NAS-Port == 5) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 14. Slice with negative start and negative end -map json &Filter-Id { - &NAS-Port += '$.my_array[-1:-3]' # Start after end (should be skipped) +map json Filter-Id { + NAS-Port += '$.my_array[-1:-3]' # Start after end (should be skipped) } -if (&NAS-Port) { +if (NAS-Port) { test_fail } # 15. Slice with start and negative end -map json &Filter-Id { - &NAS-Port += '$.my_array[1:-3]' +map json Filter-Id { + NAS-Port += '$.my_array[1:-3]' } -if (!(&NAS-Port[0] == 1) && !(&NAS-Port[1] == 2)) { +if (!(NAS-Port[0] == 1) && !(NAS-Port[1] == 2)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 16. Slice with start, end and negative step -map json &Filter-Id { - &NAS-Port += '$.my_array[4:2:-1]' +map json Filter-Id { + NAS-Port += '$.my_array[4:2:-1]' } -if (!(&NAS-Port[0] == 4) || !(&NAS-Port[1] == 3)) { +if (!(NAS-Port[0] == 4) || !(NAS-Port[1] == 3)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 17. Slice with start, end (inverted) and negative step -map json &Filter-Id { - &NAS-Port += '$.my_array[2:4:-1]' +map json Filter-Id { + NAS-Port += '$.my_array[2:4:-1]' } -if (&NAS-Port) { +if (NAS-Port) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 18. Slice with start, end and positive step -map json &Filter-Id { - &NAS-Port += '$.my_array[2:4:1]' +map json Filter-Id { + NAS-Port += '$.my_array[2:4:1]' } -if (!(&NAS-Port[0] == 2) || !(&NAS-Port[1] == 3)) { +if (!(NAS-Port[0] == 2) || !(NAS-Port[1] == 3)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 19. Slice with start, end and positive step > 1 -map json &Filter-Id { - &NAS-Port += '$.my_array[1:5:2]' +map json Filter-Id { + NAS-Port += '$.my_array[1:5:2]' } -if (!(&NAS-Port[0] == 1) && !(&NAS-Port[1] == 3)) { +if (!(NAS-Port[0] == 1) && !(NAS-Port[1] == 3)) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 20. Slice with start, end and positive step > end of array -map json &Filter-Id { - &NAS-Port += '$.my_array[1:5:4]' +map json Filter-Id { + NAS-Port += '$.my_array[1:5:4]' } -if (!(&NAS-Port[0] == 1) || &NAS-Port[1]) { +if (!(NAS-Port[0] == 1) || NAS-Port[1]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 21. Slice with start, end and positive step > end of array -map json &Filter-Id { - &NAS-Port += '$.my_array[5:1:-4]' +map json Filter-Id { + NAS-Port += '$.my_array[5:1:-4]' } -if (!(&NAS-Port[0] == 5) || &NAS-Port[1]) { +if (!(NAS-Port[0] == 5) || NAS-Port[1]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 22. No start/end 3 step -map json &Filter-Id { - &NAS-Port += '$.my_array[::3]' +map json Filter-Id { + NAS-Port += '$.my_array[::3]' } -if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 3) || &NAS-Port[2]) { +if (!(NAS-Port[0] == 0) || !(NAS-Port[1] == 3) || NAS-Port[2]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 23. No start/end 3 step -map json &Filter-Id { - &NAS-Port += '$.my_array[::-3]' +map json Filter-Id { + NAS-Port += '$.my_array[::-3]' } -if (!(&NAS-Port[0] == 5) || !(&NAS-Port[1] == 2) || &NAS-Port[2]) { +if (!(NAS-Port[0] == 5) || !(NAS-Port[1] == 2) || NAS-Port[2]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 24. No end 3 step -map json &Filter-Id { - &NAS-Port += '$.my_array[3::-3]' +map json Filter-Id { + NAS-Port += '$.my_array[3::-3]' } -if (!(&NAS-Port[0] == 3) || !(&NAS-Port[1] == 0) || &NAS-Port[2]) { +if (!(NAS-Port[0] == 3) || !(NAS-Port[1] == 0) || NAS-Port[2]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 25. End 0, 3 step -map json &Filter-Id { - &NAS-Port += '$.my_array[3:0:-3]' +map json Filter-Id { + NAS-Port += '$.my_array[3:0:-3]' } -if (!(&NAS-Port[0] == 3) || &NAS-Port[1]) { +if (!(NAS-Port[0] == 3) || NAS-Port[1]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 26. End 0, 3 step -map json &Filter-Id { - &NAS-Port += '$.my_array[0::-3]' +map json Filter-Id { + NAS-Port += '$.my_array[0::-3]' } -if (!(&NAS-Port[0] == 0) || &NAS-Port[1]) { +if (!(NAS-Port[0] == 0) || NAS-Port[1]) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 27. Everything two levels deep -map json &Filter-Id { - &Callback-Id += '$.*.*' +map json Filter-Id { + Callback-Id += '$.*.*' } -if (!(&Callback-Id[0] == '0') || \ - !(&Callback-Id[1] == '1') || \ - !(&Callback-Id[2] == '2') || \ - !(&Callback-Id[3] == '3') || \ - !(&Callback-Id[4] == '4') || \ - !(&Callback-Id[5] == '5') || \ - !(&Callback-Id[6] == 'bar') || \ - !(&Callback-Id[7] == '42')) { +if (!(Callback-Id[0] == '0') || \ + !(Callback-Id[1] == '1') || \ + !(Callback-Id[2] == '2') || \ + !(Callback-Id[3] == '3') || \ + !(Callback-Id[4] == '4') || \ + !(Callback-Id[5] == '5') || \ + !(Callback-Id[6] == 'bar') || \ + !(Callback-Id[7] == '42')) { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] # 28. Everything three levels deep (nothing) -map json &Filter-Id { - &Callback-Id += '$.*.*.*' +map json Filter-Id { + Callback-Id += '$.*.*.*' } -if (&Callback-Id) { +if (Callback-Id) { test_fail } # 29. Array access on a field (nothing) -map json &Filter-Id { - &Callback-Id += '$.my_object[0]' +map json Filter-Id { + Callback-Id += '$.my_object[0]' } -if (&Callback-Id) { +if (Callback-Id) { test_fail } # 30. Non-existent field -map json &Filter-Id { - &Callback-Id += '$.my_object.my_other_object' +map json Filter-Id { + Callback-Id += '$.my_object.my_other_object' } -if (&Callback-Id) { +if (Callback-Id) { test_fail } # Some big numbers in nested arrays -&Filter-Id := "\ +Filter-Id := "\ [\ 9223372036854775807, \ -9223372036854775807, \ @@ -349,95 +349,95 @@ if (&Callback-Id) { # version/system dependent *sigh*. redundant { group { - map json &Filter-Id { - &NAS-Port := '$[3][2]' + map json Filter-Id { + NAS-Port := '$[3][2]' } } noop } -if (!noop && (!(&NAS-Port == 4294967295) && !(&NAS-Port == 2147483647))) { +if (!noop && (!(NAS-Port == 4294967295) && !(NAS-Port == 2147483647))) { test_fail } # 32. Unsigned 32bit integers (are supported) -map json &Filter-Id { - &NAS-Port := '$[3][0]' +map json Filter-Id { + NAS-Port := '$[3][0]' } -if !(&NAS-Port == 2147483647) { +if !(NAS-Port == 2147483647) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 33. Signed 64bit integers if (0) { -map json &Filter-Id { - &test_int64 := '$[0]' +map json Filter-Id { + test_int64 := '$[0]' } -if !(&test_int64 == (int64)9223372036854775807) { +if !(test_int64 == (int64)9223372036854775807) { test_fail } # 34. Signed 64bit integers -map json &Filter-Id { - &test_int64 := '$[1]' +map json Filter-Id { + test_int64 := '$[1]' } -if !(&test_int64 == -9223372036854775807) { +if !(test_int64 == -9223372036854775807) { test_fail } -&request -= &test_int64[*] +request -= test_int64[*] # 35. Unsigned 64bit integers (not allowed by json so gets truncated) -map json &Filter-Id { - &Acct-Input-Octets64 := '$[2]' +map json Filter-Id { + Acct-Input-Octets64 := '$[2]' } -if !(&Acct-Input-Octets64 == 9223372036854775807) { +if !(Acct-Input-Octets64 == 9223372036854775807) { test_fail } } -&request -= &Acct-Input-Octets64[*] +request -= Acct-Input-Octets64[*] # 36. Multiple array indices -map json &Filter-Id { - &Cache-TTL += '$[3][0,1]' +map json Filter-Id { + Cache-TTL += '$[3][0,1]' } -if (!(&Cache-TTL[0] == 2147483647) || !(&Cache-TTL[1] == -2147483647)) { +if (!(Cache-TTL[0] == 2147483647) || !(Cache-TTL[1] == -2147483647)) { test_fail } -&request -= &Cache-TTL[*] +request -= Cache-TTL[*] # 37. Path containing dynamic expansion -&test_integer := 0 +test_integer := 0 -map json &Filter-Id { - &NAS-Port += "$[3][%{test_integer}]" +map json Filter-Id { + NAS-Port += "$[3][%{test_integer}]" } -if !(&NAS-Port == 2147483647) { +if !(NAS-Port == 2147483647) { test_fail } -&request -= &NAS-Port[*] +request -= NAS-Port[*] # 38. An expanded field name with bad chars -&Filter-Id := "\ +Filter-Id := "\ {\ \"foo.bar\": \"baz\" \ }" -&test_string := "%taint('foo.bar')" +test_string := "%taint('foo.bar')" -map json &Filter-Id { - &Callback-Id := "$.%{test_string}" +map json Filter-Id { + Callback-Id := "$.%{test_string}" } -if !(&Callback-Id == 'baz') { +if !(Callback-Id == 'baz') { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] -&Filter-Id := "\ +Filter-Id := "\ {\ \"my_array\": [0, 1, 2, 3, 4, 5], \ \"my_object\": { \ @@ -462,33 +462,33 @@ if !(&Callback-Id == 'baz') { }" # 39. Recursive descent with field match -map json &Filter-Id { - &Callback-Id += '$..bool' +map json Filter-Id { + Callback-Id += '$..bool' } -if (!("%{Callback-Id[#]}" == 1) || !(&Callback-Id == 'yes')) { +if (!("%{Callback-Id[#]}" == 1) || !(Callback-Id == 'yes')) { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] # 40. Recursive descent with element match (2nd element in each array) -map json &Filter-Id { - &Callback-Id += '$..[1]' +map json Filter-Id { + Callback-Id += '$..[1]' } -if (!("%{Callback-Id[#]}" == 3) || !(&Callback-Id[0] == '1') || !(&Callback-Id[1] == 'scratchy') || !(&Callback-Id[2] == 'clawy')) { +if (!("%{Callback-Id[#]}" == 3) || !(Callback-Id[0] == '1') || !(Callback-Id[1] == 'scratchy') || !(Callback-Id[2] == 'clawy')) { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] # 41. Recursive descent with field then element match -map json &Filter-Id { - &Callback-Id += '$..my_cats[2]' +map json Filter-Id { + Callback-Id += '$..my_cats[2]' } -if (!("%{Callback-Id[#]}" == 2) || !(&Callback-Id[0] == 'flat') || !(&Callback-Id[1] == 'woofy')) { +if (!("%{Callback-Id[#]}" == 2) || !(Callback-Id[0] == 'flat') || !(Callback-Id[1] == 'woofy')) { test_fail } -&request -= &Callback-Id[*] +request -= Callback-Id[*] test_pass diff --git a/src/tests/modules/json/json_quote.unlang b/src/tests/modules/json/json_quote.unlang index 97f0799c6e2..7b21443cf17 100644 --- a/src/tests/modules/json/json_quote.unlang +++ b/src/tests/modules/json/json_quote.unlang @@ -3,32 +3,32 @@ uint32 test_integer ipaddr test_ipaddr string dummy_string -&test_string := "Hello\n" +test_string := "Hello\n" if (!(%json.quote(%{test_string}) == "\"Hello\\n\"")) { test_fail } -&test_string := "Hello\nbob" +test_string := "Hello\nbob" if (!(%json.quote(%{test_string}) == "\"Hello\\nbob\"")) { test_fail } -&test_string := "\nHello\nbob" +test_string := "\nHello\nbob" if (!(%json.quote(%{test_string}) == "\"\\nHello\\nbob\"")) { test_fail } -&test_string := "Hello!" +test_string := "Hello!" if (!(%json.quote(%{test_string}) == '"Hello!"')) { test_fail } -&test_integer := 123456 +test_integer := 123456 if (!(%json.quote(%{test_integer}) == '123456')) { test_fail } -&test_ipaddr := 127.0.0.1 +test_ipaddr := 127.0.0.1 if (!(%json.quote(%{test_ipaddr}) == '"127.0.0.1"')) { test_fail } diff --git a/src/tests/modules/json/nested_encode.unlang b/src/tests/modules/json/nested_encode.unlang index 4c5d852ff42..df691de4ffb 100644 --- a/src/tests/modules/json/nested_encode.unlang +++ b/src/tests/modules/json/nested_encode.unlang @@ -1,24 +1,24 @@ -&Tag-1 := { - &Vendor-Specific = { - &Unisphere = { - &Service-Activate = "PPPOE_SERVICE(3072000,2048000)" +Tag-1 := { + Vendor-Specific = { + Unisphere = { + Service-Activate = "PPPOE_SERVICE(3072000,2048000)" } } } -if (!(%json.encode('&request.Tag-1') == "{\"Tag-1\":{\"type\":\"group\",\"value\":{\"Vendor-Specific\":{\"type\":\"vsa\",\"value\":{\"Unisphere\":{\"type\":\"vendor\",\"value\":{\"Service-Activate\":{\"type\":\"string\",\"value\":\"PPPOE_SERVICE(3072000,2048000)\"}}}}}}}}")) { +if (!(%json.encode('request.Tag-1') == "{\"Tag-1\":{\"type\":\"group\",\"value\":{\"Vendor-Specific\":{\"type\":\"vsa\",\"value\":{\"Unisphere\":{\"type\":\"vendor\",\"value\":{\"Service-Activate\":{\"type\":\"string\",\"value\":\"PPPOE_SERVICE(3072000,2048000)\"}}}}}}}}")) { test_fail } -if (!(%json_object_simple.encode('&request.Tag-1') == "{\"Tag-1\":{\"Vendor-Specific\":{\"Unisphere\":{\"Service-Activate\":\"PPPOE_SERVICE(3072000,2048000)\"}}}}")) { +if (!(%json_object_simple.encode('request.Tag-1') == "{\"Tag-1\":{\"Vendor-Specific\":{\"Unisphere\":{\"Service-Activate\":\"PPPOE_SERVICE(3072000,2048000)\"}}}}")) { test_fail } -if (!(%json_array.encode('&request.Tag-1') == "[{\"name\":\"Tag-1\",\"type\":\"group\",\"value\":[{\"name\":\"Vendor-Specific\",\"type\":\"vsa\",\"value\":[{\"name\":\"Unisphere\",\"type\":\"vendor\",\"value\":[{\"name\":\"Service-Activate\",\"type\":\"string\",\"value\":\"PPPOE_SERVICE(3072000,2048000)\"}]}]}]}]")) { +if (!(%json_array.encode('request.Tag-1') == "[{\"name\":\"Tag-1\",\"type\":\"group\",\"value\":[{\"name\":\"Vendor-Specific\",\"type\":\"vsa\",\"value\":[{\"name\":\"Unisphere\",\"type\":\"vendor\",\"value\":[{\"name\":\"Service-Activate\",\"type\":\"string\",\"value\":\"PPPOE_SERVICE(3072000,2048000)\"}]}]}]}]")) { test_fail } -if (!(%json_array_names.encode('&request.Tag-1') == "[\"Tag-1\",[\"Vendor-Specific\",[\"Unisphere\",[\"Service-Activate\"]]]]")) { +if (!(%json_array_names.encode('request.Tag-1') == "[\"Tag-1\",[\"Vendor-Specific\",[\"Unisphere\",[\"Service-Activate\"]]]]")) { test_fail } diff --git a/src/tests/modules/json/regression01.unlang b/src/tests/modules/json/regression01.unlang index 3b189bb0f36..2c9be6c5b42 100644 --- a/src/tests/modules/json/regression01.unlang +++ b/src/tests/modules/json/regression01.unlang @@ -1,15 +1,15 @@ # In the original failure parsing the mac-address results in a "trailing garbage" error map json '{"externalId":"10000000001","osFamily":"IOS","macAddress":"6C:4D:73:8B:51:00","guid":"Enrollment-000000000-0000-0000-0000-000000000000","isRevoked":false,"configurationType":"HS2R1","certificateSerialNumber":"0000c92c8d4896458ecfb70323d5cf81ddc0000","isExpired":false}' { - &Filter-Id := '$.externalId' - &Vendor-Specific.Fortinet.WirelessController-Device-MAC := '$.macAddress' + Filter-Id := '$.externalId' + Vendor-Specific.Fortinet.WirelessController-Device-MAC := '$.macAddress' } -if !(&Filter-Id == "10000000001") { +if !(Filter-Id == "10000000001") { test_fail } -if (&Vendor-Specific.Fortinet.WirelessController-Device-MAC != 6C:4D:73:8B:51:00) { +if (Vendor-Specific.Fortinet.WirelessController-Device-MAC != 6C:4D:73:8B:51:00) { test_fail } diff --git a/src/tests/modules/json/regression02.unlang b/src/tests/modules/json/regression02.unlang index 1a1af4afde0..db46b4e3cd0 100644 --- a/src/tests/modules/json/regression02.unlang +++ b/src/tests/modules/json/regression02.unlang @@ -1,29 +1,29 @@ string test_string # An error string from Azure AD, try and access all the bits -&test_string := "{\"error\":\"invalid_grant\",\"error_description\":\"AADSTS50126: Error validating credentials due to invalid username or password.\\r\\nTrace ID: 20bb60a5-5504-4a6b-ab40-a353a95c2500\\r\\nCorrelation ID: e58bb567-ad15-4a46-8341-cc6e800dd817\\r\\nTimestamp: 2023-02-11 02:32:40Z\",\"error_codes\":[50126],\"timestamp\":\"2023-02-11 02:32:40Z\",\"trace_id\":\"20bb60a5-5504-4a6b-ab40-a353a95c2500\",\"correlation_id\":\"e58bb567-ad15-4a46-8341-cc6e800dd817\",\"error_uri\":\"https://login.microsoftonline.com/error?code=50126\"}" +test_string := "{\"error\":\"invalid_grant\",\"error_description\":\"AADSTS50126: Error validating credentials due to invalid username or password.\\r\\nTrace ID: 20bb60a5-5504-4a6b-ab40-a353a95c2500\\r\\nCorrelation ID: e58bb567-ad15-4a46-8341-cc6e800dd817\\r\\nTimestamp: 2023-02-11 02:32:40Z\",\"error_codes\":[50126],\"timestamp\":\"2023-02-11 02:32:40Z\",\"trace_id\":\"20bb60a5-5504-4a6b-ab40-a353a95c2500\",\"correlation_id\":\"e58bb567-ad15-4a46-8341-cc6e800dd817\",\"error_uri\":\"https://login.microsoftonline.com/error?code=50126\"}" -map json &test_string { - &Filter-Id := '$.error' - &Callback-Id := '$.error_description' - &Called-Station-Id := '$.error_uri' - &NAS-Port := '$.error_codes[0]' +map json test_string { + Filter-Id := '$.error' + Callback-Id := '$.error_description' + Called-Station-Id := '$.error_uri' + NAS-Port := '$.error_codes[0]' } -if (&Filter-Id != 'invalid_grant') { +if (Filter-Id != 'invalid_grant') { test_fail } -if (&Callback-Id != "AADSTS50126: Error validating credentials due to invalid username or password.\r\nTrace ID: 20bb60a5-5504-4a6b-ab40-a353a95c2500\r\nCorrelation ID: e58bb567-ad15-4a46-8341-cc6e800dd817\r\nTimestamp: 2023-02-11 02:32:40Z") { +if (Callback-Id != "AADSTS50126: Error validating credentials due to invalid username or password.\r\nTrace ID: 20bb60a5-5504-4a6b-ab40-a353a95c2500\r\nCorrelation ID: e58bb567-ad15-4a46-8341-cc6e800dd817\r\nTimestamp: 2023-02-11 02:32:40Z") { test_fail } -if (&Called-Station-Id != 'https://login.microsoftonline.com/error?code=50126') { +if (Called-Station-Id != 'https://login.microsoftonline.com/error?code=50126') { test_fail } # This was being parsed as a negative integer -if (&NAS-Port != 50126) { +if (NAS-Port != 50126) { test_fail } diff --git a/src/tests/modules/json/regression03.unlang b/src/tests/modules/json/regression03.unlang index 786593da25f..a826f478a25 100644 --- a/src/tests/modules/json/regression03.unlang +++ b/src/tests/modules/json/regression03.unlang @@ -1,9 +1,9 @@ # Verify parsing works correctly with an unquoted xlat map json %test.passthrough("{ \"foo\":\"bar\" }",{}) { - &Filter-Id := '$.foo' + Filter-Id := '$.foo' } -if (!(&Filter-Id == 'bar')) { +if (!(Filter-Id == 'bar')) { test_fail } test_pass