From: Arran Cudbard-Bell Date: Wed, 2 Aug 2023 20:21:37 +0000 (-0500) Subject: json: Add test for consuming output from function like xlat X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8960c768ac3add83fd9bab77aa1e40826d6241bf;p=thirdparty%2Ffreeradius-server.git json: Add test for consuming output from function like xlat --- diff --git a/src/modules/rlm_test/rlm_test.c b/src/modules/rlm_test/rlm_test.c index 128277d682c..f85765d7814 100644 --- a/src/modules/rlm_test/rlm_test.c +++ b/src/modules/rlm_test/rlm_test.c @@ -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; } diff --git a/src/tests/keywords/radius.conf b/src/tests/keywords/radius.conf index 2ca0997a333..9efcdb58676 100644 --- a/src/tests/keywords/radius.conf +++ b/src/tests/keywords/radius.conf @@ -78,8 +78,8 @@ $TEMPLATE template_test } redundant redundant_test { - test1 - test2 + test1.passthrough + test2.passthrough } } diff --git a/src/tests/keywords/xlat-redundant b/src/tests/keywords/xlat-redundant index e552cf9f318..64938ced1ae 100644 --- a/src/tests/keywords/xlat-redundant +++ b/src/tests/keywords/xlat-redundant @@ -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 } diff --git a/src/tests/modules/json/module.conf b/src/tests/modules/json/module.conf index 04d1b1d4602..cbf0a304980 100644 --- a/src/tests/modules/json/module.conf +++ b/src/tests/modules/json/module.conf @@ -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 index 00000000000..6aa4cb61d3d --- /dev/null +++ b/src/tests/modules/json/regression03.unlang @@ -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