@@ -560,6 +560,7 @@ def test_client_creds_successful_flow(
560
560
wiremock_oauth_client_creds_dir ,
561
561
wiremock_generic_mappings_dir ,
562
562
monkeypatch ,
563
+ temp_cache ,
563
564
) -> None :
564
565
wiremock_client .import_mapping (
565
566
wiremock_oauth_client_creds_dir / "successful_flow.json"
@@ -570,6 +571,15 @@ def test_client_creds_successful_flow(
570
571
wiremock_client .add_mapping (
571
572
wiremock_generic_mappings_dir / "snowflake_disconnect_successful.json"
572
573
)
574
+ user = "testUser"
575
+ access_token_key = TokenKey (
576
+ user , wiremock_client .wiremock_host , TokenType .OAUTH_ACCESS_TOKEN
577
+ )
578
+ refresh_token_key = TokenKey (
579
+ user , wiremock_client .wiremock_host , TokenType .OAUTH_REFRESH_TOKEN
580
+ )
581
+ temp_cache .store (access_token_key , "unused-access-token-123" )
582
+ temp_cache .store (refresh_token_key , "unused-refresh-token-123" )
573
583
with mock .patch ("secrets.token_urlsafe" , return_value = "abc123" ):
574
584
cnx = snowflake .connector .connect (
575
585
user = "testUser" ,
@@ -582,10 +592,17 @@ def test_client_creds_successful_flow(
582
592
oauth_token_request_url = f"http://{ wiremock_client .wiremock_host } :{ wiremock_client .wiremock_http_port } /oauth/token-request" ,
583
593
host = wiremock_client .wiremock_host ,
584
594
port = wiremock_client .wiremock_http_port ,
595
+ oauth_enable_refresh_tokens = True ,
596
+ client_store_temporary_credential = True ,
585
597
)
586
598
587
599
assert cnx , "invalid cnx"
588
600
cnx .close ()
601
+ # cached tokens are expected not to change since Client Credenials must not use token cache
602
+ cached_access_token = temp_cache .retrieve (access_token_key )
603
+ cached_refresh_token = temp_cache .retrieve (refresh_token_key )
604
+ assert cached_access_token == "unused-access-token-123"
605
+ assert cached_refresh_token == "unused-refresh-token-123"
589
606
590
607
591
608
@pytest .mark .skipolddriver
@@ -626,58 +643,6 @@ def test_client_creds_token_request_error(
626
643
)
627
644
628
645
629
- @pytest .mark .skipolddriver
630
- def test_client_creds_successful_refresh_token_flow (
631
- wiremock_client : WiremockClient ,
632
- wiremock_oauth_refresh_token_dir ,
633
- wiremock_generic_mappings_dir ,
634
- monkeypatch ,
635
- temp_cache ,
636
- ) -> None :
637
- wiremock_client .import_mapping (
638
- wiremock_generic_mappings_dir / "snowflake_login_failed.json"
639
- )
640
- wiremock_client .add_mapping (
641
- wiremock_oauth_refresh_token_dir / "refresh_successful.json"
642
- )
643
- wiremock_client .add_mapping (
644
- wiremock_generic_mappings_dir / "snowflake_login_successful.json"
645
- )
646
- wiremock_client .add_mapping (
647
- wiremock_generic_mappings_dir / "snowflake_disconnect_successful.json"
648
- )
649
- user = "testUser"
650
- access_token_key = TokenKey (
651
- user , wiremock_client .wiremock_host , TokenType .OAUTH_ACCESS_TOKEN
652
- )
653
- refresh_token_key = TokenKey (
654
- user , wiremock_client .wiremock_host , TokenType .OAUTH_REFRESH_TOKEN
655
- )
656
- temp_cache .store (access_token_key , "expired-access-token-123" )
657
- temp_cache .store (refresh_token_key , "refresh-token-123" )
658
- cnx = snowflake .connector .connect (
659
- user = user ,
660
- authenticator = "OAUTH_CLIENT_CREDENTIALS" ,
661
- oauth_client_id = "123" ,
662
- account = "testAccount" ,
663
- protocol = "http" ,
664
- role = "ANALYST" ,
665
- oauth_client_secret = "testClientSecret" ,
666
- oauth_token_request_url = f"http://{ wiremock_client .wiremock_host } :{ wiremock_client .wiremock_http_port } /oauth/token-request" ,
667
- host = wiremock_client .wiremock_host ,
668
- port = wiremock_client .wiremock_http_port ,
669
- oauth_enable_refresh_tokens = True ,
670
- client_store_temporary_credential = True ,
671
- )
672
- assert cnx , "invalid cnx"
673
- cnx .close ()
674
-
675
- new_access_token = temp_cache .retrieve (access_token_key )
676
- new_refresh_token = temp_cache .retrieve (refresh_token_key )
677
- assert new_access_token == "access-token-123"
678
- assert new_refresh_token == "refresh-token-123"
679
-
680
-
681
646
@pytest .mark .skipolddriver
682
647
def test_client_creds_expired_refresh_token_flow (
683
648
wiremock_client : WiremockClient ,
@@ -729,8 +694,8 @@ def test_client_creds_expired_refresh_token_flow(
729
694
)
730
695
assert cnx , "invalid cnx"
731
696
cnx .close ()
732
-
733
- new_access_token = temp_cache .retrieve (access_token_key )
734
- new_refresh_token = temp_cache .retrieve (refresh_token_key )
735
- assert new_access_token == "access-token-123"
736
- assert new_refresh_token == "refresh-token-123"
697
+ # the cache state is expected not to change, since Client Credentials must not use token caching
698
+ cached_access_token = temp_cache .retrieve (access_token_key )
699
+ cached_refresh_token = temp_cache .retrieve (refresh_token_key )
700
+ assert cached_access_token == "expired- access-token-123"
701
+ assert cached_refresh_token == "expired- refresh-token-123"
0 commit comments