<s> from __future__ import absolute_import , division , print_function <EOL> from construct . core import FieldError <EOL> import pytest <EOL> from tls . record import ( <EOL> ContentType , TLSCiphertext , TLSCompressed , TLSPlaintext <EOL> ) <EOL> class TestTLSPlaintextParsing ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_parse_tls_plaintext_handshake ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> record = TLSPlaintext . from_bytes ( packet ) <EOL> assert record . type == ContentType . HANDSHAKE <EOL> assert record . version . major == <NUM_LIT:3> <EOL> assert record . version . minor == <NUM_LIT:3> <EOL> assert record . fragment == b'<STR_LIT>' <EOL> def test_parse_tls_plaintext_wrong_type ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( ValueError ) as exc_info : <EOL> TLSPlaintext . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> def test_incomplete_packet ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( FieldError ) as exc_info : <EOL> TLSPlaintext . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> def test_not_enough_data_to_fragment ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( FieldError ) as exc_info : <EOL> TLSPlaintext . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> def test_as_bytes ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> record = TLSPlaintext . from_bytes ( packet ) <EOL> assert record . as_bytes ( ) == packet <EOL> class TestTLSCompressedParsing ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_parse_tls_compressed_handshake ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> record = TLSCompressed . from_bytes ( packet ) <EOL> assert record . type == ContentType . HANDSHAKE <EOL> assert record . version . major == <NUM_LIT:3> <EOL> assert record . version . minor == <NUM_LIT:3> <EOL> assert record . fragment == b'<STR_LIT>' <EOL> def test_parse_tls_compressed_wrong_type ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( ValueError ) as exc_info : <EOL> TLSCompressed . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> def test_incomplete_packet ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( FieldError ) as exc_info : <EOL> TLSCompressed . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> def test_not_enough_data_to_fragment ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> with pytest . raises ( FieldError ) as exc_info : <EOL> TLSCompressed . from_bytes ( packet ) <EOL> assert str ( exc_info . value ) == "<STR_LIT>" <EOL> class TestTLSCiphertextParser ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_parse_tls_ciphertext_handshake ( self ) : <EOL> """<STR_LIT>""" <EOL> packet = ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> ) <EOL> record = TLSCiphertext . from_bytes ( packet ) <EOL> assert record . type == ContentType . HANDSHAKE <EOL> assert record . version . major == <NUM_LIT:3> <EOL> assert record . version . minor == <NUM_LIT:3> <EOL> assert record . fragment == b'<STR_LIT>' </s>
