Home | History | Annotate | Download | only in test
      1 # DNS OPT Resource Record unit tests
      2 #
      3 # Type the following command to launch start the tests:
      4 # $ sudo bash test/run_tests -t test/edns0.uts -F
      5 
      6 + Test EDNS0 rdata
      7 
      8 = EDNS0TLV(), basic instanciation
      9 tlv = EDNS0TLV()
     10 raw(tlv) == b'\x00\x00\x00\x00'
     11 
     12 = EDNS0TLV(), check parameters
     13 tlv = EDNS0TLV(optcode=42, optlen=12, optdata="edns0tlv")
     14 raw(tlv) == b'\x00*\x00\x0cedns0tlv'
     15 
     16 = EDNS0TLV(), check computed optlen
     17 tlv = EDNS0TLV(optdata="edns0tlv")
     18 raw(tlv) == b'\x00\x00\x00\x08edns0tlv'
     19 
     20 = EDNS0TLV(), dissection
     21 tlv = EDNS0TLV(b'\x00*\x00\x08edns0tlv')
     22 tlv.optcode == 42 and tlv.optlen == 8 and tlv.optdata == b"edns0tlv"
     23 
     24 + Test OPT RR
     25 
     26 = DNSRROPT(), basic instanciation
     27 opt = DNSRROPT()
     28 raw(opt) == b'\x00\x00)\x10\x00\x00\x00\x80\x00\x00\x00'
     29 
     30 = DNSRROPT(), check parameters
     31 opt = DNSRROPT(rrname="rropt", type=42, rclass=123, extrcode=1, version=2, z=3, rdlen=4, rdata=[EDNS0TLV()])
     32 raw(opt) == b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x04\x00\x00\x00\x00'
     33 
     34 = DNSRROPT() & EDN0TLV(), check parameters
     35 opt = DNSRROPT(rrname="rropt", type=42, rclass=123, extrcode=1, version=2, z=3, rdlen=4, rdata=[EDNS0TLV(optcode=42, optlen=12, optdata="edns0tlv")])
     36 raw(opt) == b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x04\x00*\x00\x0cedns0tlv'
     37 
     38 = DNSRROP(), dissection
     39 opt = DNSRROPT(b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x0c\x00*\x00\x0cedns0tlv')
     40 opt.rrname == b"rropt." and opt.rdlen == 12 and opt.rdata[0].optcode == 42 and opt.rdata[0].optdata == b"edns0tlv"
     41 
     42 + Test EDNS-PING
     43 
     44 = EDNS-PING - basic instanciation
     45 tlv = EDNS0TLV(optcode=5, optdata=b"\x00\x11\x22\x33")
     46 raw(tlv) == b'\x00\x05\x00\x04\x00\x11"3'
     47 
     48 #= EDNS-PING - Live test
     49 #~ netaccess
     50 #* NB: 85.17.219.217 and www.edns-ping.org seem down
     51 #old_debug_dissector = conf.debug_dissector
     52 #conf.debug_dissector = False
     53 #r = sr1(IP(dst="85.17.219.217")/UDP()/DNS(qd=[DNSQR(qtype="A", qname="www.edns-ping.org.")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="PING", optdata=b"\x00\x11\x22\x33")])]), timeout=1)
     54 #conf.debug_dissector = old_debug_dissector
     55 #len(r.ar) and r.ar.rdata[0].optcode == 4  # XXX: should be 5
     56 
     57 + Test DNS Name Server Identifier (NSID) Option
     58 
     59 = NSID- basic instanciation
     60 tlv = EDNS0TLV(optcode=2, optdata="")
     61 raw(tlv) == b'\x00\x02\x00\x00'
     62 
     63 = NSID - Live test
     64 ~ netaccess
     65 old_debug_dissector = conf.debug_dissector
     66 conf.debug_dissector = False
     67 r = sr1(IP(dst="l.root-servers.net")/UDP()/DNS(qd=[DNSQR(qtype="SOA", qname=".")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="NSID")])]), timeout=1)
     68 conf.debug_dissector = old_debug_dissector
     69 len(r.ar) and DNSRROPT in r.ar and len(r.ar[DNSRROPT].rdata) and len([x for x in r.ar[DNSRROPT].rdata if x.optcode == 3])
     70