From: Alan T. DeKok Date: Thu, 31 Aug 2023 15:50:27 +0000 (-0400) Subject: fix unit_test_module to actually check the results X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4faa785e63c7378549824aa18b757e4e84c12d63;p=thirdparty%2Ffreeradius-server.git fix unit_test_module to actually check the results and remove the dependency on the radius-only xlats --- diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index d28ba5d415c..253d085a843 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -322,7 +322,7 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) char unescaped[sizeof(output_buff)]; request_t *request; fr_sbuff_t line; - fr_sbuff_t out = FR_SBUFF_OUT(output_buff, sizeof(output_buff)); + fr_sbuff_t out; static fr_sbuff_escape_rules_t unprintables = { .name = "unprintables", @@ -397,10 +397,30 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) * Ignore blank lines and comments */ fr_sbuff_adv_past_whitespace(&line, SIZE_MAX, NULL); - if (*fr_sbuff_current(&line) < ' ') continue; if (fr_sbuff_is_char(&line, '#')) continue; + /* + * Look for "match", as it needs the output_buffer to be left alone. + */ + if (fr_sbuff_adv_past_str_literal(&line, "match ") > 0) { + size_t output_len = strlen(output_buff); + + if (!fr_sbuff_is_str(&line, output_buff, output_len) || (output_len != fr_sbuff_remaining(&line))) { + fprintf(stderr, "Mismatch at %s[%u]\n\tgot : %s (%zu)\n\texpected : %s (%zu)\n", + filename, lineno, output_buff, output_len, fr_sbuff_current(&line), fr_sbuff_remaining(&line)); + TALLOC_FREE(request); + return false; + } + continue; + } + + /* + * The rest of the keywords create output. + */ + output_buff[0] = '\0'; + out = FR_SBUFF_OUT(output_buff, sizeof(output_buff)); + /* * Look for "xlat" */ @@ -481,7 +501,7 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) if (len < 0) { char const *err = fr_strerror(); talloc_free(xlat_ctx); - FR_SBUFF_IN_SPRINTF_RETURN(&out, "ERROR expanding xlat: %s", *err ? err : "no error provided"); + fr_sbuff_in_sprintf(&out, "ERROR expanding xlat: %s", *err ? err : "no error provided"); continue; } @@ -494,20 +514,6 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) continue; } - /* - * Look for "match". - */ - if (fr_sbuff_adv_past_str_literal(&line, "match ") > 0) { - size_t output_len = strlen(output_buff); - if (!fr_sbuff_is_str(&line, output_buff, output_len) && (output_len != fr_sbuff_remaining(&line))) { - fprintf(stderr, "Mismatch at %s[%u]\n\tgot : %s (%zu)\n\texpected : %s (%zu)\n", - filename, lineno, output_buff, output_len, fr_sbuff_current(&line), fr_sbuff_remaining(&line)); - TALLOC_FREE(request); - return false; - } - continue; - } - fprintf(stderr, "Unknown keyword in %s[%d]\n", filename, lineno); TALLOC_FREE(request); return false; diff --git a/src/tests/xlat/expr.txt b/src/tests/xlat/expr.txt index 9bfae24eacc..5602e3f7c61 100644 --- a/src/tests/xlat/expr.txt +++ b/src/tests/xlat/expr.txt @@ -1,6 +1,6 @@ # this is "foo" + PRINTABLE version of the packet authentication vector -xlat_expr "foo%{radius.packet.vector:}" -match foo\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 +xlat_expr "foo%{bin:000000}" +match foo\000\000\000 xlat_expr 1 && 2 match 2 @@ -106,12 +106,13 @@ match 0x666f6f7f000001 # This just casts the octets to 'string', without # any escaping. # -xlat_expr "foo" + (string)%{radius.packet.vector:} -match foo\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 +xlat_expr "foo" + (string)%{bin:0x0001020304} +match foo\000\001\002\003\004 + # string + octets gets promoted to octets -xlat_expr "foo" + 0x00000000000000000000000000000000 -match 0x666f6f00000000000000000000000000000000 +xlat_expr "foo" + %{bin:0x0001020304} +match 0x666f6f0001020304 # no escaping! xlat_expr 'foo%{Packet-Authentication-Vector}'