]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
mdd migration flag for nested pairs, and test it
authorAlan T. DeKok <aland@freeradius.org>
Fri, 14 Jul 2023 13:01:51 +0000 (09:01 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 14 Jul 2023 13:30:58 +0000 (09:30 -0400)
src/bin/unit_test_attribute.c
src/tests/unit/file_nested.txt [new file with mode: 0644]

index 45f2ddb71f28e960296e624ab244cb5a600c90ff..5f3906f855d2c6179622453ec2f0130b6d844daa 100644 (file)
@@ -2453,6 +2453,49 @@ static size_t command_max_buffer_size(command_result_t *result, command_file_ctx
        RETURN_OK(snprintf(data, COMMAND_OUTPUT_MAX, "%ld", size));
 }
 
+/** Set or clear migration flags.
+ *
+ */
+static size_t command_migrate(command_result_t *result, UNUSED command_file_ctx_t *cc,
+                             UNUSED char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen)
+{
+       char *p;
+       bool *out;
+
+       fr_skip_whitespace(in);
+       p = in;
+
+       if (strncmp(p, "pair_legacy_nested", sizeof("pair_legacy_nested") - 1) == 0) {
+               p += sizeof("pair_legacy_nested") - 1;
+               out = &fr_pair_legacy_nested;
+
+       } else {
+               fr_strerror_const("Unknown migration flag");
+               RETURN_PARSE_ERROR(0);
+       }
+
+       fr_skip_whitespace(p);
+       if (*p != '=') {
+               fr_strerror_const("Missing '=' after flag");
+               RETURN_PARSE_ERROR(0);
+       }
+       p++;
+
+       fr_skip_whitespace(p);
+       if ((strcmp(p, "yes") == 0) || (strcmp(p, "true") == 0) || (strcmp(p, "1") == 0)) {
+               *out = true;
+
+       } else if ((strcmp(p, "no") == 0) || (strcmp(p, "false") == 0) || (strcmp(p, "0") == 0)) {
+               *out = false;
+
+       } else {
+               fr_strerror_const("Invalid value for flag");
+               RETURN_PARSE_ERROR(0);
+       }
+
+       RETURN_OK(0);
+}
+
 /** Skip the test file if we're missing a particular feature
  *
  */
@@ -3165,6 +3208,11 @@ static fr_table_ptr_sorted_t     commands[] = {
                                        .usage = "max-buffer-size[ <intger>]",
                                        .description = "Limit the maximum temporary buffer space available for any command which uses it"
                                }},
+       { L("migrate "),        &(command_entry_t){
+                                       .func = command_migrate,
+                                       .usage = "migrate <flag>=<value>",
+                                       .description = "Set migration flag"
+                               }},
        { L("need-feature "),   &(command_entry_t){
                                        .func = command_need_feature,
                                        .usage = "need-feature <feature>",
diff --git a/src/tests/unit/file_nested.txt b/src/tests/unit/file_nested.txt
new file mode 100644 (file)
index 0000000..ee8b92c
--- /dev/null
@@ -0,0 +1,38 @@
+#
+#  Tests for parsing files ala radclient or "users"
+#
+#  This is the same as "file.txt", but with the migration flag set.
+#
+#  $Id$
+#
+
+proto-dictionary radius
+migrate pair_legacy_nested = yes
+
+#
+#  Fully specified paths.
+#
+read_file files/cisco_avpair.txt
+match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } }
+
+#
+#  Relative attributes, all on the same line.
+#
+read_file files/cisco_relative.txt
+match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } }
+
+#
+#  Relative attributes, each on a different line
+#
+read_file files/cisco_multiline_relative.txt
+match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } }
+
+
+#
+#  Multiple Cisco AVPAir, all on one line
+#
+read_file files/cisco_single_line.txt
+match User-Name = "bob", User-Password = "hello", Vendor-Specific = { Cisco = { AVPair = "1", AVPair += "2", AVPair += "3", AVPair += "4" } }
+
+count
+match 10