]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add test looping over children of a TLV
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 Sep 2024 15:49:35 +0000 (11:49 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 3 Sep 2024 19:05:25 +0000 (15:05 -0400)
src/lib/unlang/foreach.c
src/tests/keywords/foreach-tlv-children [new file with mode: 0644]
src/tests/keywords/radius.conf

index 8f42d6e603eb7682a5cc5ad8c9c07c14171f9b27..50894e8ed0f15f0279e0685a34a46e72497aaf9e 100644 (file)
@@ -268,8 +268,6 @@ static unlang_action_t unlang_foreach(rlm_rcode_t *p_result, request_t *request,
                }
                fr_assert(state->key != NULL);
 
-               fr_assert(vp->da->type == state->key->da->type);
-
                if (fr_type_is_structural(vp->vp_type)) {
                        if (fr_pair_list_copy(state->key, &state->key->vp_group, &vp->vp_group) < 0) {
                                REDEBUG("Failed copying children of %s", gext->key->name);
diff --git a/src/tests/keywords/foreach-tlv-children b/src/tests/keywords/foreach-tlv-children
new file mode 100644 (file)
index 0000000..44f8b27
--- /dev/null
@@ -0,0 +1,37 @@
+#
+#  PRE: foreach
+#
+#  Loop over children of a TLV.
+#
+#  Note that the only data types compatible with all data types are "string" or "octets"
+#
+string out
+
+&my-tlv := {
+       &a = 1
+       &b = 2
+       &c = "foo"
+       &d = 127.0.0.1
+}
+
+
+&out = ""
+
+#
+#  Home-brew concat!
+#
+foreach string child (&my-tlv.[*]) {
+       &out += &child
+       &out += " "
+}
+
+#
+#  Sad trailing space, but we can delete it!
+#
+&out -= ' '
+
+if (&out != '1 2 foo 127.0.0.1') {
+       test_fail
+}
+
+success
index 0b219702800feef3a1cecabec58f68fb03b805d1..3fc1e844b0620963cae1741d5a2938bdc33882fb 100644 (file)
@@ -135,6 +135,15 @@ server default {
                type = Access-Request
        }
 
+       dictionary {
+               tlv my-tlv {
+                       uint32 a
+                       uint32 b
+                       string c
+                       ipaddr d
+               }
+       }
+
        recv Access-Request {
                &control.Password.Cleartext := "hello"