@@ -252,9 +252,9 @@ class TestKernelOAuthU2M:
252252 ``sql offline_access`` / port 8030 (see PECOBLR-4039). The Python
253253 connector is an OVERRIDE: on the kernel path it forwards its OWN
254254 coupled ``client_id`` + ``redirect_port`` bundle so it authenticates
255- as ``databricks-sql-python`` rather than the kernel default. Scopes
256- are fixed to ``PYSQL_OAUTH_SCOPES`` (not caller-overridable), matching
257- the Thrift path which hardcodes them for U2M .
255+ as ``databricks-sql-python`` rather than the kernel default. A caller
256+ may override ``oauth_scopes``; absent one, ``PYSQL_OAUTH_SCOPES`` is
257+ forwarded as the default .
258258
259259 ``azure-oauth`` (Azure AD) is deliberately NOT handled yet — the
260260 kernel can't drive the Azure AD authorization/token flow — so it is
@@ -293,10 +293,9 @@ def test_azure_oauth_not_supported(self, opts):
293293 with pytest .raises (NotSupportedError , match = "azure-oauth" ):
294294 kernel_auth_kwargs (_FakeOAuthProvider (), opts )
295295
296- def test_u2m_custom_client_id_and_port_honored_scopes_fixed (self ):
297- # A caller may override the coupled client_id + redirect_port. Scopes
298- # are NOT caller-overridable (Thrift parity): a supplied oauth_scopes
299- # is ignored and PYSQL_OAUTH_SCOPES is forwarded regardless.
296+ def test_u2m_custom_client_id_port_and_scopes_honored (self ):
297+ # A caller may override the coupled client_id + redirect_port and
298+ # the oauth_scopes. All three are forwarded as supplied.
300299 kwargs = kernel_auth_kwargs (
301300 _FakeOAuthProvider (),
302301 {
@@ -310,14 +309,13 @@ def test_u2m_custom_client_id_and_port_honored_scopes_fixed(self):
310309 "auth_type" : "oauth-u2m" ,
311310 "client_id" : "custom-client" ,
312311 "redirect_port" : 9999 ,
313- "oauth_scopes" : list ( PYSQL_OAUTH_SCOPES ) ,
312+ "oauth_scopes" : [ "custom-scope" , "offline_access" ] ,
314313 }
315314
316315 def test_u2m_custom_client_id_only_falls_back_to_connector_defaults (self ):
317316 # A custom client_id without explicit scopes/port fills the
318- # remaining two from the connector defaults — matching the Thrift
319- # path, where a custom client_id still uses PYSQL_OAUTH_SCOPES and
320- # the default redirect-port range.
317+ # remaining two from the connector defaults — a custom client_id
318+ # still uses PYSQL_OAUTH_SCOPES and the default redirect-port range.
321319 kwargs = kernel_auth_kwargs (
322320 _FakeOAuthProvider (),
323321 {
@@ -362,19 +360,30 @@ def test_u2m_redirect_port_ignored_without_client_id(self):
362360 )
363361 assert kwargs ["redirect_port" ] == PYSQL_OAUTH_REDIRECT_PORT_RANGE [0 ]
364362
365- def test_u2m_ignores_custom_scopes (self ):
366- # Scopes are fixed for U2M — the Thrift path hardcodes
367- # PYSQL_OAUTH_SCOPES and never reads a caller oauth_scopes kwarg, so
368- # the kernel path forwards the same fixed scopes for parity. A
369- # (well-typed) caller oauth_scopes is validated but not honored.
363+ def test_u2m_honors_custom_scopes (self ):
364+ # A caller-supplied oauth_scopes is forwarded to the kernel, even
365+ # without an explicit client_id. Absent one, PYSQL_OAUTH_SCOPES is
366+ # forwarded as the default (see the bare-bundle test above).
370367 kwargs = kernel_auth_kwargs (
371368 _FakeOAuthProvider (),
372369 {
373370 "auth_type" : "databricks-oauth" ,
374371 "oauth_scopes" : ["all-apis" , "offline_access" ],
375372 },
376373 )
377- assert kwargs ["oauth_scopes" ] == list (PYSQL_OAUTH_SCOPES )
374+ assert kwargs ["oauth_scopes" ] == ["all-apis" , "offline_access" ]
375+
376+ def test_u2m_normalizes_space_delimited_scopes (self ):
377+ # A space-delimited oauth_scopes string is normalized to a list,
378+ # mirroring the M2M path.
379+ kwargs = kernel_auth_kwargs (
380+ _FakeOAuthProvider (),
381+ {
382+ "auth_type" : "databricks-oauth" ,
383+ "oauth_scopes" : "all-apis offline_access" ,
384+ },
385+ )
386+ assert kwargs ["oauth_scopes" ] == ["all-apis" , "offline_access" ]
378387
379388
380389class TestKernelIdentityFederationClientId :
0 commit comments