Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/google-auth/tests/transport/test__custom_tls_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_custom_tls_signer_provider():
ENTERPRISE_CERT_FILE_PROVIDER
)
signer_object.load_libraries()
signer_object.attach_to_ssl_context(ssl.SSLContext())
signer_object.attach_to_ssl_context(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))

assert signer_object.should_use_provider()
assert signer_object._enterprise_cert_file_path == ENTERPRISE_CERT_FILE_PROVIDER
Expand All @@ -238,7 +238,7 @@ def test_custom_tls_signer_failed_to_attach():
signer_object._sign_callback = mock.MagicMock()
signer_object._cert = b"mock cert"
signer_object._offload_lib.ConfigureSslContext.return_value = False
signer_object.attach_to_ssl_context(ssl.SSLContext())
signer_object.attach_to_ssl_context(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))
assert excinfo.match("failed to configure ECP Offload SSL context")


Expand All @@ -249,7 +249,7 @@ def test_custom_tls_signer_failed_to_attach_provider():
)
signer_object._provider_lib = mock.MagicMock()
signer_object._provider_lib.ECP_attach_to_ctx.return_value = False
signer_object.attach_to_ssl_context(ssl.SSLContext())
signer_object.attach_to_ssl_context(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))
assert excinfo.match("failed to configure ECP Provider SSL context")


Expand All @@ -258,12 +258,12 @@ def test_custom_tls_signer_failed_to_attach_no_libs():
signer_object = _custom_tls_signer.CustomTlsSigner(ENTERPRISE_CERT_FILE)
signer_object._offload_lib = None
signer_object._signer_lib = None
signer_object.attach_to_ssl_context(ssl.SSLContext())
signer_object.attach_to_ssl_context(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))
assert excinfo.match("Invalid ECP configuration.")


def test_cast_ssl_ctx_to_void_p_stdlib_success():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
fake_impl = mock.Mock()
fake_impl.name = "cpython"
with mock.patch("sys.implementation", fake_impl):
Expand All @@ -282,7 +282,7 @@ def test_cast_ssl_ctx_to_void_p_stdlib_success():


def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_pypy():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
fake_impl = mock.Mock()
fake_impl.name = "pypy"

Expand All @@ -295,7 +295,7 @@ def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_pypy():


def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_trace_refs():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
fake_impl = mock.Mock()
fake_impl.name = "cpython"

Expand All @@ -317,7 +317,7 @@ def test_cast_ssl_ctx_to_void_p_stdlib_type_error():


def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_debug_flag():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
fake_impl = mock.Mock()
fake_impl.name = "cpython"
with mock.patch("sys.implementation", fake_impl), mock.patch(
Expand All @@ -331,7 +331,7 @@ def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_debug_flag():


def test_cast_ssl_ctx_to_void_p_stdlib_unsupported_runtime_free_threaded():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

def mock_get_config_var(var):
if var == "Py_GIL_DISABLED":
Expand All @@ -351,7 +351,7 @@ def mock_get_config_var(var):


def test_cast_ssl_ctx_to_void_p_stdlib_dynamic_offset():
context = ssl.SSLContext()
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
with mock.patch("sys.getsizeof", return_value=40) as mock_sizeof:
with mock.patch("ctypes.c_void_p.from_address") as mock_from_address:
_custom_tls_signer._cast_ssl_ctx_to_void_p_stdlib(context)
Expand Down
Loading