@@ -577,6 +577,7 @@ async def test_client_creds_successful_flow_async(
577577 wiremock_client : WiremockClient ,
578578 wiremock_oauth_client_creds_dir ,
579579 wiremock_generic_mappings_dir ,
580+ temp_cache_async ,
580581) -> None :
581582 wiremock_client .import_mapping (
582583 wiremock_oauth_client_creds_dir / "successful_flow.json"
@@ -587,6 +588,15 @@ async def test_client_creds_successful_flow_async(
587588 wiremock_client .add_mapping (
588589 wiremock_generic_mappings_dir / "snowflake_disconnect_successful.json"
589590 )
591+ user = "testUser"
592+ access_token_key = TokenKey (
593+ user , wiremock_client .wiremock_host , TokenType .OAUTH_ACCESS_TOKEN
594+ )
595+ refresh_token_key = TokenKey (
596+ user , wiremock_client .wiremock_host , TokenType .OAUTH_REFRESH_TOKEN
597+ )
598+ temp_cache_async .store (access_token_key , "unused-access-token-123" )
599+ temp_cache_async .store (refresh_token_key , "unused-refresh-token-123" )
590600 with mock .patch ("secrets.token_urlsafe" , return_value = "abc123" ):
591601 cnx = SnowflakeConnection (
592602 user = "testUser" ,
@@ -599,10 +609,17 @@ async def test_client_creds_successful_flow_async(
599609 oauth_token_request_url = f"http://{ wiremock_client .wiremock_host } :{ wiremock_client .wiremock_http_port } /oauth/token-request" ,
600610 host = wiremock_client .wiremock_host ,
601611 port = wiremock_client .wiremock_http_port ,
612+ oauth_enable_refresh_tokens = True ,
613+ client_store_temporary_credential = True ,
602614 )
603615
604616 await cnx .connect ()
605617 await cnx .close ()
618+ # cached tokens are expected not to change since Client Credentials must not use token cache
619+ cached_access_token = temp_cache_async .retrieve (access_token_key )
620+ cached_refresh_token = temp_cache_async .retrieve (refresh_token_key )
621+ assert cached_access_token == "unused-access-token-123"
622+ assert cached_refresh_token == "unused-refresh-token-123"
606623
607624
608625@pytest .mark .skipolddriver
@@ -643,57 +660,6 @@ async def test_client_creds_token_request_error_async(
643660 )
644661
645662
646- @pytest .mark .skipolddriver
647- async def test_client_creds_successful_refresh_token_flow_async (
648- wiremock_client : WiremockClient ,
649- wiremock_oauth_refresh_token_dir ,
650- wiremock_generic_mappings_dir ,
651- temp_cache_async ,
652- ) -> None :
653- wiremock_client .import_mapping (
654- wiremock_generic_mappings_dir / "snowflake_login_failed.json"
655- )
656- wiremock_client .add_mapping (
657- wiremock_oauth_refresh_token_dir / "refresh_successful.json"
658- )
659- wiremock_client .add_mapping (
660- wiremock_generic_mappings_dir / "snowflake_login_successful.json"
661- )
662- wiremock_client .add_mapping (
663- wiremock_generic_mappings_dir / "snowflake_disconnect_successful.json"
664- )
665- user = "testUser"
666- access_token_key = TokenKey (
667- user , wiremock_client .wiremock_host , TokenType .OAUTH_ACCESS_TOKEN
668- )
669- refresh_token_key = TokenKey (
670- user , wiremock_client .wiremock_host , TokenType .OAUTH_REFRESH_TOKEN
671- )
672- temp_cache_async .store (access_token_key , "expired-access-token-123" )
673- temp_cache_async .store (refresh_token_key , "refresh-token-123" )
674- cnx = SnowflakeConnection (
675- user = user ,
676- authenticator = "OAUTH_CLIENT_CREDENTIALS" ,
677- oauth_client_id = "123" ,
678- account = "testAccount" ,
679- protocol = "http" ,
680- role = "ANALYST" ,
681- oauth_client_secret = "testClientSecret" ,
682- oauth_token_request_url = f"http://{ wiremock_client .wiremock_host } :{ wiremock_client .wiremock_http_port } /oauth/token-request" ,
683- host = wiremock_client .wiremock_host ,
684- port = wiremock_client .wiremock_http_port ,
685- oauth_enable_refresh_tokens = True ,
686- client_store_temporary_credential = True ,
687- )
688- await cnx .connect ()
689- await cnx .close ()
690-
691- new_access_token = temp_cache_async .retrieve (access_token_key )
692- new_refresh_token = temp_cache_async .retrieve (refresh_token_key )
693- assert new_access_token == "access-token-123"
694- assert new_refresh_token == "refresh-token-123"
695-
696-
697663@pytest .mark .skipolddriver
698664async def test_client_creds_expired_refresh_token_flow_async (
699665 wiremock_client : WiremockClient ,
@@ -744,8 +710,8 @@ async def test_client_creds_expired_refresh_token_flow_async(
744710 )
745711 await cnx .connect ()
746712 await cnx .close ()
747-
748- new_access_token = temp_cache_async .retrieve (access_token_key )
749- new_refresh_token = temp_cache_async .retrieve (refresh_token_key )
750- assert new_access_token == "access-token-123"
751- assert new_refresh_token == "refresh-token-123"
713+ # the cache state is expected not to change, since Client Credentials must not use token caching
714+ cached_access_token = temp_cache_async .retrieve (access_token_key )
715+ cached_refresh_token = temp_cache_async .retrieve (refresh_token_key )
716+ assert cached_access_token == "expired- access-token-123"
717+ assert cached_refresh_token == "expired- refresh-token-123"
0 commit comments