@@ -324,14 +324,34 @@ def test_u2m_custom_client_id_only_falls_back_to_connector_defaults(self):
324324
325325 def test_u2m_redirect_port_coerced_to_int (self ):
326326 # oauth_redirect_port may arrive as a string (e.g. from a DSN);
327- # the kernel binding wants an int.
327+ # the kernel binding wants an int. The port override is coupled to
328+ # an explicit client_id (see the coupling test below), so supply
329+ # one here to exercise the coercion path.
328330 kwargs = kernel_auth_kwargs (
329331 _FakeOAuthProvider (),
330- {"auth_type" : "databricks-oauth" , "oauth_redirect_port" : "8021" },
332+ {
333+ "auth_type" : "databricks-oauth" ,
334+ "oauth_client_id" : "custom-client" ,
335+ "oauth_redirect_port" : "8021" ,
336+ },
331337 )
332338 assert kwargs ["redirect_port" ] == 8021
333339 assert isinstance (kwargs ["redirect_port" ], int )
334340
341+ def test_u2m_redirect_port_ignored_without_client_id (self ):
342+ # A bare oauth_redirect_port (no explicit client_id) must NOT be
343+ # forwarded: it would be paired with the default databricks-sql-python
344+ # app, whose registered redirect URIs only cover the default port
345+ # range, so an arbitrary port would resolve to an unregistered URI
346+ # and fail the U2M flow. This mirrors the Thrift path's coupling,
347+ # where oauth_redirect_port_range is only overridden when both
348+ # oauth_client_id and oauth_redirect_port are supplied.
349+ kwargs = kernel_auth_kwargs (
350+ _FakeOAuthProvider (),
351+ {"auth_type" : "databricks-oauth" , "oauth_redirect_port" : 9999 },
352+ )
353+ assert kwargs ["redirect_port" ] == PYSQL_OAUTH_REDIRECT_PORT_RANGE [0 ]
354+
335355 @pytest .mark .parametrize ("auth_type" , ["databricks-oauth" , "azure-oauth" ])
336356 def test_u2m_forwards_custom_scopes (self , auth_type ):
337357 kwargs = kernel_auth_kwargs (
0 commit comments