From: Alan T. DeKok Date: Tue, 3 Sep 2024 15:49:35 +0000 (-0400) Subject: add test looping over children of a TLV X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c105db87995ecee180771bc55f4d43a37efed9bd;p=thirdparty%2Ffreeradius-server.git add test looping over children of a TLV --- diff --git a/src/lib/unlang/foreach.c b/src/lib/unlang/foreach.c index 8f42d6e603..50894e8ed0 100644 --- a/src/lib/unlang/foreach.c +++ b/src/lib/unlang/foreach.c @@ -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 index 0000000000..44f8b27a04 --- /dev/null +++ b/src/tests/keywords/foreach-tlv-children @@ -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 diff --git a/src/tests/keywords/radius.conf b/src/tests/keywords/radius.conf index 0b21970280..3fc1e844b0 100644 --- a/src/tests/keywords/radius.conf +++ b/src/tests/keywords/radius.conf @@ -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"