]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix unit_test_module to actually check the results
authorAlan T. DeKok <aland@freeradius.org>
Thu, 31 Aug 2023 15:50:27 +0000 (11:50 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 31 Aug 2023 15:50:27 +0000 (11:50 -0400)
and remove the dependency on the radius-only xlats

src/bin/unit_test_module.c
src/tests/xlat/expr.txt

index d28ba5d415c1ca4ea69d568e5e876048f86cc8a8..253d085a8439b7e6a0b6986be22d038bb000d243 100644 (file)
@@ -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;
index 9bfae24eaccb9c8dc649f25205409250a596c6ad..5602e3f7c61ac9f8872352eda426834ad368cc6a 100644 (file)
@@ -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}'