From: Nick Porter Date: Fri, 19 May 2023 16:14:25 +0000 (+0100) Subject: Register instance specific module xlats as . X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f11ee983ae01ecf01a923014e6edb07c08f875e7;p=thirdparty%2Ffreeradius-server.git Register instance specific module xlats as . --- diff --git a/doc/antora/modules/raddb/pages/mods-available/json.adoc b/doc/antora/modules/raddb/pages/mods-available/json.adoc index a15fab909a8..0ef06abf63d 100644 --- a/doc/antora/modules/raddb/pages/mods-available/json.adoc +++ b/doc/antora/modules/raddb/pages/mods-available/json.adoc @@ -77,7 +77,7 @@ map json "%(rest:GET http://example.org/api/user/%{User-Name})" { The only options for the JSON module are to control the output -format of the `json_encode` xlat. +format of the `json.encode` xlat. @@ -187,7 +187,7 @@ Escapes string for use as a JSON string. The string caipirinha/gelada should be caipirinha\\/gelada to be a valid JSON string. ``` -### %{json_encode:...} +### %{json.encode:...} Generates a JSON document from a given list of attribute templates. The format of document generated can be controlled with the 'encode' section in @@ -210,7 +210,7 @@ it, `link:https://freeradius.org/rfc/rfc2865.html#User-Name[User-Name]` and `lin .Example ``` -%{json_encode:&User-Name &Calling-Station-Id} +%{json.encode:&User-Name &Calling-Station-Id} ``` The following will include all attributes in the RADIUS request, except for @@ -219,7 +219,7 @@ The following will include all attributes in the RADIUS request, except for .Example ``` -%{json_encode:&request[*] !&User-Password} +%{json.encode:&request[*] !&User-Password} ``` In another (contrived) example, all the attributes in the RADIUS request will @@ -229,7 +229,7 @@ be included in the document, _except_ any attributes in the RADIUS reply. .Example ``` -%{json_encode:&request[*] !&reply[*] &control.User-Name} +%{json.encode:&request[*] !&reply[*] &control.User-Name} ``` #### Output format modes diff --git a/raddb/mods-available/json b/raddb/mods-available/json index 5bfad2bbb3d..f9028642300 100644 --- a/raddb/mods-available/json +++ b/raddb/mods-available/json @@ -81,7 +81,7 @@ json { # # The only options for the JSON module are to control the output - # format of the `json_encode` xlat. + # format of the `json.encode` xlat. # encode { @@ -204,7 +204,7 @@ json { # The string caipirinha/gelada should be caipirinha\\/gelada to be a valid JSON string. # ``` # -# ### %{json_encode:...} +# ### %{json.encode:...} # # Generates a JSON document from a given list of attribute templates. The # format of document generated can be controlled with the 'encode' section in @@ -227,7 +227,7 @@ json { # .Example # # ``` -# %{json_encode:&User-Name &Calling-Station-Id} +# %{json.encode:&User-Name &Calling-Station-Id} # ``` # # The following will include all attributes in the RADIUS request, except for @@ -236,7 +236,7 @@ json { # .Example # # ``` -# %{json_encode:&request[*] !&User-Password} +# %{json.encode:&request[*] !&User-Password} # ``` # # In another (contrived) example, all the attributes in the RADIUS request will @@ -246,7 +246,7 @@ json { # .Example # # ``` -# %{json_encode:&request[*] !&reply[*] &control.User-Name} +# %{json.encode:&request[*] !&reply[*] &control.User-Name} # ``` # # #### Output format modes diff --git a/src/lib/unlang/xlat_func.c b/src/lib/unlang/xlat_func.c index 5de229bab30..c5b24c589d1 100644 --- a/src/lib/unlang/xlat_func.c +++ b/src/lib/unlang/xlat_func.c @@ -173,6 +173,7 @@ xlat_t *xlat_func_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx { xlat_t *c; module_inst_ctx_t *our_mctx = NULL; + char inst_name[256]; fr_assert(xlat_root); @@ -181,6 +182,15 @@ xlat_t *xlat_func_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx return NULL; } + /* + * Name xlats other than those which are just the module instance + * as . + */ + if (mctx && name != mctx->inst->name) { + snprintf(inst_name, sizeof(inst_name), "%s.%s", mctx->inst->name, name); + name = inst_name; + } + /* * If it already exists, replace the instance. */ diff --git a/src/modules/rlm_cipher/rlm_cipher.c b/src/modules/rlm_cipher/rlm_cipher.c index 8729bf1e412..6abfe0b480c 100644 --- a/src/modules/rlm_cipher/rlm_cipher.c +++ b/src/modules/rlm_cipher/rlm_cipher.c @@ -575,7 +575,7 @@ static xlat_arg_parser_t const cipher_rsa_encrypt_xlat_arg[] = { * Arguments are @verbatim(...)@endverbatim * @verbatim -%{<inst>_encrypt:<plaintext>...} +%{<inst>.encrypt:<plaintext>...} @endverbatim * * If multiple arguments are provided they will be concatenated. @@ -636,7 +636,7 @@ static xlat_arg_parser_t const cipher_rsa_sign_xlat_arg[] = { * Arguments are @verbatim(<plaintext>...)@endverbatim * @verbatim -%{<inst>_sign:<plaintext>...} +%{<inst>.sign:<plaintext>...} @endverbatim * * If multiple arguments are provided they will be concatenated. @@ -714,7 +714,7 @@ static xlat_arg_parser_t const cipher_rsa_decrypt_xlat_arg[] = { * Arguments are @verbatim(<ciphertext\>...)@endverbatim * @verbatim -%{<inst>_decrypt:<ciphertext>...} +%{<inst>.decrypt:<ciphertext>...} @endverbatim * * If multiple arguments are provided they will be concatenated. @@ -775,7 +775,7 @@ static xlat_arg_parser_t const cipher_rsa_verify_xlat_arg[] = { * Arguments are @verbatim(<signature>, <plaintext>...)@endverbatim * @verbatim -%(<inst>_verify:<signature> <plaintext>...) +%(<inst>.verify:<signature> <plaintext>...) @endverbatim * * If multiple arguments are provided (after @verbatim<signature>@endverbatim) @@ -890,7 +890,7 @@ static xlat_arg_parser_t const cipher_certificate_xlat_args[] = { * Arguments are @verbatim(<digest>)@endverbatim * @verbatim -%(<inst>_certificate:fingerprint <digest>) +%(<inst>.certificate:fingerprint <digest>) @endverbatim * * @ingroup xlat_functions @@ -939,7 +939,7 @@ static xlat_action_t cipher_fingerprint_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, /** Return the serial of the public certificate * @verbatim -%(<inst>_certificate:serial) +%(<inst>.certificate:serial) @endverbatim * * @ingroup xlat_functions @@ -1293,28 +1293,22 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) } if (inst->rsa->private_key_file) { - char *xlat_name; xlat_t *xlat; /* * Register decrypt xlat */ - xlat_name = talloc_asprintf(inst, "%s_decrypt", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, xlat_name, cipher_rsa_decrypt_xlat, FR_TYPE_STRING); + xlat = xlat_func_register_module(inst, mctx, "decrypt", cipher_rsa_decrypt_xlat, FR_TYPE_STRING); xlat_func_mono_set(xlat, cipher_rsa_decrypt_xlat_arg); - talloc_free(xlat_name); /* * Verify sign xlat */ - xlat_name = talloc_asprintf(inst, "%s_verify", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, xlat_name, cipher_rsa_verify_xlat, FR_TYPE_BOOL); + xlat = xlat_func_register_module(inst, mctx, "verify", cipher_rsa_verify_xlat, FR_TYPE_BOOL); xlat_func_args_set(xlat, cipher_rsa_verify_xlat_arg); - talloc_free(xlat_name); } if (inst->rsa->certificate_file) { - char *xlat_name; xlat_t *xlat; /* @@ -1336,28 +1330,21 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Register encrypt xlat */ - xlat_name = talloc_asprintf(inst, "%s_encrypt", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, xlat_name, cipher_rsa_encrypt_xlat, FR_TYPE_OCTETS); + xlat = xlat_func_register_module(inst, mctx, "encrypt", cipher_rsa_encrypt_xlat, FR_TYPE_OCTETS); xlat_func_mono_set(xlat, cipher_rsa_encrypt_xlat_arg); - talloc_free(xlat_name); /* * Register sign xlat */ - xlat_name = talloc_asprintf(inst, "%s_sign", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, xlat_name, cipher_rsa_sign_xlat, FR_TYPE_OCTETS); + xlat = xlat_func_register_module(inst, mctx, "sign", cipher_rsa_sign_xlat, FR_TYPE_OCTETS); xlat_func_mono_set(xlat, cipher_rsa_sign_xlat_arg); - talloc_free(xlat_name); /* * FIXME: These should probably be split into separate xlats * so we can optimise for return types. */ - xlat_name = talloc_asprintf(inst, "%s_certificate", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, xlat_name, cipher_certificate_xlat, FR_TYPE_VOID); + xlat = xlat_func_register_module(inst, mctx, "certificate", cipher_certificate_xlat, FR_TYPE_VOID); xlat_func_args_set(xlat, cipher_certificate_xlat_args); - - talloc_free(xlat_name); } break; diff --git a/src/modules/rlm_escape/rlm_escape.c b/src/modules/rlm_escape/rlm_escape.c index dc1cc5c5ffe..82f707d48e2 100644 --- a/src/modules/rlm_escape/rlm_escape.c +++ b/src/modules/rlm_escape/rlm_escape.c @@ -193,18 +193,15 @@ static xlat_action_t unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, */ static int mod_bootstrap(module_inst_ctx_t const *mctx) { - char *unescape; xlat_t *xlat; - MEM(unescape = talloc_asprintf(NULL, "un%s", mctx->inst->name)); - xlat = xlat_func_register_module(NULL, mctx, mctx->inst->name, escape_xlat, FR_TYPE_STRING); + xlat = xlat_func_register_module(NULL, mctx, "escape", escape_xlat, FR_TYPE_STRING); xlat_func_mono_set(xlat, escape_xlat_arg); xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE); - xlat = xlat_func_register_module(NULL, mctx, unescape, unescape_xlat, FR_TYPE_STRING); + xlat = xlat_func_register_module(NULL, mctx, "unescape", unescape_xlat, FR_TYPE_STRING); xlat_func_mono_set(xlat, unescape_xlat_arg); xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE); - talloc_free(unescape); return 0; } diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index eac3de93d90..d7ccd80e601 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -161,7 +161,7 @@ static xlat_arg_parser_t const json_encode_xlat_arg[] = { /** Convert given attributes to a JSON document * - * Usage is `%{json_encode:attr tmpl list}` + * Usage is `%{json.encode:attr tmpl list}` * * @ingroup xlat_functions */ @@ -528,13 +528,10 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) rlm_json_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_json_t); CONF_SECTION *conf = mctx->inst->conf; xlat_t *xlat; - char *name; fr_json_format_t *format = inst->format; - name = talloc_asprintf(inst, "%s_encode", mctx->inst->name); - xlat = xlat_func_register_module(inst, mctx, name, json_encode_xlat, FR_TYPE_STRING); + xlat = xlat_func_register_module(inst, mctx, "encode", json_encode_xlat, FR_TYPE_STRING); xlat_func_mono_set(xlat, json_encode_xlat_arg); - talloc_free(name); /* * Check the output format type and warn on unused diff --git a/src/modules/rlm_redis/rlm_redis.c b/src/modules/rlm_redis/rlm_redis.c index e443bb65af2..bdbbeabd4f8 100644 --- a/src/modules/rlm_redis/rlm_redis.c +++ b/src/modules/rlm_redis/rlm_redis.c @@ -239,7 +239,7 @@ static xlat_arg_parser_t const redis_remap_xlat_args[] = { /** Force a redis cluster remap * @verbatim -%{redis_remap:<redis server ip>:<redis server port>} +%{redis.remap:<redis server ip>:<redis server port>} @endverbatim * * @ingroup xlat_functions @@ -301,7 +301,7 @@ static xlat_arg_parser_t const redis_node_xlat_args[] = { /** Return the node that is currently servicing a particular key * @verbatim -%(redis_node:<key> [<index>]) +%(redis.node:<key> [<index>]) @endverbatim * * @ingroup xlat_functions @@ -856,35 +856,28 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) static int mod_bootstrap(module_inst_ctx_t const *mctx) { rlm_redis_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_t); - char *name; xlat_t *xlat; xlat = xlat_func_register_module(inst, mctx, mctx->inst->name, redis_xlat, FR_TYPE_VOID); xlat_func_args_set(xlat, redis_args); /* - * %(redis_node:<key>[ idx]) + * %(redis.node:<key>[ idx]) */ - name = talloc_asprintf(NULL, "%s_node", mctx->inst->name); - if (unlikely((xlat = xlat_func_register_module(inst, mctx, name, redis_node_xlat, FR_TYPE_STRING)) == NULL)) return -1; + if (unlikely((xlat = xlat_func_register_module(inst, mctx, "node", redis_node_xlat, FR_TYPE_STRING)) == NULL)) return -1; xlat_func_args_set(xlat, redis_node_xlat_args); - talloc_free(name); - name = talloc_asprintf(NULL, "%s_remap", mctx->inst->name); - if (unlikely((xlat = xlat_func_register_module(inst, mctx, name, redis_remap_xlat, FR_TYPE_STRING)) == NULL)) return -1; + if (unlikely((xlat = xlat_func_register_module(inst, mctx, "remap", redis_remap_xlat, FR_TYPE_STRING)) == NULL)) return -1; xlat_func_args_set(xlat, redis_remap_xlat_args); - talloc_free(name); /* * Loop over the lua functions, registering an xlat * that'll call that function specifically. */ talloc_foreach(inst->lua.funcs, func) { - name = talloc_asprintf(NULL, "%s.%s", mctx->inst->name, func->name); - if (unlikely((xlat = xlat_func_register_module(inst, mctx, name, redis_lua_func_xlat, FR_TYPE_VOID)) == NULL)) return -1; + if (unlikely((xlat = xlat_func_register_module(inst, mctx, func->name, redis_lua_func_xlat, FR_TYPE_VOID)) == NULL)) return -1; xlat_func_args_set(xlat, redis_lua_func_args); xlat_func_async_instantiate_set(xlat, redis_lua_func_instantiate, redis_lua_func_inst_t, NULL, func); - talloc_free(name); } return 0; diff --git a/src/tests/keywords/escape b/src/tests/keywords/escape index 8af127cd339..60f6f1ddb1a 100644 --- a/src/tests/keywords/escape +++ b/src/tests/keywords/escape @@ -15,39 +15,39 @@ # = not followed by hex and without 2 following chars &Tmp-String-8 := 'a=Az=y' -if (!(<string>"%{escape:%{Tmp-String-0}}" == &Tmp-String-0)) { +if (!(<string>"%{escape.escape:%{Tmp-String-0}}" == &Tmp-String-0)) { test_fail } -if (!(<string>"%{escape:%{Tmp-String-1}}" == &Tmp-String-3)) { +if (!(<string>"%{escape.escape:%{Tmp-String-1}}" == &Tmp-String-3)) { test_fail } -if (!(<string>"%{escape:%{Tmp-String-2}}" == &Tmp-String-4)) { +if (!(<string>"%{escape.escape:%{Tmp-String-2}}" == &Tmp-String-4)) { test_fail } -if (!(<string>"%{unescape:%{Tmp-String-0}}" == &Tmp-String-0)) { +if (!(<string>"%{escape.unescape:%{Tmp-String-0}}" == &Tmp-String-0)) { test_fail } -if (!(<string>"%{unescape:%{Tmp-String-3}}" == "%{Tmp-String-1}")) { +if (!(<string>"%{escape.unescape:%{Tmp-String-3}}" == "%{Tmp-String-1}")) { test_fail } -if (!(<string>"%{unescape:%{Tmp-String-4}}" == &Tmp-String-2)) { +if (!(<string>"%{escape.unescape:%{Tmp-String-4}}" == &Tmp-String-2)) { test_fail } -if (!(<string>"%{escape:%{Tmp-String-6}}" == &Tmp-String-7)) { +if (!(<string>"%{escape.escape:%{Tmp-String-6}}" == &Tmp-String-7)) { test_fail } -if (!(<string>"%{unescape:%{Tmp-String-7}}" == &Tmp-String-6)) { +if (!(<string>"%{escape.unescape:%{Tmp-String-7}}" == &Tmp-String-6)) { test_fail } -if (!(<string>"%{unescape:%{Tmp-String-8}}" == &Tmp-String-8)) { +if (!(<string>"%{escape.unescape:%{Tmp-String-8}}" == &Tmp-String-8)) { test_fail } diff --git a/src/tests/modules/cipher/fingerprint.unlang b/src/tests/modules/cipher/fingerprint.unlang index ce1b69a61b3..83ae8deda3c 100644 --- a/src/tests/modules/cipher/fingerprint.unlang +++ b/src/tests/modules/cipher/fingerprint.unlang @@ -2,7 +2,7 @@ # We can't really check the values here as the certs change periodically # but we can test the digest length, and for smoke... # -&Tmp-Octets-0 := "%(cipher_rsa_certificate:fingerprint sha1)" +&Tmp-Octets-0 := "%(cipher_rsa.certificate:fingerprint sha1)" if ("%(length:%{Tmp-Octets-0})" != 20) { test_fail @@ -10,7 +10,7 @@ if ("%(length:%{Tmp-Octets-0})" != 20) { test_pass } -&Tmp-Octets-0 := "%(cipher_rsa_certificate:fingerprint sha256)" +&Tmp-Octets-0 := "%(cipher_rsa.certificate:fingerprint sha256)" if ("%(length:%{Tmp-Octets-0})" != 32) { test_fail diff --git a/src/tests/modules/cipher/rsa_encrypt_decrypt.unlang b/src/tests/modules/cipher/rsa_encrypt_decrypt.unlang index d7c5942d8d5..e86dfac24a8 100644 --- a/src/tests/modules/cipher/rsa_encrypt_decrypt.unlang +++ b/src/tests/modules/cipher/rsa_encrypt_decrypt.unlang @@ -1,5 +1,5 @@ &Tmp-String-0 := "Hello world!" -&Tmp-Octets-0 := "%{cipher_rsa_encrypt:%{Tmp-String-0}}" +&Tmp-Octets-0 := "%{cipher_rsa.encrypt:%{Tmp-String-0}}" if (!&Tmp-Octets-0) { test_fail @@ -15,7 +15,7 @@ else { test_pass } -&Tmp-String-1 := "%{cipher_rsa_decrypt:%{Tmp-Octets-0}}" +&Tmp-String-1 := "%{cipher_rsa.decrypt:%{Tmp-Octets-0}}" if (&Tmp-String-0 != &Tmp-String-1) { test_fail @@ -27,7 +27,7 @@ else { # # Padding scheme should ensure ciphertext is not consistent # -&Tmp-Octets-1 := "%{cipher_rsa_encrypt:%{Tmp-String-0}}" +&Tmp-Octets-1 := "%{cipher_rsa.encrypt:%{Tmp-String-0}}" if (&Tmp-Octets-0 == &Tmp-Octets-1) { test_fail @@ -40,7 +40,7 @@ else { # Repeat tests to ensure there are no issues with EVP_PKEY_CTX reuse # &Tmp-String-0 := "Goodbye world!" -&Tmp-Octets-0 := "%{cipher_rsa_encrypt:%{Tmp-String-0}}" +&Tmp-Octets-0 := "%{cipher_rsa.encrypt:%{Tmp-String-0}}" if (!&Tmp-Octets-0) { test_fail @@ -56,7 +56,7 @@ else { test_pass } -&Tmp-String-1 := "%{cipher_rsa_decrypt:%{Tmp-Octets-0}}" +&Tmp-String-1 := "%{cipher_rsa.decrypt:%{Tmp-Octets-0}}" if (&Tmp-String-0 != &Tmp-String-1) { test_fail diff --git a/src/tests/modules/cipher/rsa_sign_verify.unlang b/src/tests/modules/cipher/rsa_sign_verify.unlang index 3c19bb850ba..5325fc66c03 100644 --- a/src/tests/modules/cipher/rsa_sign_verify.unlang +++ b/src/tests/modules/cipher/rsa_sign_verify.unlang @@ -1,86 +1,64 @@ &Tmp-String-0 := "Hello world!" -&Tmp-Octets-0 := "%{cipher_rsa_sign:%{Tmp-String-0}}" +&Tmp-Octets-0 := "%{cipher_rsa.sign:%{Tmp-String-0}}" if (!&Tmp-Octets-0) { test_fail } -else { - test_pass -} if (<octets>&Tmp-String-0[0] == &Tmp-Octets-0[0]) { test_fail } -else { - test_pass -} # # Pass the signature and the original message to the verification function # -&Tmp-String-0 := "%(cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0})" +&Tmp-String-0 := "%(cipher_rsa.verify:%{Tmp-Octets-0} %{Tmp-String-0})" if (&Tmp-String-0 != 'yes') { test_fail } -else { - test_pass -} # # Verification should now fail # &Tmp-String-0 := "Goodbye world!" -&Tmp-String-0 := "%(cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0})" +&Tmp-String-0 := "%(cipher_rsa.verify:%{Tmp-Octets-0} %{Tmp-String-0})" if (&Tmp-String-0 != 'no') { test_fail } -else { - test_pass -} # # Repeat tests to ensure there are no issues with EVP_PKEY_CTX reuse # &Tmp-String-0 := "Hello nurse!" -&Tmp-Octets-0 := "%{cipher_rsa_sign:%{Tmp-String-0}}" +&Tmp-Octets-0 := "%{cipher_rsa.sign:%{Tmp-String-0}}" if (!&Tmp-Octets-0) { test_fail } -else { - test_pass -} if (<octets>&Tmp-String-0[0] == &Tmp-Octets-0[0]) { test_fail } -else { - test_pass -} # # Pass the signature and the original message to the verification function # -&Tmp-String-0 := "%(cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0})" +&Tmp-String-0 := "%(cipher_rsa.verify:%{Tmp-Octets-0} %{Tmp-String-0})" if (&Tmp-String-0 != 'yes') { test_fail } -else { - test_pass -} # # Verification should now fail # &Tmp-String-0 := "Goodbye nurse!" -&Tmp-String-0 := "%(cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0})" +&Tmp-String-0 := "%(cipher_rsa.verify:%{Tmp-Octets-0} %{Tmp-String-0})" if (&Tmp-String-0 != 'no') { test_fail } -else { - test_pass -} + +test_pass diff --git a/src/tests/modules/cipher/serial.unlang b/src/tests/modules/cipher/serial.unlang index 3e85aa5d092..01a168a5622 100644 --- a/src/tests/modules/cipher/serial.unlang +++ b/src/tests/modules/cipher/serial.unlang @@ -1,4 +1,4 @@ -&Tmp-Octets-0 := "%(cipher_rsa_certificate:serial)" +&Tmp-Octets-0 := "%(cipher_rsa.certificate:serial)" if ("%(length:%{Tmp-Octets-0})" != 1) { test_fail diff --git a/src/tests/modules/cipher/valid.unlang b/src/tests/modules/cipher/valid.unlang index d8aac72735d..aed4692c0b5 100644 --- a/src/tests/modules/cipher/valid.unlang +++ b/src/tests/modules/cipher/valid.unlang @@ -1,5 +1,5 @@ -&Tmp-Date-0 := "%(cipher_rsa_certificate:notBefore)" -&Tmp-Date-1 := "%(cipher_rsa_certificate:notAfter)" +&Tmp-Date-0 := "%(cipher_rsa.certificate:notBefore)" +&Tmp-Date-1 := "%(cipher_rsa.certificate:notAfter)" # Check the cert validity period is 30 days if (<uint32>"%{expr:%(integer:%{Tmp-Date-1}) - %(integer:%{Tmp-Date-0})}" != <uint32>"%{expr:86400 * 60}") { diff --git a/src/tests/modules/json/encode.unlang b/src/tests/modules/json/encode.unlang index 1f9edd99fda..d04d54cf98f 100644 --- a/src/tests/modules/json/encode.unlang +++ b/src/tests/modules/json/encode.unlang @@ -1,18 +1,18 @@ # -# json_encode tests +# json.encode tests # &request -= &Packet-Type[*] # 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.[*] ! }" +&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.[*]}" +&control.Tmp-String-7 := "%{json_object.encode:&request.[*]}" +&control.Tmp-String-8 := "%{json_object_no.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"}}')) { test_fail @@ -43,8 +43,8 @@ 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.[*]}" +&control.Tmp-String-1 := "%{json_object.encode:&request.[*]}" +&control.Tmp-String-2 := "%{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"}}') { test_fail @@ -56,15 +56,15 @@ if !(&control.Tmp-String-2 == '{"pf:User-Name":{"type":"string","value":["john"] } # 1b. "object" empty inputs -&control.Tmp-String-1 := "%{json_object_encode:!&request.[*]}" +&control.Tmp-String-1 := "%{json_object.encode:!&request.[*]}" if !(&control.Tmp-String-1 == '{}') { 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.[*]}" +&control.Tmp-String-1 := "%{json_object_simple.encode:&request.[*]}" +&control.Tmp-String-2 := "%{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"}') { test_fail @@ -75,15 +75,15 @@ if !(&control.Tmp-String-2 == '{"pf:User-Name":["john"],"pf:Filter-Id":["f1","f2 } # 2b. "object_simple" empty inputs -&control.Tmp-String-1 := "%{json_object_simple_encode:!&request.[*]}" +&control.Tmp-String-1 := "%{json_object_simple.encode:!&request.[*]}" if !(&control.Tmp-String-1 == '{}') { test_fail } # 3a. Output mode "array" tests -&control.Tmp-String-1 := "%{json_array_encode:&request.[*]}" -&control.Tmp-String-2 := "%{json_array_ex_encode:&request.[*]}" +&control.Tmp-String-1 := "%{json_array.encode:&request.[*]}" +&control.Tmp-String-2 := "%{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"}]') { test_fail @@ -94,15 +94,15 @@ if !(&control.Tmp-String-2 == '[{"name":"pf:User-Name","type":"string","value":[ } # 3b. "array" empty inputs -&control.Tmp-String-1 := "%{json_array_encode:!&request.[*]}" +&control.Tmp-String-1 := "%{json_array.encode:!&request.[*]}" if !(&control.Tmp-String-1 == '[]') { 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.[*]}" +&control.Tmp-String-1 := "%{json_array_names.encode:&request.[*]}" +&control.Tmp-String-2 := "%{json_array_names_ex.encode:&request.[*]}" if !(&control.Tmp-String-1 == '["User-Name","Filter-Id","Filter-Id","NAS-Port","Service-Type"]') { test_fail @@ -113,15 +113,15 @@ if !(&control.Tmp-String-2 == '["pf:User-Name","pf:Filter-Id","pf:Filter-Id","pf } # 4b. "array_of_names" empty inputs -&control.Tmp-String-1 := "%{json_array_names_encode:!&request.[*]}" +&control.Tmp-String-1 := "%{json_array_names.encode:!&request.[*]}" if !(&control.Tmp-String-1 == '[]') { 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.[*]}" +&control.Tmp-String-1 := "%{json_array_values.encode:&request.[*]}" +&control.Tmp-String-2 := "%{json_array_values_ex.encode:&request.[*]}" if !(&control.Tmp-String-1 == '["john","f1","f2",999,"Login-User"]') { test_fail @@ -132,7 +132,7 @@ if !(&control.Tmp-String-2 == '["john","f1","f2","999","1"]') { } # 5b. "array_of_values" empty inputs -&control.Tmp-String-1 := "%{json_array_values_encode:!&request.[*]}" +&control.Tmp-String-1 := "%{json_array_values.encode:!&request.[*]}" if !(&control.Tmp-String-1 == '[]') { test_fail @@ -140,7 +140,7 @@ if !(&control.Tmp-String-1 == '[]') { # Convert `make json.test` unlang update output to tests, for when # things need updating. -# +# # cat \ # | cut -c44- \ # | sed -e 's/\\"/"/g' \ diff --git a/src/tests/modules/redis/cluster_key.unlang b/src/tests/modules/redis/cluster_key.unlang index 5a622a25cb5..a053697ed85 100644 --- a/src/tests/modules/redis/cluster_key.unlang +++ b/src/tests/modules/redis/cluster_key.unlang @@ -38,19 +38,19 @@ if ("%(redis:SET d "%{control.Tmp-String-2}")" == 'OK') { # # Now check they are where we expect # -if ("%(redis:@%(redis_node:b 0) GET b)" == "%{control.Tmp-String-0}") { +if ("%(redis:@%(redis.node:b 0) GET b)" == "%{control.Tmp-String-0}") { test_pass } else { test_fail } -if ("%(redis:@%(redis_node:c 0) GET c)" == "%{control.Tmp-String-1}") { +if ("%(redis:@%(redis.node:c 0) GET c)" == "%{control.Tmp-String-1}") { test_pass } else { test_fail } -if ("%(redis:@%(redis_node:d 0) GET d)" == "%{control.Tmp-String-2}") { +if ("%(redis:@%(redis.node:d 0) GET d)" == "%{control.Tmp-String-2}") { test_pass } else { test_fail diff --git a/src/tests/modules/redis/cluster_node_fail.unlang b/src/tests/modules/redis/cluster_node_fail.unlang index 3775c324fa6..d4cab510c2f 100644 --- a/src/tests/modules/redis/cluster_node_fail.unlang +++ b/src/tests/modules/redis/cluster_node_fail.unlang @@ -12,13 +12,13 @@ if (!("%(redis:SET b 'boom')" == 'OK')) { %(delay:0.5) # Note the current master -&Tmp-String-1 := %(redis_node:b 0) +&Tmp-String-1 := %(redis.node:b 0) # Note the current replica -&Tmp-String-2 := %(redis_node:b 1) +&Tmp-String-2 := %(redis.node:b 1) # Cause one of the redis cluster nodes to SEGV -if ("%(redis:@%(redis_node:b 0) DEBUG SEGFAULT)" != '') { +if ("%(redis:@%(redis.node:b 0) DEBUG SEGFAULT)" != '') { test_fail } @@ -30,9 +30,9 @@ if (!("%(redis:@%{Tmp-String-2} CLUSTER FAILOVER TAKEOVER)" == 'OK')) { # Allow time for the takeover to propagate to other nodes foreach &control.Tmp-Integer-0 { # Keep remapping the cluster - %(redis_remap:%{Tmp-String-2}) + %(redis.remap:%{Tmp-String-2}) - if (%(redis_node:b 0) == &Tmp-String-2) { + if (%(redis.node:b 0) == &Tmp-String-2) { break } %(delay:0.5) @@ -43,7 +43,7 @@ if (!("%(redis:GET b)" == 'boom')) { } # Kill that one too -if ("%(redis:@%(redis_node:b) DEBUG SEGFAULT)" != '') { +if ("%(redis:@%(redis.node:b) DEBUG SEGFAULT)" != '') { test_fail } diff --git a/src/tests/modules/redis/cluster_reset.inc b/src/tests/modules/redis/cluster_reset.inc index ae4a42a0d78..677c7a1912b 100644 --- a/src/tests/modules/redis/cluster_reset.inc +++ b/src/tests/modules/redis/cluster_reset.inc @@ -66,7 +66,7 @@ foreach &control.Tmp-Integer-0 { # # Force a remap as the slaves don't show up in the cluster immediately # - if ("%(redis_remap:%{Tmp-String-0}:30001)" == 'success') { + if ("%(redis.remap:%{Tmp-String-0}:30001)" == 'success') { # Hashes to Redis cluster node master 0 (1) if (("%(redis:SET b "%{control.Tmp-String-0}")" == 'OK') && \ ("%(redis:SET c "%{control.Tmp-String-1}")" == 'OK') && \ @@ -76,9 +76,9 @@ foreach &control.Tmp-Integer-0 { # so we now need to figure out which slave each of those keys # ended up on. # - if (("%(redis:-@%(redis_node:b 1) GET b)" == "%{control.Tmp-String-0}") && \ - ("%(redis:-@%(redis_node:c 1) GET c)" == "%{control.Tmp-String-1}") && \ - ("%(redis:-@%(redis_node:d 1) GET d)" == "%{control.Tmp-String-2}")) { + if (("%(redis:-@%(redis.node:b 1) GET b)" == "%{control.Tmp-String-0}") && \ + ("%(redis:-@%(redis.node:c 1) GET c)" == "%{control.Tmp-String-1}") && \ + ("%(redis:-@%(redis.node:d 1) GET d)" == "%{control.Tmp-String-2}")) { break } } diff --git a/src/tests/modules/rest/rest_xlat.unlang b/src/tests/modules/rest/rest_xlat.unlang index a6c2cadcac2..cc05ebfb0f2 100644 --- a/src/tests/modules/rest/rest_xlat.unlang +++ b/src/tests/modules/rest/rest_xlat.unlang @@ -70,7 +70,7 @@ if (!(&control.Tmp-String-3[0] == 'Bob') || !(&control.Tmp-String-3[1] == 'dummy test_fail } -&control.Tmp-String-2 = "%{json_encode:&NAS-IP-Address}" +&control.Tmp-String-2 = "%{json.encode:&NAS-IP-Address}" # POST to https with JSON body data &Tmp-String-2 := "%(rest:POST https://%{Tmp-String-0}:%{Tmp-Integer-1}/user/%{User-Name}/mac/%{Called-Station-Id}?section=accounting %{control.Tmp-String-2})"