Esempio n. 1
0
 def test(self, in_cksum):
     inst = SCIONUDPHeader()
     inst._dst = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"dsIA"}),
             "host": create_mock_full({"pack()": b"dstH"}),
         },
         class_=SCIONAddr)
     inst._src = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"srIA"}),
             "host": create_mock_full({"pack()": b"srcH"}),
         },
         class_=SCIONAddr)
     inst.pack = create_mock_full(return_value=b"packed with null checksum")
     payload = b"payload"
     expected_call = b"".join([
         b"dsIA",
         b"srIA",
         b"dstH",
         b"srcH",
         b"\x00",
         bytes([L4Proto.UDP]),
         b"packed with null checksum",
         payload,
     ])
     in_cksum.return_value = 0x3412
     # Call
     ntools.eq_(inst._calc_checksum(payload), bytes.fromhex("3412"))
     # Tests
     in_cksum.assert_called_once_with(expected_call)
Esempio n. 2
0
 def test(self):
     inst = SCIONUDPHeader()
     inst._src = "src addr"
     inst._dst = "dst addr"
     inst.src_port = "src port"
     inst.dst_port = "dst port"
     # Call
     inst.reverse()
     # Tests
     ntools.eq_(inst._src, "dst addr")
     ntools.eq_(inst._dst, "src addr")
     ntools.eq_(inst.src_port, "dst port")
     ntools.eq_(inst.dst_port, "src port")
Esempio n. 3
0
 def test(self, scapy_checksum):
     inst = SCIONUDPHeader()
     inst._src = create_mock(["pack"], class_=SCIONAddr)
     inst._src.pack.return_value = b"source address"
     inst._dst = create_mock(["pack"], class_=SCIONAddr)
     inst._dst.pack.return_value = b"destination address"
     inst.pack = create_mock()
     inst.pack.return_value = b"packed with null checksum"
     payload = b"payload"
     expected_call = b"".join([
         b"source address", b"destination address", bytes([L4Proto.UDP]),
         b"packed with null checksum", payload,
     ])
     scapy_checksum.return_value = 0x3412
     # Call
     ntools.eq_(inst._calc_checksum(payload), bytes.fromhex("1234"))
     # Tests
     scapy_checksum.assert_called_once_with(expected_call)