def test_incomplete_packet(self): """ Reject an incomplete packet """ packet = ( b'\x16' # type b'\x03' # minor version b'\x00\x0A' # big-endian length b'0123456789' # fragment ) with pytest.raises(FieldError) as exc_info: TLSCompressed.from_bytes(packet) assert str(exc_info.value) == "expected 2608, found 9"
def test_not_enough_data_to_fragment(self): """ Detect insufficient data to fragment. """ packet = ( b'\x16' # type b'\x03' # major version b'\x03' # minor version b'\x00\x0A' # big-endian length b'12' # fragment ) with pytest.raises(FieldError) as exc_info: TLSCompressed.from_bytes(packet) assert str(exc_info.value) == "expected 10, found 2"
def test_parse_tls_compressed_wrong_type(self): """ Raise an error when the type is not one of those defined in :class:`enums.ContentType`. """ packet = ( b'\x1a' # invalid type b'\x03' b'\x03' b'\x00\x0A' b'0123456789') with pytest.raises(ValueError) as exc_info: TLSCompressed.from_bytes(packet) assert str(exc_info.value) == "26 is not a valid ContentType"
def test_parse_tls_compressed_wrong_type(self): """ Raise an error when the type is not one of those defined in ContentType """ packet = ( b'\x1a' # invalid type b'\x03' b'\x03' b'\x00\x0A' b'0123456789' ) with pytest.raises(ValueError) as exc_info: TLSCompressed.from_bytes(packet) assert str(exc_info.value) == "26 is not a valid ContentType"
def test_fragment_too_long(self): """ :py:func:`tls.record.TLSCompressed` rejects a packet containing a longer-than-allowed fragment. """ packet = ( b'\x16' # type b'\x03' # major version b'\x03' # minor version b'\xff\xff' + # big-endian length (b'a' * 0xFFFF) # fragment ) with pytest.raises(ValidationError) as exc_info: TLSCompressed.from_bytes(packet) assert exc_info.value.args == ('invalid object', 0xFFFF)
def test_parse_tls_compressed_handshake(self): """ :class:`TLSCompressed`, which has attributes representing all the fields in the TLSCompressed struct. """ packet = ( b'\x16' # type b'\x03' # major version b'\x03' # minor version b'\x00\x0A' # big-endian length b'0123456789' # fragment ) record = TLSCompressed.from_bytes(packet) assert record.type == enums.ContentType.HANDSHAKE assert record.version.major == 3 assert record.version.minor == 3 assert record.fragment == b'0123456789'