Debian Codegraph @

tests/test_retry.py

raw symbols SCIP
1 from unittest import TestCase
2
3 from aioquic.quic.retry import QuicRetryTokenHandler
4
5
6 class QuicRetryTokenHandlerTest(TestCase):
7 def test_retry_token(self):
8 addr = ("127.0.0.1", 1234)
9 original_destination_connection_id = b"\x08\x07\x06\05\x04\x03\x02\x01"
10 retry_source_connection_id = b"abcdefgh"
11
12 handler = QuicRetryTokenHandler()
13
14 # create token
15 token = handler.create_token(
16 addr, original_destination_connection_id, retry_source_connection_id
17 )
18 self.assertIsNotNone(token)
19 self.assertEqual(len(token), 256)
20
21 # validate token - ok
22 self.assertEqual(
23 handler.validate_token(addr, token),
24 (original_destination_connection_id, retry_source_connection_id),
25 )
26
27 # validate token - empty
28 with self.assertRaises(ValueError) as cm:
29 handler.validate_token(addr, b"")
30 self.assertEqual(
31 str(cm.exception), "Ciphertext length must be equal to key size."
32 )
33
34 # validate token - wrong address
35 with self.assertRaises(ValueError) as cm:
36 handler.validate_token(("1.2.3.4", 12345), token)
37 self.assertEqual(str(cm.exception), "Remote address does not match.")