]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make unit_test_attribute use fr_pair_list_afrom_substr()
authorAlan T. DeKok <aland@freeradius.org>
Sat, 28 Oct 2023 19:16:17 +0000 (15:16 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 28 Oct 2023 19:16:17 +0000 (15:16 -0400)
and update the tests now that they produce the correct result

src/bin/unit_test_attribute.c
src/tests/unit/protocols/radius/eapol_msg.txt
src/tests/unit/protocols/radius/tag.txt

index e48125ff3a50d7223eda98defb436cd1f8fc1bbe..9608643650dd7d4baaf62dec22c7e0bd9fa7321a 100644 (file)
@@ -1850,8 +1850,10 @@ static size_t command_encode_pair(command_result_t *result, command_file_ctx_t *
 
        size_t          iterations = 0;
        fr_dict_t const *dict;
+       fr_pair_parse_t root, relative;
 
        fr_pair_list_init(&head);
+
        slen = load_test_point_by_command((void **)&tp, p, "tp_encode_pair");
        if (!tp) {
                fr_strerror_const_push("Failed locating encode testpoint");
@@ -1885,12 +1887,22 @@ static size_t command_encode_pair(command_result_t *result, command_file_ctx_t *
        }
 
        dict = cc->tmpl_rules.attr.dict_def ? cc->tmpl_rules.attr.dict_def : cc->config->dict;
-       if (fr_pair_list_afrom_str(cc->tmp_ctx, fr_dict_root(dict),
-                                  p, in + inlen - p, &head) != T_EOL) {
+
+       root = (fr_pair_parse_t) {
+               .ctx = cc->tmp_ctx,
+               .da = fr_dict_root(dict),
+               .list = &head,
+       };
+       relative = (fr_pair_parse_t) { };
+
+       slen = fr_pair_list_afrom_substr(&root, &relative, &FR_SBUFF_IN(p, inlen - (p - in)));
+       if (slen <= 0) {
                CLEAR_TEST_POINT(cc);
                RETURN_OK_WITH_ERROR();
        }
 
+        PAIR_LIST_VERIFY(&head);
+
        /*
         *      Outer loop implements truncate test
         */
@@ -2074,6 +2086,7 @@ static size_t command_encode_proto(command_result_t *result, command_file_ctx_t
 
        fr_pair_list_t  head;
        fr_dict_t const *dict;
+       fr_pair_parse_t root, relative;
 
        fr_pair_list_init(&head);
 
@@ -2093,8 +2106,16 @@ static size_t command_encode_proto(command_result_t *result, command_file_ctx_t
        }
 
        dict = cc->tmpl_rules.attr.dict_def ? cc->tmpl_rules.attr.dict_def : cc->config->dict;
-       if (fr_pair_list_afrom_str(cc->tmp_ctx, fr_dict_root(dict),
-                                  p, in + inlen - p, &head) != T_EOL) {
+
+       root = (fr_pair_parse_t) {
+               .ctx = cc->tmp_ctx,
+               .da = fr_dict_root(dict),
+               .list = &head,
+       };
+       relative = (fr_pair_parse_t) { };
+
+       slen = fr_pair_list_afrom_substr(&root, &relative, &FR_SBUFF_IN(p, inlen - (p - in)));
+       if (slen <= 0) {
                CLEAR_TEST_POINT(cc);
                RETURN_OK_WITH_ERROR();
        }
@@ -2428,10 +2449,20 @@ static size_t command_pair(command_result_t *result, command_file_ctx_t *cc,
        fr_pair_list_t  head;
        ssize_t         slen;
        fr_dict_t const *dict = cc->tmpl_rules.attr.dict_def ? cc->tmpl_rules.attr.dict_def : cc->config->dict;
+       fr_pair_parse_t root, relative;
 
        fr_pair_list_init(&head);
 
-       if (fr_pair_list_afrom_str(NULL, fr_dict_root(dict), in, inlen, &head) != T_EOL) {
+       root = (fr_pair_parse_t) {
+               .ctx = cc->tmp_ctx,
+               .da = fr_dict_root(dict),
+               .list = &head,
+       };
+       relative = (fr_pair_parse_t) { };
+
+       slen = fr_pair_list_afrom_substr(&root, &relative, &FR_SBUFF_IN(in, inlen));
+       if (slen <= 0) {
+//             fr_strerror_printf_push_head("ERROR offset %d", (int) -slen);
                fr_pair_list_free(&head);
                RETURN_OK_WITH_ERROR();
        }
index a0a0def8c40d551e8aedd08a5cb09836ad269159..83f65fb31a4066090e88de2bd52d219658a6d325 100644 (file)
@@ -9,6 +9,9 @@ fuzzer-out radius
 decode-proto 020200eb8b7a26bee11f1ca308233d49733187720506000030391217506f776572656420627920467265655241444955531a0c000004d23806deadbeef1a0c000000141e06cafecafe1a0c000000141e06cadecade1a1200000be1130c6d792070726f66696c651a0c00000be11006000000051a0c000001370706000000011a2a0000013711248701b3e481d72fa1333b9838a3cd448837eaed62a843295f1c9dd153c6866e499f201a2a0000013710249385f7dc0fd758b02dd0dc43f68266508ec93c678a5fa38525749016edede8eeea0e4f0603fc0004501200e9e565eb053138254850edb41fc013
 match Packet-Type = Access-Accept, Packet-Authentication-Vector = 0x8b7a26bee11f1ca308233d4973318772, NAS-Port = 12345, Reply-Message = "Powered by FreeRADIUS", Vendor-Specific = { raw.1234 = { raw.56 = 0xdeadbeef }, raw.20 = { raw.30 = 0xcafecafe }, raw.20 = { raw.30 = 0xcadecade }, Alcatel = { FR-Direct-Profile = "my profile", Home-Agent-UDP-Port = 5 }, Microsoft = { MPPE-Encryption-Policy = Encryption-Allowed, raw.MPPE-Recv-Key = 0x8701b3e481d72fa1333b9838a3cd448837eaed62a843295f1c9dd153c6866e499f20, raw.MPPE-Send-Key = 0x9385f7dc0fd758b02dd0dc43f68266508ec93c678a5fa38525749016edede8eeea0e } }, EAP-Message = 0x03fc0004, Message-Authenticator = 0x00e9e565eb053138254850edb41fc013
 
+pair Vendor-Specific = { raw.1234 = { raw.56 = 0xdeadbeef } }
+match Vendor-Specific = { raw.1234 = { raw.56 = 0xdeadbeef } }
+
 encode-pair Vendor-Specific = { raw.1234 = { raw.56 = 0xdeadbeef } }
 match 1a 0c 00 00 04 d2 38 06 de ad be ef
 
@@ -29,4 +32,4 @@ decode-pair -
 match  NAS-Port = 12345, Reply-Message = "Powered by FreeRADIUS", Vendor-Specific = { raw.1234 = { raw.56 = 0xdeadbeef }, raw.20 = { raw.30 = 0xcafecafe }, raw.20 = { raw.30 = 0xcadecade }, Alcatel = { FR-Direct-Profile = "my profile", Home-Agent-UDP-Port = 5 } }
 
 count
-match 15
+match 17
index 31cd8cf8ab7ce10bc5ae510f5311d83e55f8ec6c..22db3c448c679670cb65afbb391868235d7371cc 100644 (file)
@@ -12,7 +12,7 @@ decode-pair -
 match Tag-1 = { Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
 
 pair Tag-2 = { &Vendor-Specific.Unisphere.Service-Activate = "PPPOE_SERVICE(3072000,2048000)" }
-match Tag-2 = { Vendor-Specific.Unisphere.Service-Activate = "PPPOE_SERVICE(3072000,2048000)" }
+match Tag-2 = { Vendor-Specific = { Unisphere = { Service-Activate = "PPPOE_SERVICE(3072000,2048000)" } } }
 
 encode-pair Tag-2 = { Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED" }
 match 1a 12 00 00 13 0a 41 0c 02 55 4e 50 4f 4c 49 43 45 44
@@ -27,27 +27,17 @@ decode-pair -
 match Tag-1 = { Tunnel-Private-Group-Id = "foo", Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
 
 
-#
-#  This returns "Service-Activate", but ignores Tag-1
-#
-#  fr_pair_list_afrom_str() calls fr_dict_attr_by_oid_substr() which just
-#  ends up finding the leaf.  So if there are intermediate groups, they are
-#  skipped.w
-#
-#pair Tag-1.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
-#match Tag-1 = { Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
+pair Tag-1.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
+match Tag-1 = { Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
 
-#encode-pair Tag-1.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
-#match 1a 12 00 00 13 0a 41 0c 01 55 4e 50 4f 4c 49 43 45 44
+encode-pair Tag-1.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
+match 1a 12 00 00 13 0a 41 0c 01 55 4e 50 4f 4c 49 43 45 44
 
-#decode-pair -
-#match Tag1 = { Vendor-Specific = { Unsiphere = { Service-Activate = "UNPLOICED" } } }
+decode-pair -
+match Tag-1 = { Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
 
-#
-#  This doesn't work for the same reason as Tag-1 above.
-#
-#pair Tmp-Group-0.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
-#match Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } }
+pair Tmp-Group-0.Vendor-Specific.Unisphere.Service-Activate = "UNPOLICED"
+match Tmp-Group-0 = { Vendor-Specific = { Unisphere = { Service-Activate = "UNPOLICED" } } }
 
 count
-match 17
+match 25