]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove Tmp- attributes from json module tests
authorNick Porter <nick@portercomputing.co.uk>
Mon, 8 Jan 2024 11:48:09 +0000 (11:48 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Mon, 8 Jan 2024 11:48:09 +0000 (11:48 +0000)
src/tests/modules/json/encode.unlang
src/tests/modules/json/encode_error.unlang
src/tests/modules/json/eval.unlang
src/tests/modules/json/json_quote.unlang
src/tests/modules/json/regression01.unlang
src/tests/modules/json/regression02.unlang
src/tests/modules/json/regression03.unlang

index e22c6800f72f99a15912281cbad3a744bbf9df75..d84b09ff05b7cd571e2bbf92e475fa4b607f489c 100644 (file)
@@ -1,3 +1,8 @@
+string test_string1
+string test_string2
+string test_string3
+string test_string4
+string test_string5
 #
 #      json.encode tests
 #
 &request -= &Net[*]
 
 # 0. Check basic xlat parsing
-&control.Tmp-String-1 := %json.encode("&request.[*]")
-&control.Tmp-String-2 := %json.encode("&request.[*] ")
-&control.Tmp-String-3 := %json.encode(" &request.[*]")
-&control.Tmp-String-4 := %json.encode("         &request.[*]   ")
-&control.Tmp-String-5 := %json.encode(" &request.[*]    !&Filter-Id ")
-&control.Tmp-String-6 := %json.encode("&request.[*] ! ")
-#  Check defaults are the same as output_mode "object":
-&control.Tmp-String-7 := %json_object.encode("&request.[*]")
-&control.Tmp-String-8 := %json_object_no.encode("&request.[*]")
+&test_string1 := %json.encode("&request.[*]")
+&test_string2 := %json.encode("&request.[*] ")
+&test_string3 := %json.encode(" &request.[*]")
+&test_string4 := %json.encode("         &request.[*]   ")
 
-if (!(&control.Tmp-String-1 == '{"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 (!(&control.Tmp-String-1 == &control.Tmp-String-2) ||
-    !(&control.Tmp-String-1 == &control.Tmp-String-3) ||
-    !(&control.Tmp-String-1 == &control.Tmp-String-4)) {
+if (!(&test_string1 == &test_string2) ||
+    !(&test_string1 == &test_string3) ||
+    !(&test_string1 == &test_string4)) {
        test_fail
 }
 
-#  Check defaults
-if (!(&control.Tmp-String-1 == &control.Tmp-String-7) ||
-    !(&control.Tmp-String-1 == &control.Tmp-String-8)) {
+#  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_fail
 }
 
-if !(&control.Tmp-String-5 == '{"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
 }
 
-if &control.Tmp-String-6 {
+&test_string1 := %json.encode("&request.[*] ! ")
+if &test_string1 {
        test_fail
 }
 
@@ -56,98 +60,98 @@ if &control.Tmp-String-6 {
 
 # These are unsorted dictionaries. Hopefully json-c doesn't suddenly
 # decide that it's going to use a different ordering of the keys...
-&control.Tmp-String-1 := %json_object.encode("&request.[*]")
-&control.Tmp-String-2 := %json_object_ex.encode("&request.[*]")
+&test_string1 := %json_object.encode("&request.[*]")
+&test_string2 := %json_object_ex.encode("&request.[*]")
 
-if !(&control.Tmp-String-1 == '{"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
 }
 
-"%{control.Tmp-String-2}"
-if !(&control.Tmp-String-2 == '{"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_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"]}}') {
        test_fail
 }
 
 # 1b. "object" empty inputs
-&control.Tmp-String-1 := %json_object.encode("!&request.[*]")
+&test_string1 := %json_object.encode("!&request.[*]")
 
-if !(&control.Tmp-String-1 == '{}') {
+if !(&test_string1 == '{}') {
        test_fail
 }
 
 # 2a. Output mode "object_simple" tests
-&control.Tmp-String-1 := %json_object_simple.encode("&request.[*]")
-&control.Tmp-String-2 := %json_object_simple_ex.encode("&request.[*]")
+&test_string1 := %json_object_simple.encode("&request.[*]")
+&test_string2 := %json_object_simple_ex.encode("&request.[*]")
 
-if !(&control.Tmp-String-1 == '{"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 !(&control.Tmp-String-2 == '{"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
-&control.Tmp-String-1 := %json_object_simple.encode("!&request.[*]")
+&test_string1 := %json_object_simple.encode("!&request.[*]")
 
-if !(&control.Tmp-String-1 == '{}') {
+if !(&test_string1 == '{}') {
        test_fail
 }
 
 # 3a. Output mode "array" tests
-&control.Tmp-String-1 := %json_array.encode("&request.[*]")
-&control.Tmp-String-2 := %json_array_ex.encode("&request.[*]")
+&test_string1 := %json_array.encode("&request.[*]")
+&test_string2 := %json_array_ex.encode("&request.[*]")
 
-if !(&control.Tmp-String-1 == '[{"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 !(&control.Tmp-String-2 == '[{"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
-&control.Tmp-String-1 := %json_array.encode("!&request.[*]")
+&test_string1 := %json_array.encode("!&request.[*]")
 
-if !(&control.Tmp-String-1 == '[]') {
+if !(&test_string1 == '[]') {
        test_fail
 }
 
 # 4a. Output mode "array_of_names" tests
-&control.Tmp-String-1 := %json_array_names.encode("&request.[*]")
-&control.Tmp-String-2 := %json_array_names_ex.encode("&request.[*]")
+&test_string1 := %json_array_names.encode("&request.[*]")
+&test_string2 := %json_array_names_ex.encode("&request.[*]")
 
-if !(&control.Tmp-String-1 == '["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 !(&control.Tmp-String-2 == '["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
-&control.Tmp-String-1 := %json_array_names.encode("!&request.[*]")
+&test_string1 := %json_array_names.encode("!&request.[*]")
 
-if !(&control.Tmp-String-1 == '[]') {
+if !(&test_string1 == '[]') {
        test_fail
 }
 
 # 5a. Output mode "array_of_values" tests
-&control.Tmp-String-1 := %json_array_values.encode("&request.[*]")
-&control.Tmp-String-2 := %json_array_values_ex.encode("&request.[*]")
+&test_string1 := %json_array_values.encode("&request.[*]")
+&test_string2 := %json_array_values_ex.encode("&request.[*]")
 
-if !(&control.Tmp-String-1 == '["john","f1","f2",999,"Login-User"]') {
+if !(&test_string1 == '["john","f1","f2",999,"Login-User"]') {
        test_fail
 }
 
-if !(&control.Tmp-String-2 == '["john","f1","f2","999","1"]') {
+if !(&test_string2 == '["john","f1","f2","999","1"]') {
        test_fail
 }
 
 # 5b. "array_of_values" empty inputs
-&control.Tmp-String-1 := %json_array_values.encode("!&request.[*]")
+&test_string1 := %json_array_values.encode("!&request.[*]")
 
-if !(&control.Tmp-String-1 == '[]') {
+if !(&test_string1 == '[]') {
        test_fail
 }
 
index 91c6cf0673de7765f0e2c3509cdd0eccb0db832f..58cf49dfa18c3186766cea5795f85f42fd2ba679 100644 (file)
@@ -1,9 +1,10 @@
+string test_string
 #
 #       json xlat input parsing test - error with no input
 #
 
-&Tmp-String-1 := %json_object_ex_encode()  # ERROR
-if (&Tmp-String-1) {
+&test_string := %json_object_ex_encode()  # ERROR
+if (&test_string) {
        test_fail
 }
 
index d22f4afc621cca71fa0d24b3dfc5bf4a1384b3e4..f44402055cce9bdb37d9d26012dfb598ddbbd0f7 100644 (file)
@@ -1,19 +1,22 @@
 #
 #      Evaluation tests
 #
+uint32 test_integer
+int64 test_int64
+string test_string
 
-&Tmp-String-0 := "{\"foo\":\"bar\"}"
+&Filter-Id := "{\"foo\":\"bar\"}"
 
 # 0. Simple field access
-map json &Tmp-String-0 {
-       &Tmp-String-1 := '$.foo'
+map json &Filter-Id {
+       &Callback-Id := '$.foo'
 }
 
-if !(&Tmp-String-1 == 'bar') {
+if !(&Callback-Id == 'bar') {
        test_fail
 }
 
-&Tmp-String-0 := "\
+&Filter-Id := "\
 {\
        \"my_array\": [0, 1, 2, 3, 4, 5], \
        \"my_object\": { \
@@ -27,309 +30,309 @@ if !(&Tmp-String-1 == 'bar') {
        \"bool_false\": false \
 }"
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 # Check conversion of all JSON types to strings
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$.*'
+map json &Filter-Id {
+       &Callback-Id += '$.*'
 }
 
 # 1. Array type
-if !(&Tmp-String-1[0] == '[ 0, 1, 2, 3, 4, 5 ]') {
+if !(&Callback-Id[0] == '[ 0, 1, 2, 3, 4, 5 ]') {
        test_fail
 }
 
 # 2. Object type
-if !(&Tmp-String-1[1] == '{ "foo": "bar", "num": 42 }') {
+if !(&Callback-Id[1] == '{ "foo": "bar", "num": 42 }') {
        test_fail
 }
 
 # 3. Integer type
-if !(&Tmp-String-1[2] == '99') {
+if !(&Callback-Id[2] == '99') {
        test_fail
 }
 
 # 4. Double type
-if !(&Tmp-String-1[3] == '5.9') {
+if !(&Callback-Id[3] == '5.9') {
        test_fail
 }
 
 # 5. null type
-if !(&Tmp-String-1[4] == 'null') {
+if !(&Callback-Id[4] == 'null') {
        test_fail
 }
 
 # 6. Boolean true
-if !(&Tmp-String-1[5] == 'yes') {
+if !(&Callback-Id[5] == 'yes') {
        test_fail
 }
 
 # 7. Boolean false
-if (&Tmp-String-1[6] != 'no') {
+if (&Callback-Id[6] != 'no') {
        test_fail
 }
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 #
 # Now check array slicing operates correctly
 #
 
 # 8. String form
-map json &Tmp-String-0 {
-       &Tmp-String-1 := '$.my_array'
+map json &Filter-Id {
+       &Callback-Id := '$.my_array'
 }
-if !(&Tmp-String-1 == '[ 0, 1, 2, 3, 4, 5 ]') {
+if !(&Callback-Id == '[ 0, 1, 2, 3, 4, 5 ]') {
        test_fail
 }
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 # 9. Simple index
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 := '$.my_array[0]'
+map json &Filter-Id {
+       &NAS-Port := '$.my_array[0]'
 }
-if !(&Tmp-Integer-0 == 0) {
+if !(&NAS-Port == 0) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 9a. All of the array
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array.*'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array.*'
 }
-if (!(&Tmp-Integer-0[0] == 0) || !(&Tmp-Integer-0[1] == 1) || !(&Tmp-Integer-0[2] == 2) || !(&Tmp-Integer-0[3] == 3) || !(&Tmp-Integer-0[4] == 4) || !(&Tmp-Integer-0[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
 }
 
-&Tmp-Integer-0 := 9
+&NAS-Port := 9
 
 # 9b. All of the array using prepend, places the array before the existing value
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 ^= '$.my_array.*'
+map json &Filter-Id {
+       &NAS-Port ^= '$.my_array.*'
 }
-if (!(&Tmp-Integer-0[0] == 0) || !(&Tmp-Integer-0[1] == 1) || !(&Tmp-Integer-0[2] == 2) || !(&Tmp-Integer-0[3] == 3) || !(&Tmp-Integer-0[4] == 4) || !(&Tmp-Integer-0[5] == 5) || !(&Tmp-Integer-0[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 -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 10. End of the array
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 := '$.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 !(&Tmp-Integer-0 == 5) {
+if !(&NAS-Port == 5) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 11. Past end of the array
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 := '$.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 (&Tmp-Integer-0) {
+if (&NAS-Port) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 12. Simple slice
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[0:2]'     # A single value
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[0:2]'  # A single value
 }
-if (!(&Tmp-Integer-0[0] == 0) || !(&Tmp-Integer-0[1] == 1)) {
+if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 1)) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 13. Slice with negative start
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.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 !(&Tmp-Integer-0 == 5) {
+if !(&NAS-Port == 5) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 14. Slice with negative start and negative end
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.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 (&Tmp-Integer-0) {
+if (&NAS-Port) {
        test_fail
 }
 
 # 15. Slice with start and negative end
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[1:-3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[1:-3]'
 }
-if (!(&Tmp-Integer-0[0] == 1) && !(&Tmp-Integer-0[1] == 2)) {
+if (!(&NAS-Port[0] == 1) && !(&NAS-Port[1] == 2)) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 16. Slice with start, end and negative step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[4:2:-1]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[4:2:-1]'
 }
-if (!(&Tmp-Integer-0[0] == 4) || !(&Tmp-Integer-0[1] == 3)) {
+if (!(&NAS-Port[0] == 4) || !(&NAS-Port[1] == 3)) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 17. Slice with start, end (inverted) and negative step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[2:4:-1]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[2:4:-1]'
 }
-if (&Tmp-Integer-0) {
+if (&NAS-Port) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 18. Slice with start, end and positive step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[2:4:1]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[2:4:1]'
 }
-if (!(&Tmp-Integer-0[0] == 2) || !(&Tmp-Integer-0[1] == 3)) {
+if (!(&NAS-Port[0] == 2) || !(&NAS-Port[1] == 3)) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 19. Slice with start, end and positive step > 1
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[1:5:2]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[1:5:2]'
 }
-if (!(&Tmp-Integer-0[0] == 1) && !(&Tmp-Integer-0[1] == 3)) {
+if (!(&NAS-Port[0] == 1) && !(&NAS-Port[1] == 3)) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 20. Slice with start, end and positive step > end of array
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[1:5:4]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[1:5:4]'
 }
-if (!(&Tmp-Integer-0[0] == 1) || &Tmp-Integer-0[1]) {
+if (!(&NAS-Port[0] == 1) || &NAS-Port[1]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 21. Slice with start, end and positive step > end of array
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[5:1:-4]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[5:1:-4]'
 }
-if (!(&Tmp-Integer-0[0] == 5) || &Tmp-Integer-0[1]) {
+if (!(&NAS-Port[0] == 5) || &NAS-Port[1]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 22. No start/end 3 step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[::3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[::3]'
 }
-if (!(&Tmp-Integer-0[0] == 0) || !(&Tmp-Integer-0[1] == 3) || &Tmp-Integer-0[2]) {
+if (!(&NAS-Port[0] == 0) || !(&NAS-Port[1] == 3) || &NAS-Port[2]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 23. No start/end 3 step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[::-3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[::-3]'
 }
-if (!(&Tmp-Integer-0[0] == 5) || !(&Tmp-Integer-0[1] == 2) || &Tmp-Integer-0[2]) {
+if (!(&NAS-Port[0] == 5) || !(&NAS-Port[1] == 2) || &NAS-Port[2]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 24. No end 3 step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[3::-3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[3::-3]'
 }
-if (!(&Tmp-Integer-0[0] == 3) || !(&Tmp-Integer-0[1] == 0) || &Tmp-Integer-0[2]) {
+if (!(&NAS-Port[0] == 3) || !(&NAS-Port[1] == 0) || &NAS-Port[2]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 25. End 0, 3 step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[3:0:-3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[3:0:-3]'
 }
-if (!(&Tmp-Integer-0[0] == 3) || &Tmp-Integer-0[1]) {
+if (!(&NAS-Port[0] == 3) || &NAS-Port[1]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 26. End 0, 3 step
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += '$.my_array[0::-3]'
+map json &Filter-Id {
+       &NAS-Port += '$.my_array[0::-3]'
 }
-if (!(&Tmp-Integer-0[0] == 0) || &Tmp-Integer-0[1]) {
+if (!(&NAS-Port[0] == 0) || &NAS-Port[1]) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 27. Everything two levels deep
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$.*.*'
+map json &Filter-Id {
+       &Callback-Id += '$.*.*'
 }
 
-if (!(&Tmp-String-1[0] == '0') || \
-    !(&Tmp-String-1[1] == '1') || \
-    !(&Tmp-String-1[2] == '2') || \
-    !(&Tmp-String-1[3] == '3') || \
-    !(&Tmp-String-1[4] == '4') || \
-    !(&Tmp-String-1[5] == '5') || \
-    !(&Tmp-String-1[6] == 'bar') || \
-    !(&Tmp-String-1[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 -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 # 28. Everything three levels deep (nothing)
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$.*.*.*'
+map json &Filter-Id {
+       &Callback-Id += '$.*.*.*'
 }
 
-if (&Tmp-String-1) {
+if (&Callback-Id) {
        test_fail
 }
 
 # 29. Array access on a field (nothing)
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$.my_object[0]'
+map json &Filter-Id {
+       &Callback-Id += '$.my_object[0]'
 }
 
-if (&Tmp-String-1) {
+if (&Callback-Id) {
        test_fail
 }
 
 # 30. Non-existent field
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$.my_object.my_other_object'
+map json &Filter-Id {
+       &Callback-Id += '$.my_object.my_other_object'
 }
 
-if (&Tmp-String-1) {
+if (&Callback-Id) {
        test_fail
 }
 
 # Some big numbers in nested arrays
-&Tmp-String-0 := "\
+&Filter-Id := "\
 [\
        9223372036854775807, \
        -9223372036854775807, \
@@ -346,97 +349,95 @@ if (&Tmp-String-1) {
 # version/system dependent *sigh*.
 redundant {
        group {
-               map json &Tmp-String-0 {
-                       &Tmp-Integer-0 := '$[3][2]'
+               map json &Filter-Id {
+                       &NAS-Port := '$[3][2]'
                }
        }
        noop
 }
-if (!noop && (!(&Tmp-Integer-0 == 4294967295) && !(&Tmp-Integer-0 == 2147483647))) {
+if (!noop && (!(&NAS-Port == 4294967295) && !(&NAS-Port == 2147483647))) {
        test_fail
 }
 
 # 32. Unsigned 32bit integers (are supported)
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 := '$[3][0]'
+map json &Filter-Id {
+       &NAS-Port := '$[3][0]'
 }
-if !(&Tmp-Integer-0 == 2147483647) {
+if !(&NAS-Port == 2147483647) {
        test_fail
 }
 
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 33. Signed 64bit integers
 if (0) {
-map json &Tmp-String-0 {
-       &Tmp-int64-0 := '$[0]'
+map json &Filter-Id {
+       &test_int64 := '$[0]'
 }
-if !(&Tmp-int64-0 == (int64)9223372036854775807) {
+if !(&test_int64 == (int64)9223372036854775807) {
        test_fail
 }
 
-&request -= &Tmp-int64-0[*]
-
 # 34. Signed 64bit integers
-map json &Tmp-String-0 {
-       &Tmp-int64-0 := '$[1]'
+map json &Filter-Id {
+       &test_int64 := '$[1]'
 }
-if !(&Tmp-int64-0 == -9223372036854775807) {
+if !(&test_int64 == -9223372036854775807) {
        test_fail
 }
 
-&request -= &Tmp-int64-0[*]
+&request -= &test_int64[*]
 
 # 35. Unsigned 64bit integers (not allowed by json so gets truncated)
-map json &Tmp-String-0 {
-       &Tmp-uint64-0 := '$[2]'
+map json &Filter-Id {
+       &Acct-Input-Octets64 := '$[2]'
 }
-if !(&Tmp-uint64-0 == 9223372036854775807) {
+if !(&Acct-Input-Octets64 == 9223372036854775807) {
        test_fail
 }
 }
 
-&request -= &Tmp-uint64-0[*]
+&request -= &Acct-Input-Octets64[*]
 
 # 36. Multiple array indices
-map json &Tmp-String-0 {
-       &Tmp-Signed-0 += '$[3][0,1]'
+map json &Filter-Id {
+       &Cache-TTL += '$[3][0,1]'
 }
-if (!(&Tmp-Signed-0[0] == 2147483647) || !(&Tmp-signed-0[1] == -2147483647)) {
+if (!(&Cache-TTL[0] == 2147483647) || !(&Cache-TTL[1] == -2147483647)) {
        test_fail
 }
 
-&request -= &Tmp-Signed-0[*]
+&request -= &Cache-TTL[*]
 
 # 37. Path containing dynamic expansion
-&Tmp-Integer-2 := 0
+&test_integer := 0
 
-map json &Tmp-String-0 {
-       &Tmp-Integer-0 += "$[3][%{Tmp-Integer-2}]"
+map json &Filter-Id {
+       &NAS-Port += "$[3][%{test_integer}]"
 }
-if !(&Tmp-Integer-0 == 2147483647) {
+if !(&NAS-Port == 2147483647) {
        test_fail
 }
-&request -= &Tmp-Integer-0[*]
+&request -= &NAS-Port[*]
 
 # 38. An expanded field name with bad chars
-&Tmp-String-0 := "\
+&Filter-Id := "\
 {\
        \"foo.bar\": \"baz\" \
 }"
-&Tmp-String-2 := "%taint('foo.bar')"
+&test_string := "%taint('foo.bar')"
 
-map json &Tmp-String-0 {
-       &Tmp-String-1 := "$.%{Tmp-String-2}"
+map json &Filter-Id {
+       &Callback-Id := "$.%{test_string}"
 }
 
-if !(&Tmp-String-1 == 'baz') {
+if !(&Callback-Id == 'baz') {
        test_fail
 }
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
-&Tmp-String-0 := "\
+&Filter-Id := "\
 {\
        \"my_array\": [0, 1, 2, 3, 4, 5], \
        \"my_object\": { \
@@ -461,33 +462,33 @@ if !(&Tmp-String-1 == 'baz') {
 }"
 
 # 39. Recursive descent with field match
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$..bool'
+map json &Filter-Id {
+       &Callback-Id += '$..bool'
 }
 
-if (!("%{Tmp-String-1[#]}" == 1) || !(&Tmp-String-1 == 'yes')) {
+if (!("%{Callback-Id[#]}" == 1) || !(&Callback-Id == 'yes')) {
        test_fail
 }
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 # 40. Recursive descent with element match (2nd element in each array)
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$..[1]'
+map json &Filter-Id {
+       &Callback-Id += '$..[1]'
 }
-if (!("%{Tmp-String-1[#]}" == 3) || !(&Tmp-String-1[0] == '1') || !(&Tmp-String-1[1] == 'scratchy') || !(&Tmp-String-1[2] == 'clawy')) {
+if (!("%{Callback-Id[#]}" == 3) || !(&Callback-Id[0] == '1') || !(&Callback-Id[1] == 'scratchy') || !(&Callback-Id[2] == 'clawy')) {
        test_fail
 }
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 # 41. Recursive descent with field then element match
-map json &Tmp-String-0 {
-       &Tmp-String-1 += '$..my_cats[2]'
+map json &Filter-Id {
+       &Callback-Id += '$..my_cats[2]'
 }
-if (!("%{Tmp-String-1[#]}" == 2) || !(&Tmp-String-1[0] == 'flat') || !(&Tmp-String-1[1] == 'woofy')) {
+if (!("%{Callback-Id[#]}" == 2) || !(&Callback-Id[0] == 'flat') || !(&Callback-Id[1] == 'woofy')) {
        test_fail
 }
 
-&request -= &Tmp-String-1[*]
+&request -= &Callback-Id[*]
 
 test_pass
index 2ab0f9a1b07c83c6a7177ff60db3e758fd9089f7..fc3f9449f89631616111eef0c7b6bff2a01ac225 100644 (file)
@@ -1,34 +1,39 @@
-&Tmp-String-0 := "Hello\n"
-if (!(%json_quote(%{Tmp-String-0}) == "\"Hello\\n\"")) {
+string test_string
+uint32 test_integer
+ipaddr test_ipaddr
+string dummy_string
+
+&test_string := "Hello\n"
+if (!(%json_quote(%{test_string}) == "\"Hello\\n\"")) {
        test_fail
 }
 
-&Tmp-String-0 := "Hello\nbob"
-if (!(%json_quote(%{Tmp-String-0}) == "\"Hello\\nbob\"")) {
+&test_string := "Hello\nbob"
+if (!(%json_quote(%{test_string}) == "\"Hello\\nbob\"")) {
        test_fail
 }
 
-&Tmp-String-0 := "\nHello\nbob"
-if (!(%json_quote(%{Tmp-String-0}) == "\"\\nHello\\nbob\"")) {
+&test_string := "\nHello\nbob"
+if (!(%json_quote(%{test_string}) == "\"\\nHello\\nbob\"")) {
        test_fail
 }
 
-&Tmp-String-0 := "Hello!"
-if (!(%json_quote(%{Tmp-String-0}) == '"Hello!"')) {
+&test_string := "Hello!"
+if (!(%json_quote(%{test_string}) == '"Hello!"')) {
        test_fail
 }
 
-&Tmp-Integer-0 := 123456
-if (!(%json_quote(%{Tmp-Integer-0}) == '123456')) {
+&test_integer := 123456
+if (!(%json_quote(%{test_integer}) == '123456')) {
        test_fail
 }
 
-&Tmp-IP-Address-0 := 127.0.0.1
-if (!(%json_quote(%{Tmp-IP-Address-0}) == '"127.0.0.1"')) {
+&test_ipaddr := 127.0.0.1
+if (!(%json_quote(%{test_ipaddr}) == '"127.0.0.1"')) {
        test_fail
 }
 
-if (!(%json_quote(%{Tmp-String-1}) == 'null')) {
+if (!(%json_quote(%{dummy_string}) == 'null')) {
        test_fail
 }
 
index 6a6554b53e341c51b458d54c66a2f58c9a35785e..3b189bb0f36f293f7ca27b82cdd67d5c4a51093c 100644 (file)
@@ -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}' {
-       &Tmp-String-0 := '$.externalId'
-       &Tmp-Ethernet-0 := '$.macAddress'
+       &Filter-Id := '$.externalId'
+       &Vendor-Specific.Fortinet.WirelessController-Device-MAC := '$.macAddress'
 }
 
-if (&Tmp-String-0 != "10000000001") {
+if !(&Filter-Id == "10000000001") {
        test_fail
 }
 
-if (&Tmp-Ethernet-0 != 6C:4D:73:8B:51:00) {
+if (&Vendor-Specific.Fortinet.WirelessController-Device-MAC != 6C:4D:73:8B:51:00) {
        test_fail
 }
 
index fb4c990b5a89243a5cda5f198e0a3441f243dc46..1a1af4afde08184ed972776adbd4e137a68d25a7 100644 (file)
@@ -1,27 +1,29 @@
+string test_string
+
 # An error string from Azure AD, try and access all the bits
-&Tmp-String-0 := "{\"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 &Tmp-String-0 {
-       &Tmp-String-0 := '$.error'
-       &Tmp-String-1 := '$.error_description'
-       &Tmp-String-2 := '$.error_uri'
-       &Tmp-Integer-0 := '$.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 (&Tmp-String-0 != 'invalid_grant') {
+if (&Filter-Id != 'invalid_grant') {
        test_fail
 }
 
-if (&Tmp-String-1 != "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 (&Tmp-String-2 != '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 (&Tmp-Integer-0 != 50126) {
+if (&NAS-Port != 50126) {
        test_fail
 }
 
index 04676ad227634a5dc5af22940af2b0a723d1ac4b..786593da25f13dfd56d22e8b14795600ae00b2ea 100644 (file)
@@ -1,9 +1,9 @@
 # Verify parsing works correctly with an unquoted xlat
 map json %test.passthrough("{ \"foo\":\"bar\" }",{}) {
-       &Tmp-String-0 := '$.foo'
+       &Filter-Id := '$.foo'
 }
 
-if (!(&Tmp-String-0 == 'bar')) {
+if (!(&Filter-Id == 'bar')) {
        test_fail
 }
 test_pass