From 6e9b02642b4a5d31f1db071769ac5b5f107b6aa3 Mon Sep 17 00:00:00 2001 From: Guillaume Valadon <guillaume@valadon.net> Date: Wed, 28 Dec 2016 18:08:20 +0100 Subject: [PATCH] More regression tests --- test/regression.uts | 242 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 240 insertions(+), 2 deletions(-) diff --git a/test/regression.uts b/test/regression.uts index a2cd5a5b..16baaeb9 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -89,6 +89,47 @@ save_session(fname="scapySession1") = Test load_session load_session(fname="scapySession1") += Test utility functions + +tmpfile = get_temp_file(autoext=".ut") +tmpfile.startswith("/tmp/scapy") +conf.temp_files[0].endswith(".ut") +conf.temp_files.pop() + +get_temp_file(True).startswith("/tmp/scapy") and len(conf.temp_files) == 0 + +sane("A\x00\xFFB") == "A..B" + +linehexdump(Ether(), dump=True) == "FFFFFFFFFFFF0242D077E8129000 .......B.w...." + +chexdump(Ether(), dump=True) == "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x42, 0xd0, 0x77, 0xe8, 0x12, 0x90, 0x00" + +hexstr("A\x00\xFFB") == "41 00 ff 42 A..B" + +fletcher16_checksum("\x28\x07") == 22319 + +tex_escape("$#_") == "\\$\\#\\_" + +f = colgen(range(3)) +len([f.next() for i in range(2)]) == 2 + +f = incremental_label() +[f.next() for i in range(2)] == ["tag00000", "tag00001"] + +import random +random.seed(0x2807) +corrupt_bytes("ABCDE") == "ABCDW" +sane(corrupt_bytes("ABCDE", n=3)) == "A.8D4" + +corrupt_bits("ABCDE") == "EBCDE" +sane(corrupt_bits("ABCDE", n=3)) == "AF.EE" + += Test utility functions - network related +~ netaccess + +atol("www.secdev.org") == 3642339845 + + ############ ############ + Basic tests @@ -2844,14 +2885,24 @@ if not len(conf.route6.routes): conf.route6.routes.append(("::1", 128, "::", LOOPBACK_NAME, ["::1"])) True += Route6 - Route6.make_route + +r6 = Route6() +r6.make_route("2001:db8::1", dev=LOOPBACK_NAME) == ("2001:db8::1", 128, "::", LOOPBACK_NAME, []) +len_r6 = len(r6.routes) + += Route6 - Route6.add & Route6.delt + +r6.add(dst="2001:db8:cafe:f000::/64", gw="2001:db8:cafe::1", dev="eth0") +print len(r6.routes) == len_r6 + 1 +r6.delt(dst="2001:db8:cafe:f000::/64", gw="2001:db8:cafe::1") +len(r6.routes) == len_r6 -# There are many other to do. # Below is our Homework : here is the mountain ... -########### Net6 Class ############################################## ########### ICMPv6MLQuery Class ##################################### ########### ICMPv6MLReport Class #################################### ########### ICMPv6MLDone Class ###################################### @@ -7219,3 +7270,190 @@ s == 'E\x00\x007\x00\x01\x00\x00@\x11|\xb3\x7f\x00\x00\x01\x7f\x00\x00\x01\x07\x = Radius - dissection p = IP(s) Radius in p and len(p[Radius].attributes) == 1 and p[Radius].attributes[0].value == "scapy" + + +############ +############ ++ Addresses generators + += Net + +n1 = Net("192.168.0.0/31") +[ip for ip in n1] == ["192.168.0.0", "192.168.0.1"] + +n2 = Net("192.168.0.*") +len([ip for ip in n2]) == 256 + +n3 = Net("192.168.0.1-5") +len([ip for ip in n3]) == 5 + +(n1 == n3) == False + +(n3 in n2) == True + += OID + +oid = OID("1.2.3.4.5.6-8") +len([ o for o in oid ]) == 3 + += Net6 + +n1 = Net6("2001:db8::/127") +len([ip for ip in n1]) == 2 + + +############ +############ ++ IPv6 helpers + += in6_getLocalUniquePrefix() + +p = in6_getLocalUniquePrefix() +len(p) == 16 and p.startswith("fd") + += Misc addresses manipulation functions + +teredoAddrExtractInfo("2001:0:0a0b:0c0d:0028:f508:f508:08f5") == ("10.11.12.13", 40, "10.247.247.10", 2807) + +in6_iseui64("fe80::bae8:58ff:fed4:e5f6") == True + +in6_isanycast("2001:db8::fdff:ffff:ffff:ff80") == True + +a = inet_pton(socket.AF_INET6, "2001:db8::2807") +in6_xor(a, a) == "\x00" * 16 + +a = inet_pton(socket.AF_INET6, "fe80::bae8:58ff:fed4:e5f6") +r = inet_ntop(socket.AF_INET6, in6_getnsma(a)) +r == "ff02::1:ffd4:e5f6" + +in6_isllsnmaddr(r) == True + +in6_isdocaddr("2001:db8::2807") == True + +in6_isaddrllallnodes("ff02::1") == True + +in6_isaddrllallservers("ff02::2") == True + += in6_getscope() + +in6_getscope("2001:db8::2807") == IPV6_ADDR_GLOBAL +in6_getscope("fec0::2807") == IPV6_ADDR_SITELOCAL +in6_getscope("fe80::2807") == IPV6_ADDR_LINKLOCAL +in6_getscope("ff02::2807") == IPV6_ADDR_LINKLOCAL +in6_getscope("ff0e::2807") == IPV6_ADDR_GLOBAL +in6_getscope("ff05::2807") == IPV6_ADDR_SITELOCAL +in6_getscope("ff01::2807") == IPV6_ADDR_LOOPBACK +in6_getscope("::1") == IPV6_ADDR_LOOPBACK + + +############ +############ ++ Test Route class + += make_route() + +r4 = Route() +len_r4 = len(r4.routes) +r4.make_route(host="10.12.13.14") == (168561934, 4294967295L, '0.0.0.0', LOOPBACK_NAME, '0.0.0.0') +r4.make_route(net="10.12.13.0/24") == (168561920, 4294967040L, '0.0.0.0', LOOPBACK_NAME, '0.0.0.0') +r4.make_route(net="10.12.0.0/16", dev="dummy0") == (168558592, 4294901760L, '0.0.0.0', 'dummy0', '0.0.0.0') + += add() & delt() + +r4.add(net="192.168.1.0/24", gw="1.2.3.4", dev="dummy0") +len(r4.routes) == len_r4 + 1 +r4.delt(net="192.168.1.0/24", gw="1.2.3.4", dev="dummy0") +len(r4.routes) == len_r4 + += ifchange() + +r4.add(net="192.168.1.0/24", gw="1.2.3.4", dev="dummy0") +r4.ifchange("dummy0", "5.6.7.8") +r4.routes[-1][-1] == "5.6.7.8" + += ifdel() + +r4.ifdel("dummy0") +len(r4.routes) == len_r4 + += ifadd() & get_if_bcast() + +r4.ifadd("dummy0", "1.2.3.4/24") +r4.get_if_bcast("dummy0") == "1.2.3.255" + +r4.ifdel("dummy0") +len(r4.routes) == len_r4 + + +############ +############ ++ Random objects + += RandomEnumeration + +re = RandomEnumeration(0, 7, seed=0x2807, forever=False) +[x for x in re] == [3, 4, 2, 5, 1, 6, 0, 7] + += RandIP6 + +random.seed(0x2807) +r6 = RandIP6() +str(r6) == "d279:1205:e445:5a9f:db28:efc9:afd7:f594" + +random.seed(0x2807) +r6 = RandIP6("2001:db8::-") +print r6 == "2001:0db8::9e9c" + +r6 = RandIP6("2001:db8::*") +print r6 == "2001:0db8::9ccb" + += RandMAC + +random.seed(0x2807) +rm = RandMAC() +rm == "12:5a:ef:f5:91:44" + +rm = RandMAC("00:01:02:03:04:0-7") +rm == "00:01:02:03:04:01" + += RandOID + +random.seed(0x2807) +ro = RandOID() +ro == "7.222.44.194.276.116.320.6.84.97.31.5.25.20.13.84.104.18" + +ro = RandOID("1.2.3.*") +ro == "1.2.3.41" + +ro = RandOID("1.2.3.0-28") +ro == "1.2.3.11" + += RandRegExp + +random.seed(0x2807) +re = RandRegExp("[g-v]* @? [0-9]{3} . (g|v)") +print re == "vmuvr @ 906 g" + += Corrupted(Bytes|Bits) + +random.seed(0x2807) +cb = CorruptedBytes("ABCDE", p=0.5) +sane(cb) == "pB..E" + +cb = CorruptedBits("ABCDE", p=0.2) +sane(cb) == "E.Kl`" + += Rand* + +random.seed(0x2807) +rs = RandSingNum(-28, 07) +print rs == -7 + +rss = RandSingString() +rss == "CON:" + +rek = RandEnumKeys({'a': 1, 'b': 2}) +str(rek) == 'b' + +rts = RandTermString(4, "scapy") +sane(str(rts)) == "[...scapy" -- GitLab