Exemplo n.º 1
0
    def test_decompression_failed_invalid(self):
        decoder = Decoder(0x100, 0x10)

        with self.assertRaises(DecompressionFailed) as cm:
            decoder.feed_header(0, b"123")
        self.assertEqual(str(cm.exception),
                         "lsqpack_dec_header_in for stream 0 failed")
Exemplo n.º 2
0
    def test_blocked_stream_free(self):
        decoder = Decoder(0x100, 0x10)
        stream_id = 0

        # the stream is blocked
        with self.assertRaises(StreamBlocked):
            decoder.feed_header(stream_id, binascii.unhexlify("0482d9101112"))

        # free the decoder with pending block
        del decoder
Exemplo n.º 3
0
    def test_with_settings(self):
        encoder = Encoder()
        decoder = Decoder(0x100, 0x10)
        stream_id = 0
        seqno = 0

        # apply decoder settings
        tsu = encoder.apply_settings(0x100, 0x10)
        self.assertEqual(tsu, b"\x3f\xe1\x01")

        # ROUND 1

        # encode headers
        control, data = encoder.encode(stream_id, seqno, [(b"one", b"foo"),
                                                          (b"two", b"bar")])
        self.assertEqual(control, b"")
        self.assertEqual(data, b"\x00\x00*=E\x82\x94\xe7#two\x03bar")

        # decode headers
        decoder.feed_encoder(control)
        control, headers = decoder.feed_header(stream_id, data)
        self.assertEqual(control, b"")
        self.assertEqual(headers, [(b"one", b"foo"), (b"two", b"bar")])

        # ROUND 2

        # encode headers
        control, data = encoder.encode(stream_id, seqno, [(b"one", b"foo"),
                                                          (b"two", b"bar")])
        self.assertEqual(control, b"b=E\x82\x94\xe7Ctwo\x03bar")
        self.assertEqual(data, b"\x03\x81\x10\x11")

        # decode headers
        decoder.feed_encoder(control)
        control, headers = decoder.feed_header(stream_id, data)
        self.assertEqual(control, b"\x80")
        self.assertEqual(headers, [(b"one", b"foo"), (b"two", b"bar")])

        # ROUND 3

        # encode headers
        control, data = encoder.encode(stream_id, seqno, [(b"one", b"foo"),
                                                          (b"two", b"bar")])
        self.assertEqual(control, b"")
        self.assertEqual(data, b"\x03\x00\x81\x80")

        # decode headers
        decoder.feed_encoder(control)
        control, headers = decoder.feed_header(stream_id, data)
        self.assertEqual(control, b"\x80")
        self.assertEqual(headers, [(b"one", b"foo"), (b"two", b"bar")])
Exemplo n.º 4
0
    def test_simple(self):
        encoder = Encoder()
        decoder = Decoder(0x100, 0x10)
        stream_id = 0

        # encode headers
        control, data = encoder.encode(stream_id, [(b"one", b"foo"),
                                                   (b"two", b"bar")])
        self.assertEqual(control, b"")
        self.assertEqual(data, b"\x00\x00*=E\x82\x94\xe7#two\x03bar")

        # decode headers
        decoder.feed_encoder(control)
        control, headers = decoder.feed_header(stream_id, data)
        self.assertEqual(control, b"")
        self.assertEqual(headers, [(b"one", b"foo"), (b"two", b"bar")])
Exemplo n.º 5
0
    def test_blocked_stream(self):
        decoder = Decoder(0x100, 0x10)
        stream_id = 0

        # no streams unblocked
        self.assertEqual(decoder.feed_encoder(b""), [])

        # cannot resume non existent block
        with self.assertRaises(ValueError):
            decoder.resume_header(stream_id)

        # the stream is blocked
        with self.assertRaises(StreamBlocked):
            decoder.feed_header(stream_id, binascii.unhexlify("0482d9101112"))

        # the stream is still blocked
        with self.assertRaises(StreamBlocked):
            decoder.resume_header(stream_id)

        # the stream becomes unblocked
        self.assertEqual(
            decoder.feed_encoder(
                binascii.unhexlify(
                    "3fe10168f2b14939d69ce84f8d9635e9ef2a12bd454dc69a659f6cf2b14939d6"
                    "b505b161cc5a9385198fdad313c696dd6d5f4a082a65b6850400bea0837190dc"
                    "138a62d1bf")),
            [stream_id],
        )

        # the header is resumed
        control, headers = decoder.resume_header(stream_id)
        self.assertEqual(control, b"\x80")
        self.assertEqual(
            headers,
            [
                (b":status", b"200"),
                (b"x-echo-host", b"fb.mvfst.net:4433"),
                (b"x-echo-user-agent", b"aioquic"),
                (b"date", b"Sun, 21 Jul 2019 21:31:26 GMT"),
            ],
        )

        # free the decoder
        del decoder
Exemplo n.º 6
0
    def __init__(self, quic: QuicConnection):
        self._max_table_capacity = 0x100
        self._blocked_streams = 0x10

        self._is_client = quic.configuration.is_client
        self._quic = quic
        self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)
        self._encoder = Encoder()
        self._stream_buffers: Dict[int, bytes] = {}
        self._stream_types: Dict[int, int] = {}

        self._local_control_stream_id: Optional[int] = None
        self._local_decoder_stream_id: Optional[int] = None
        self._local_encoder_stream_id: Optional[int] = None

        self._peer_control_stream_id: Optional[int] = None
        self._peer_decoder_stream_id: Optional[int] = None
        self._peer_encoder_stream_id: Optional[int] = None

        self._init_connection()
Exemplo n.º 7
0
 def test_encoder_stream_error(self):
     decoder = Decoder(0x100, 0x10)
     with self.assertRaises(EncoderStreamError) as cm:
         decoder.feed_encoder(b"\x00")
     self.assertEqual(str(cm.exception), "lsqpack_dec_enc_in failed")