From: Alan T. DeKok Date: Fri, 31 Jan 2025 19:29:30 +0000 (-0500) Subject: re-add '&' to get the tests to pass X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ed588ee9c560f1789f1d8d54a3aeffb1e252587;p=thirdparty%2Ffreeradius-server.git re-add '&' to get the tests to pass the xlat argument parser still needs: %json.encode("&request.[*]") and this without the "&" doesn't work %json.encode("request.[*]) --- diff --git a/src/tests/modules/json/encode.unlang b/src/tests/modules/json/encode.unlang index c5a0f294679..d84b09ff05b 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 69adac27db9..58cf49dfa18 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 a7427d8e150..f44402055cc 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 @@ Filter-Id := "\ \"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 @@ Filter-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 @@ Filter-Id := "\ }" # 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 7b21443cf17..97f0799c6e2 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 df691de4ffb..4c5d852ff42 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 2c9be6c5b42..3b189bb0f36 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 db46b4e3cd0..1a1af4afde0 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 a826f478a25..786593da25f 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 diff --git a/src/tests/modules/linelog/module.conf b/src/tests/modules/linelog/module.conf index 22e5af4203a..83063a070ec 100644 --- a/src/tests/modules/linelog/module.conf +++ b/src/tests/modules/linelog/module.conf @@ -3,7 +3,7 @@ linelog linelog_fmt_and_ref { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_a.log + filename = "$ENV{MODULE_TEST_DIR}/test_a.log" } format = "%{User-Name} default" @@ -12,7 +12,7 @@ linelog linelog_fmt_and_ref { messages { test_exec = %exec('/bin/echo',"%{User-Name} exec") - test_attr = User-Name + test_attr = &User-Name test_xlat = "%{User-Name} xlat" test_literal = '%{User-Name} literal' test_empty = '' @@ -31,7 +31,7 @@ linelog linelog_ref { messages { test_exec = %exec('/bin/echo', "%{User-Name} exec") - test_attr = User-Name + test_attr = &User-Name test_xlat = "%{User-Name} xlat" test_literal = '%{User-Name} literal' } @@ -42,16 +42,16 @@ linelog linelog_fmt_and_ref_attr { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_c.log + filename = "$ENV{MODULE_TEST_DIR}/test_c.log" } - format = User-Name + format = &User-Name - reference = control.Filter-Id + reference = &control.Filter-Id messages { test_exec = %exec('/bin/echo', "%{User-Name} exec") - test_attr = User-Name + test_attr = &User-Name test_xlat = "%{User-Name} xlat" test_literal = '%{User-Name} literal' } @@ -62,10 +62,10 @@ linelog linelog_fmt { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_d.log + filename = "$ENV{MODULE_TEST_DIR}/test_d.log" } - format = User-Name + format = &User-Name } # Used by linelog @@ -73,7 +73,7 @@ linelog linelog_header { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_e.log + filename = "$ENV{MODULE_TEST_DIR}/test_e.log" } header = "Log started %{control.Callback-Id}" @@ -85,13 +85,13 @@ linelog linelog_escapes { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_escapes.log + filename = "$ENV{MODULE_TEST_DIR}/test_escapes.log" } reference = ".messages.%{control.Filter-Id}" messages { - test_attr = control.Callback-Id + test_attr = &control.Callback-Id test_xlat = "%{User-Name}\n\tbar" test_literal = 'foo\nbar' } @@ -102,24 +102,24 @@ linelog linelog_fmt_delim { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_delim.log + filename = "$ENV{MODULE_TEST_DIR}/test_delim.log" } delimiter = ", " - format = User-Name + format = &User-Name } linelog linelog_fmt_delim_xlat { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_xlat.log + filename = "$ENV{MODULE_TEST_DIR}/test_xlat.log" } delimiter = ", " - format = User-Name + format = &User-Name } # Used by linelog-multi @@ -127,7 +127,7 @@ linelog linelog_ref_multi { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_multi.log + filename = "$ENV{MODULE_TEST_DIR}/test_multi.log" } delimiter = ", " @@ -135,9 +135,9 @@ linelog linelog_ref_multi { reference = ".messages.%{control.Filter-Id}" messages { - test_multi_str = control.Reply-Message[*] - test_multi_octets = control.Class[*] - test_empty = control.User-Name[*] + test_multi_str = &control.Reply-Message[*] + test_multi_octets = &control.Class[*] + test_empty = &control.User-Name[*] } } @@ -146,7 +146,7 @@ linelog linelog_missing { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_missing.log + filename = "$ENV{MODULE_TEST_DIR}/test_missing.log" } } @@ -155,13 +155,13 @@ linelog linelog_missingref { destination = file file { - filename = $ENV{MODULE_TEST_DIR}/test_missing.log + filename = "$ENV{MODULE_TEST_DIR}/test_missing.log" } - reference = control.Filter-Id + reference = &control.Filter-Id messages { - valid = control.User-Name + valid = &control.User-Name } } diff --git a/src/tests/modules/rest/rest_xlat.unlang b/src/tests/modules/rest/rest_xlat.unlang index e96b7689c51..113171069ca 100644 --- a/src/tests/modules/rest/rest_xlat.unlang +++ b/src/tests/modules/rest/rest_xlat.unlang @@ -75,7 +75,7 @@ if (!(control.User-Name[0] == 'Bob') || !(control.User-Name[1] == 'dummy')) { test_fail } -test_string := %json.encode('request.NAS-IP-Address') +test_string := %json.encode('&request.NAS-IP-Address') # POST to https with JSON body data result_string := %rest('POST', "https://%{server_host}:%uri.safe(%{server_ssl_port})/user/%{User-Name}/mac/%{Called-Station-Id}?section=accounting", %{test_string})