]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
json: Add test for consuming output from function like xlat
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 2 Aug 2023 20:21:37 +0000 (15:21 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 2 Aug 2023 20:21:44 +0000 (15:21 -0500)
src/modules/rlm_test/rlm_test.c
src/tests/keywords/radius.conf
src/tests/keywords/xlat-redundant
src/tests/modules/json/module.conf
src/tests/modules/json/regression03.unlang [new file with mode: 0644]

index 128277d682cfff393e92fc5f542031ccf640acab..f85765d7814e159fb542dc8775a0e7ef33e1db0a 100644 (file)
@@ -379,7 +379,7 @@ static xlat_action_t trigger_test_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
 }
 
 
-static xlat_arg_parser_t const test_xlat_args[] = {
+static xlat_arg_parser_t const test_xlat_passthrough_args[] = {
        { .required = true, .concat = true, .type = FR_TYPE_STRING },
        { .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .concat = true, .type = FR_TYPE_STRING },
        XLAT_ARG_PARSER_TERMINATOR
@@ -390,9 +390,9 @@ static xlat_arg_parser_t const test_xlat_args[] = {
  *
  * This just copies the input to the output.
  */
-static xlat_action_t test_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
-                              UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request,
-                              fr_value_box_list_t *in)
+static xlat_action_t test_xlat_passthrough(TALLOC_CTX *ctx, fr_dcursor_t *out,
+                                          UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request,
+                                          fr_value_box_list_t *in)
 {
        fr_value_box_t  *vb;
 
@@ -483,8 +483,8 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx)
                INFO("inst->tmpl_m is NULL");
        }
 
-       if (!(xlat = xlat_func_register_module(inst, mctx, mctx->inst->name, test_xlat, FR_TYPE_VOID))) return -1;
-       xlat_func_args_set(xlat, test_xlat_args);
+       if (!(xlat = xlat_func_register_module(inst, mctx, "passthrough", test_xlat_passthrough, FR_TYPE_VOID))) return -1;
+       xlat_func_args_set(xlat, test_xlat_passthrough_args);
 
        return 0;
 }
index 2ca0997a333e2a6a3a5de06012a8263d6c26fab8..9efcdb586761b35cf2258a406d2737bee8a396d5 100644 (file)
@@ -78,8 +78,8 @@ $TEMPLATE template_test
        }
 
        redundant redundant_test {
-               test1
-               test2
+               test1.passthrough
+               test2.passthrough
        }
 
 }
index e552cf9f318477f3bed3435008fdcf84e6209206..64938ced1ae255fdb41f65999a8ba119ad662cfd 100644 (file)
@@ -2,11 +2,11 @@
 #
 #  PRE: if
 #
-if (!(%(concat:%(test1:foo bar) '|') == "foo|bar")) {
+if (!(%(concat:%(test1.passthrough:foo bar) '|') == "foo|bar")) {
        test_fail
 }
 
-if (!(%(concat:%(test2:foo bar) '|') == "foo|bar")) {
+if (!(%(concat:%(test2.passthrough:foo bar) '|') == "foo|bar")) {
        test_fail
 }
 
index 04d1b1d460226f6543a7ec66171dd7ef0f192b51..cbf0a304980928b6403fdd491638392607370c8b 100644 (file)
@@ -148,3 +148,7 @@ json json_array_values_ex {
                }
        }
 }
+
+test {
+
+}
diff --git a/src/tests/modules/json/regression03.unlang b/src/tests/modules/json/regression03.unlang
new file mode 100644 (file)
index 0000000..6aa4cb6
--- /dev/null
@@ -0,0 +1,9 @@
+# Verify parsing works correctly with an unquoted xlat
+map json %(test.passthrough:"{ \"foo\":\"bar\" }" {}) {
+       &Tmp-String-0 := '$.foo'
+}
+
+if (!(&Tmp-String-0 == 'bar')) {
+       test_fail
+}
+test_pass