]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add test which currently returns an error
authorAlan T. DeKok <aland@freeradius.org>
Thu, 15 May 2025 19:38:21 +0000 (15:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 16 May 2025 12:31:09 +0000 (08:31 -0400)
so we have some notes for conditions in tmpl_dcursors

src/lib/server/tmpl_tokenize.c
src/tests/keywords/array-filter [new file with mode: 0644]

index cf2756245224e92ab1434a66d716aee80d407bd8..4a29349bffd62d75ff5495c9da8ff5987e45831d 100644 (file)
@@ -1410,23 +1410,28 @@ static fr_slen_t tmpl_attr_parse_filter(tmpl_attr_error_t *err, tmpl_attr_t *ar,
                fr_sbuff_parse_rules_t p_rules;
                fr_sbuff_term_t const filter_terminals = FR_SBUFF_TERMS(L("]"));
 
+
+               tmp = FR_SBUFF(&our_name);
+               t_rules = (tmpl_rules_t) {};
+               t_rules.attr = *at_rules;
+
                /*
                 *      Unspecified child, we can create a filter starting from the children.
                 *
                 *      @todo - When parsing the condition, we need to ensure that the condition contains a
                 *      reference to the current cursor, and we need to decide what that syntax is.
                 */
-               if ((ar->type != TMPL_ATTR_TYPE_UNSPEC) &&
-                   (!ar->ar_da || !fr_type_is_structural(ar->ar_da->type))) {
-                       fr_strerror_printf("Invalid filter - cannot use filter on leaf attributes");
-                       ar->ar_num = 0;
-                       goto error;
-               }
+               if (ar->type == TMPL_ATTR_TYPE_UNSPEC) {
+                       t_rules.attr.namespace = fr_dict_root(at_rules->dict_def);
 
-               tmp = FR_SBUFF(&our_name);
-               t_rules = (tmpl_rules_t) {};
-               t_rules.attr = *at_rules;
-               t_rules.attr.namespace = ar->ar_da; /* @todo - parent? */
+               } else {
+                       if (!ar->ar_da || !fr_type_is_structural(ar->ar_da->type)) {
+                               fr_strerror_printf("Invalid filter - cannot use filter on leaf attributes");
+                               ar->ar_num = 0;
+                               goto error;
+                       }
+                       t_rules.attr.namespace = ar->ar_da;
+               }
 
                p_rules = (fr_sbuff_parse_rules_t) {
                        .terminals = &filter_terminals,
diff --git a/src/tests/keywords/array-filter b/src/tests/keywords/array-filter
new file mode 100644 (file)
index 0000000..82c58c7
--- /dev/null
@@ -0,0 +1,26 @@
+#
+#  PRE: if
+#
+#  Tests for dereferencing the Nth attribute
+#
+request += {
+       Class = 0x01020304,
+       Class = 0x05060708,
+       Class = 0x090a0b0c,
+}
+
+reply.NAS-Port = 0
+
+if (0) {
+
+foreach octets foo (request.[(Class != 0x05060708)]) {
+       %pairs.debug(foo)
+
+       reply.Filter-Id += "class is " + %hex(foo)
+       reply.NAS-Port += 1
+}
+} else {
+
+       # this don't work.
+       reply.Proxy-State := request.[(. == 0x01020304)]        # ERROR
+}