| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright: (c) 2022, Jordan Borean (@jborean93) <[email protected]> |
| 3 |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) |
| 4 |
import typing |
| 5 |
|
| 6 |
import pytest |
| 7 |
|
| 8 |
import spnego._tls_struct as tls |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.parametrize( |
| 12 |
"enum_cls, value, expected", |
| 13 |
[ |
| 14 |
(tls.TlsProtocolVersion, 0x0A, "Unknown TLS Protocol Version 0x000A"), |
| 15 |
(tls.TlsContentType, 0x63, "Unknown TLS Content Type 0x63"), |
| 16 |
(tls.TlsHandshakeMessageType, 0xFF, "Unknown Handshake Message Type 0xFF"), |
| 17 |
(tls.TlsCipherSuite, 0xFF01, "Unknown Cipher Suite 0xFF01"), |
| 18 |
(tls.TlsCompressionMethod, 0x05, "Unknown Compression Method 0x05"), |
| 19 |
(tls.TlsExtensionType, 0x63, "Unknown Extension Type 0x0063"), |
| 20 |
(tls.TlsServerNameType, 2, "Unknown Server Name Type 0x02"), |
| 21 |
(tls.TlsECPointFormat, 3, "Unknown EC Point Format 0x03"), |
| 22 |
(tls.TlsSupportedGroup, 0x1254, "Unknown Supported Group 0x1254"), |
| 23 |
(tls.TlsSignatureScheme, 0x0001, "Unknown Signature Scheme 0x0001"), |
| 24 |
(tls.TlsPskKeyExchangeMode, 0x44, "Unknown PSK Key Exchange Mode 0x44"), |
| 25 |
(tls.TlsECCurveType, 0x55, "Unknown EC Curve Type 0x55"), |
| 26 |
(tls.TlsClientCertificateType, 0x70, "Unknown Client Certificate Type 0x70"), |
| 27 |
(tls.DistinguishedNameType, "1.2.3.4", "Unknown DN OID Type 1.2.3.4"), |
| 28 |
], |
| 29 |
) |
| 30 |
def test_tls_enum_missing_member(enum_cls, value, expected): |
| 31 |
actual = enum_cls(value) |
| 32 |
assert isinstance(actual, enum_cls) |
| 33 |
assert actual.name == expected |
| 34 |
assert actual.value == value |
| 35 |
|
| 36 |
|
| 37 |
def test_tls_enum_fail_non_int(): |
| 38 |
with pytest.raises(ValueError, match="'fail' is not a valid TlsProtocolVersion"): |
| 39 |
tls.TlsProtocolVersion("fail") # type: ignore[arg-type] # Testing a failure here |