def test(self, super_pack): inst = SCIONExtPacket() inst._l4_proto = 0x42 super_pack.return_value = b"super" inst.ext_hdrs = [] for idx, class_, len_, type_ in ((0, 0x1, 0x0, 0x0), (1, 0x2, 0x1, 0x11), (2, 0x3, 0x2, 0x1)): hdr = create_mock(["hdr_len", "EXT_CLASS", "EXT_TYPE", "pack"]) hdr.EXT_CLASS = class_ hdr.hdr_len.return_value = len_ hdr.EXT_TYPE = type_ hdr.pack.return_value = bytes( range(5 + len_ * ExtensionHeader.LINE_LEN)) inst.ext_hdrs.append(hdr) expected = b"".join([ b"super", bytes([0x2, 0x0, 0x0]), bytes(range(5)), bytes([0x3, 0x1, 0x11]), bytes(range(13)), bytes([0x42, 0x2, 0x1]), bytes(range(21)), ]) # Call ntools.eq_(inst._inner_pack(), expected)
def test(self, super_values): inst = SCIONExtPacket() ext_hdrs = [] for _ in range(3): ext_hdrs.append(MagicMock(spec_set=ExtensionHeader)) # Call inst._inner_from_values("cmn hdr", "addr hdr", "path hdr", ext_hdrs) # Tests super_values.assert_called_once_with(inst, "cmn hdr", "addr hdr", "path hdr") ntools.eq_(inst.ext_hdrs, ext_hdrs)
def test_basic(self, inner_values, set_pld): inst = SCIONExtPacket.from_values("cmn hdr", "addr hdr", "path hdr", "ext hdrs") # Tests ntools.assert_is_instance(inst, SCIONExtPacket) inner_values.assert_called_once_with(inst, "cmn hdr", "addr hdr", "path hdr", "ext hdrs") set_pld.assert_called_once_with(inst, b"")
def test_unknown_e2e(self, super_val): inst = SCIONExtPacket() inst._unknown_exts = {ExtensionClass.END_TO_END: [1]} # Call ntools.assert_raises(SCMPBadEnd2End, inst.validate, "pkt len")
def test_unknown_hbh(self, super_val): inst = SCIONExtPacket() inst._unknown_exts = {ExtensionClass.HOP_BY_HOP: [1]} # Call ntools.assert_raises(SCMPBadHopByHop, inst.validate, "pkt len")
def test_no_unknown(self, super_val): inst = SCIONExtPacket() # Call ntools.ok_(inst.validate("pkt len")) # Tests super_val.assert_called_once_with(inst, "pkt len")
def test_with_exts(self): inst = SCIONExtPacket() inst.ext_hdrs = [create_mock(["EXT_CLASS"]), 0] # Call ntools.eq_(inst._get_next_hdr(), inst.ext_hdrs[0].EXT_CLASS)
def test_no_exts(self): inst = SCIONExtPacket() inst.ext_hdrs = [] inst._l4_proto = 42 # Call ntools.eq_(inst._get_next_hdr(), 42)
def test(self, super_offset): inst = SCIONExtPacket() inst.ext_hdrs = ["a", "bb", "cccc"] super_offset.return_value = 42 # Call ntools.eq_(inst._get_offset_len(), 49)
def test_payload(self, inner_values, set_pld): inst = SCIONExtPacket.from_values("cmn hdr", "addr hdr", "path hdr", "ext hdrs", "payload") # Tests set_pld.assert_called_once_with(inst, "payload")