Exemplo n.º 1
0
 def test_eq(self):
     data1 = b"\x03\x00\x04Z\xfd\xc6\xff\x02\x00\tAUTHORITI"
     ptlv1 = ProxyTLV.from_raw(data1)
     data2 = b"\x02\x00\tAUTHORITI\x03\x00\x04Z\xfd\xc6\xff"
     ptlv2 = ProxyTLV.from_raw(data2)
     assert ptlv1 is not ptlv2
     assert ptlv1 == ptlv2
Exemplo n.º 2
0
 def test_parse_partial(self):
     TEST_TLV_DATA_1_TRUNCATED = (
         b"\x03\x00\x04Z\xfd\xc6\xff\x02\x00\tAUTHORITI\x05\x00\tUNIKUE_I")
     rslt: Dict[str, Any]
     rslt, _ = ProxyTLV.parse(TEST_TLV_DATA_1_TRUNCATED)
     assert isinstance(rslt, dict)
     assert "CRC32C" in rslt
Exemplo n.º 3
0
 def test_1_ne_raises(self):
     ptlv = ProxyTLV.from_raw(TEST_TLV_DATA_1)
     expectre = r"mismatch:AUTHORITY actual=.* expect=.*"
     with pytest.raises(ValueError, match=expectre):
         ptlv.same_attribs(_raises=True, AUTHORITY=b"whut")
     expectre = r"notfound:i_dont_even"
     with pytest.raises(KeyError, match=expectre):
         ptlv.same_attribs(_raises=True, i_dont_even=b"what is this")
Exemplo n.º 4
0
 def test_malformed_ssl_partialok(self):
     test_data = (
         b"\x20\x00\x17\x01\x02\x03\x04\x05\x21\x00\x07version\x22\x00\x09trunc"
     )
     rslt: Dict[str, Any]
     rslt, _ = ProxyTLV.parse(test_data, partial_ok=True)
     assert rslt["SSL"] is False
     assert rslt["SSL_VERSION"] == b"version"
     assert "SSL_CN" not in rslt
Exemplo n.º 5
0
 def test_1(self):
     ptlv = ProxyTLV.from_raw(TEST_TLV_DATA_1)
     assert "ALPN" not in ptlv
     assert "NOOP" not in ptlv
     assert "SSL_CN" not in ptlv
     assert "NETNS" not in ptlv
     assert ptlv.ALPN is None
     assert ptlv.AUTHORITY == b"AUTHORITI"
     assert ptlv.same_attribs(
         AUTHORITY=b"AUTHORITI",
         CRC32C=b"Z\xfd\xc6\xff",
         UNIQUE_ID=b"UNIKUE_ID",
         SSL=True,
         SSL_VERSION=b"TLSv1.3",
         SSL_CIPHER=b"ECDHE-RSA-AES256-CBC-SHA384",
         SSL_SIG_ALG=b"RSA-SHA256",
         SSL_KEY_ALG=b"RSA4096",
     )
Exemplo n.º 6
0
 def test_2(self):
     ptlv = ProxyTLV.from_raw(TEST_TLV_DATA_2)
     assert "ALPN" not in ptlv
     assert "NOOP" not in ptlv
     assert "SSL_CN" not in ptlv
     assert "NETNS" in ptlv
     assert ptlv.ALPN is None
     assert ptlv.AUTHORITY == b"AUTHORIT2"
     assert ptlv.UNIQUE_ID == b"UNIQUEID2"
     assert ptlv.same_attribs(
         CRC32C=b"Z\xfd\xc6\xff",
         UNIQUE_ID=b"UNIQUEID2",
         SSL=True,
         SSL_VERSION=b"TLSv1.3",
         SSL_CIPHER=b"ECDHE-RSA-AES256-CBC-SHA384",
         SSL_SIG_ALG=b"RSA-SHA256",
         SSL_KEY_ALG=b"RSA4096",
         NETNS=b"something",
     )
     assert not ptlv.same_attribs(false_attrib=None)
     with pytest.raises(ValueError, match=r"mismatch:SSL"):
         ptlv.same_attribs(SSL=False, _raises=True)
Exemplo n.º 7
0
 def test_malformed_ssl_notpartialok(self):
     test_data = (
         b"\x20\x00\x0D\x01\x02\x03\x04\x05\x21\x00\x07version\x22\x00\x09trunc"
     )
     with pytest.raises(MalformedTLV):
         _ = ProxyTLV.parse(test_data, partial_ok=False)
Exemplo n.º 8
0
 def test_unknowntype_strict(self):
     test_data = b"\xFF\x00\x04yeah"
     with pytest.raises(UnknownTypeTLV):
         _ = ProxyTLV.parse(test_data, strict=True)
Exemplo n.º 9
0
 def test_unknowntype_notstrict(self):
     test_data = b"\xFF\x00\x04yeah"
     rslt: Dict[str, Any]
     rslt, _ = ProxyTLV.parse(test_data, strict=False)
     assert "xFF" in rslt
     assert rslt["xFF"] == b"yeah"
Exemplo n.º 10
0
 def test_backmap(self, typename, typeint):
     assert ProxyTLV.name_to_num(typename) == typeint
Exemplo n.º 11
0
 def test_1_ne(self):
     ptlv = ProxyTLV.from_raw(TEST_TLV_DATA_1)
     assert not ptlv.same_attribs(SSL=False)
     assert not ptlv.same_attribs(false_attrib=None)