Add btests for has_valid_octets() and normalize_mac()

These functions reside in base/utils/addrs.zeek and were not tested. We don't
use has_valid_octets() anywhere right now, normalize_mac() is used in the RADIUS
analyzer, and addr_to_uri() is used in the signatures/dpd.zeek tests.
This commit is contained in:
Christian Kreibich 2025-03-18 17:45:24 -07:00
parent cb5e3d0054
commit 7ba9609992
2 changed files with 26 additions and 0 deletions

View file

@ -61,3 +61,15 @@ F
[1.1.1.1]
[1.1.1.1]
[6:1:2::3:4:5:6]
============ test has_valid_octets()
T
T
T
F
F
============ test normalize_mac()
aa:bb:cc:dd:ee:ff
aa:bb:cc:dd:ee:ff
aa:bb:cc:dd:ee:ff
00:11:aa:bb:cc:dd:ee:ff

View file

@ -149,4 +149,18 @@ event zeek_init()
# by a person trying to parse such a string, but that's just what's going
# to happen; it's on them to deal).
print extract_ip_addresses("IPv6:1:2::3:4:5:6:7");
print "============ test has_valid_octets()";
print has_valid_octets(vector("1", "1", "1", "1"));
print has_valid_octets(vector("0", "0", "0", "0"));
print has_valid_octets(vector("255", "255", "255", "255"));
print has_valid_octets(vector("256", "255", "255", "255")); # F
print has_valid_octets(vector("65535", "255", "255", "255")); # F
print "============ test normalize_mac()";
print normalize_mac("aabbccddeeff");
print normalize_mac("this is aa:bb:cc:dd:ee:ff");
print normalize_mac("this is aa bb cc dd ee ff");
print normalize_mac("this is 00:11:aa:bb:cc:dd:ee:ff");
print normalize_mac("this is nothing mac-related");
}