示例#1
0
 def test_fails_for_truncated_udp_header(self):
     packet = make_udp_packet(truncated_header=True)
     udp = UDP(packet)
     self.assertThat(udp.is_valid(), Equals(False))
     self.assertThat(
         udp.invalid_reason, DocTestMatches("Truncated UDP header...")
     )
示例#2
0
 def test_fails_for_truncated_payload(self):
     payload = factory.make_bytes(48)
     packet = make_udp_packet(truncated_payload=True, payload=payload)
     udp = UDP(packet)
     self.assertThat(udp.is_valid(), Equals(False))
     self.assertThat(udp.invalid_reason,
                     DocTestMatches("UDP packet truncated..."))
示例#3
0
 def test__fails_for_bad_length(self):
     payload = factory.make_bytes(48)
     packet = make_udp_packet(total_length=0, payload=payload)
     udp = UDP(packet)
     self.assertThat(udp.is_valid(), Equals(False))
     self.assertThat(
         udp.invalid_reason, DocTestMatches(
             "Invalid UDP packet; got length..."))
示例#4
0
 def test_parses_udp_packet(self):
     payload = factory.make_bytes(48)
     packet = make_udp_packet(payload=payload)
     udp = UDP(packet)
     self.assertThat(udp.is_valid(), Equals(True))
     self.assertThat(udp.payload, Equals(payload))