Skip to content

Commit

Permalink
make unit_test_attribute use fr_pair_list_afrom_substr()
Browse files Browse the repository at this point in the history
and update the tests now that they produce the correct result
  • Loading branch information
alandekok committed Oct 28, 2023
1 parent 3514b55 commit 9bf966d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
41 changes: 36 additions & 5 deletions src/bin/unit_test_attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);

Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion src/tests/unit/protocols/radius/eapol_msg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
30 changes: 10 additions & 20 deletions src/tests/unit/protocols/radius/tag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 9bf966d

Please sign in to comment.