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...") )
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..."))
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..."))
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))