Skip to content

Commit 41eb42d

Browse files
cathleenyIsaac
andcommitted
test(kernel): cover the credentials_provider http-client gate
Add test_kernel_credentials_provider_keeps_python_http_client: on use_kernel=True with a credentials_provider the connector still builds a UnifiedHttpClient and hands it to the session, the federation- wrapped provider chain and the kernel, as on Thrift. Verified the test fails with the gate removed (TokenFederationProvider raises on http_client=None). The no-provider control case is covered by test_kernel_http_client_lifecycle[explicit]. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
1 parent 84d527b commit 41eb42d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎tests/unit/test_session.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,37 @@ def test_kernel_http_client_lifecycle(self, mock_thrift, route):
10201020
1 if route == "recovery" else 0
10211021
)
10221022

1023+
@patch("%s.session.ThriftDatabricksClient" % PACKAGE)
1024+
def test_kernel_credentials_provider_keeps_python_http_client(self, mock_thrift):
1025+
# use_kernel=True WITH a credentials_provider: unlike a plain kernel
1026+
# connection, the connector still builds its own UnifiedHttpClient —
1027+
# the provider chain's token-federation exchange needs it, exactly
1028+
# as on Thrift (TokenFederationProvider raises on a missing client,
1029+
# so a regression here breaks federation at runtime). The client must
1030+
# flow to the session, the federation-wrapped chain and the kernel.
1031+
# The control case — use_kernel=True without a provider builds no
1032+
# client — is covered by test_kernel_http_client_lifecycle[explicit].
1033+
from databricks.sql.auth.token_federation import TokenFederationProvider
1034+
1035+
def provider():
1036+
return {"Authorization": "Bearer prov#1"}
1037+
1038+
with self._fake_kernel() as kernel, patch(
1039+
f"{self.PACKAGE}.client.UnifiedHttpClient"
1040+
) as http_client:
1041+
conn = self._connect(use_kernel=True, credentials_provider=provider)
1042+
try:
1043+
assert conn.session.use_kernel is True
1044+
http_client.assert_called_once()
1045+
assert conn.http_client is http_client.return_value
1046+
assert conn.session.http_client is conn.http_client
1047+
assert kernel.call_args.kwargs["http_client"] is conn.http_client
1048+
# Same federation-wrapped chain as Thrift, carrying that client.
1049+
assert isinstance(conn.session.auth_provider, TokenFederationProvider)
1050+
assert conn.session.auth_provider.http_client is conn.http_client
1051+
finally:
1052+
conn.close()
1053+
10231054
@pytest.mark.parametrize("failure_stage", ["backend", "open"])
10241055
def test_explicit_kernel_failure_preserves_error_and_telemetry(self, failure_stage):
10251056
with self._fake_kernel() as kernel, patch(

0 commit comments

Comments
 (0)