Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_success(self):
"""Verifies the if the Response can indicate a success to a request correctly"""
self.assertTrue(self.craft_response_of_type(icmp.Types.EchoReply).success,
'Unable to validate a successful response')
self.assertFalse(self.craft_response_of_type(icmp.Types.DestinationUnreachable).success,
'Unable to validate Destination Unreachable')
self.assertFalse(self.craft_response_of_type(icmp.Types.BadIPHeader).success,
'Unable to validate Bad IP Header')
self.assertFalse(executor.Response(None, 0.1).success, 'Unable to validate timeout (no payload)')
def test_checksum_creation(self):
"""Verifies it generates the correct checksum, given packet data"""
packet = icmp.ICMP(icmp.Types.EchoRequest, payload='random text goes here', identifier=16)
self.assertEqual(packet.expected_checksum, 485, 'Checksum creation failed')
packet = icmp.ICMP(icmp.Types.EchoReply, payload='foobar', identifier=11)
self.assertEqual(packet.expected_checksum, 48060, 'Checksum creation failed')
def test_pack(self):
"""Verifies that creates the correct pack"""
self.assertEqual(
icmp.ICMP(icmp.Types.EchoReply, payload='banana', identifier=19700).packet,
b'\x00\x00\xcb\x8e\xf4L\x01\x00banana',
"Fail to pack ICMP structure to packet"
)
self.assertEqual(
icmp.ICMP(icmp.Types.EchoReply, payload='random text goes here', identifier=12436).packet,
b'\x00\x00h\xd1\x940\x01\x00random text goes here',
"Fail to pack ICMP structure to packet"
)
self.assertEqual(
icmp.ICMP(icmp.Types.EchoRequest, payload='random text goes here', identifier=18676).packet,
b'\x08\x00\x00\xb9\xf4H\x01\x00random text goes here',
"Fail to unpack ICMP structure to packet"
)
def test_success(self):
"""Verifies the if the Response can indicate a success to a request correctly"""
self.assertTrue(self.craft_response_of_type(icmp.Types.EchoReply).success,
'Unable to validate a successful response')
self.assertFalse(self.craft_response_of_type(icmp.Types.DestinationUnreachable).success,
'Unable to validate Destination Unreachable')
self.assertFalse(self.craft_response_of_type(icmp.Types.BadIPHeader).success,
'Unable to validate Bad IP Header')
self.assertFalse(executor.Response(None, 0.1).success, 'Unable to validate timeout (no payload)')