Skip to content

Commit c40d89b

Browse files
fix usage of delete_temporary_credential
1 parent 407612e commit c40d89b

File tree

5 files changed

+35
-53
lines changed

5 files changed

+35
-53
lines changed

test/integ/aio/sso/test_connection_manual_async.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import pytest
2525

2626
import snowflake.connector.aio
27-
from snowflake.connector.auth._auth import delete_temporary_credential
27+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
2828

2929
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
3030

@@ -77,11 +77,7 @@ async def fin():
7777

7878

7979
@pytest.mark.skipif(
80-
not (
81-
CONNECTION_PARAMETERS_SSO
82-
and CONNECTION_PARAMETERS_ADMIN
83-
and delete_temporary_credential
84-
),
80+
not (CONNECTION_PARAMETERS_SSO and CONNECTION_PARAMETERS_ADMIN),
8581
reason="SSO and ADMIN connection parameters must be provided.",
8682
)
8783
async def test_connect_externalbrowser(token_validity_test_values):
@@ -90,10 +86,13 @@ async def test_connect_externalbrowser(token_validity_test_values):
9086
In order to run this test, remove the above pytest.mark.skip annotation and run it. It will popup a windows once
9187
but the rest connections should not create popups.
9288
"""
93-
delete_temporary_credential(
94-
host=CONNECTION_PARAMETERS_SSO["host"],
95-
user=CONNECTION_PARAMETERS_SSO["user"],
96-
cred_type=ID_TOKEN,
89+
90+
TokenCache.make().remove(
91+
TokenKey(
92+
CONNECTION_PARAMETERS_SSO["host"],
93+
CONNECTION_PARAMETERS_SSO["user"],
94+
TokenType.ID_TOKEN,
95+
)
9796
) # delete existing temporary credential
9897
CONNECTION_PARAMETERS_SSO["client_store_temporary_credential"] = True
9998

test/integ/sso/test_connection_manual.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
import pytest
2525

2626
import snowflake.connector
27-
28-
try:
29-
from snowflake.connector.auth import delete_temporary_credential
30-
except ImportError:
31-
delete_temporary_credential = None
27+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
3228

3329
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
3430

@@ -79,11 +75,7 @@ def fin():
7975

8076

8177
@pytest.mark.skipif(
82-
not (
83-
CONNECTION_PARAMETERS_SSO
84-
and CONNECTION_PARAMETERS_ADMIN
85-
and delete_temporary_credential
86-
),
78+
not (CONNECTION_PARAMETERS_SSO and CONNECTION_PARAMETERS_ADMIN),
8779
reason="SSO and ADMIN connection parameters must be provided.",
8880
)
8981
def test_connect_externalbrowser(token_validity_test_values):
@@ -92,10 +84,12 @@ def test_connect_externalbrowser(token_validity_test_values):
9284
In order to run this test, remove the above pytest.mark.skip annotation and run it. It will popup a windows once
9385
but the rest connections should not create popups.
9486
"""
95-
delete_temporary_credential(
96-
host=CONNECTION_PARAMETERS_SSO["host"],
97-
user=CONNECTION_PARAMETERS_SSO["user"],
98-
cred_type=ID_TOKEN,
87+
TokenCache.make().remove(
88+
TokenKey(
89+
CONNECTION_PARAMETERS_SSO["host"],
90+
CONNECTION_PARAMETERS_SSO["user"],
91+
TokenType.ID_TOKEN,
92+
)
9993
) # delete existing temporary credential
10094
CONNECTION_PARAMETERS_SSO["client_store_temporary_credential"] = True
10195

test/integ/sso/test_unit_sso_connection.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@
88
import os
99
from unittest.mock import Mock, patch
1010

11-
import pytest
12-
1311
import snowflake.connector
12+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
1413

1514
try:
1615
from snowflake.connector.compat import IS_MACOS
1716
except ImportError:
1817
IS_MACOS = False
19-
try:
20-
from snowflake.connector.auth import delete_temporary_credential
21-
except ImportError:
22-
delete_temporary_credential = None
18+
2319

2420
ID_TOKEN = "ID_TOKEN"
2521

2622

27-
@pytest.mark.skipif(
28-
delete_temporary_credential is None,
29-
reason="delete_temporary_credential is not available.",
30-
)
3123
@patch("snowflake.connector.auth_webbrowser.AuthByWebBrowser.authenticate")
3224
@patch("snowflake.connector.network.SnowflakeRestful._post_request")
3325
def test_connect_externalbrowser(
@@ -119,7 +111,7 @@ def test_body():
119111
authenticator = "externalbrowser"
120112
host = "testaccount.snowflakecomputing.com"
121113

122-
delete_temporary_credential(host=host, user=user, cred_type=ID_TOKEN)
114+
TokenCache.make().remove(TokenKey(host, user, TokenType.ID_TOKEN))
123115

124116
# first connection
125117
con = snowflake.connector.connect(

test/unit/aio/test_mfa_no_cache_async.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,20 @@
1212

1313
import snowflake.connector.aio
1414
from snowflake.connector.compat import IS_LINUX
15+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
1516

1617
try:
1718
from snowflake.connector.options import installed_keyring
1819
except ImportError:
1920
# if installed_keyring is unavailable, we set it as True to skip the test
2021
installed_keyring = True
21-
try:
22-
from snowflake.connector.auth._auth import delete_temporary_credential
23-
except ImportError:
24-
delete_temporary_credential = None
2522

2623
MFA_TOKEN = "MFATOKEN"
2724

2825

2926
@pytest.mark.skipif(
30-
IS_LINUX or installed_keyring or not delete_temporary_credential,
31-
reason="Required test env is Mac/Win with no pre-installed keyring package"
32-
"and available delete_temporary_credential.",
27+
IS_LINUX or installed_keyring,
28+
reason="Required test env is Mac/Win with no pre-installed keyring package",
3329
)
3430
@patch("snowflake.connector.aio._network.SnowflakeRestful._post_request")
3531
async def test_mfa_no_local_secure_storage(mockSnowflakeRestfulPostRequest):
@@ -91,8 +87,8 @@ async def mock_post_request(url, headers, json_body, **kwargs):
9187
"host": "testaccount.snowflakecomputing.com",
9288
}
9389

94-
delete_temporary_credential(
95-
host=conn_cfg["host"], user=conn_cfg["user"], cred_type=MFA_TOKEN
90+
TokenCache.make().remove(
91+
TokenKey(conn_cfg["host"], conn_cfg["user"], TokenType.MFA_TOKEN)
9692
)
9793

9894
# first connection, no mfa token cache

test/unit/test_mfa_no_cache.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212

1313
import snowflake.connector
1414
from snowflake.connector.compat import IS_LINUX
15+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
1516

1617
try:
1718
from snowflake.connector.options import installed_keyring
1819
except ImportError:
1920
# if installed_keyring is unavailable, we set it as True to skip the test
2021
installed_keyring = True
21-
try:
22-
from snowflake.connector.auth import delete_temporary_credential
23-
except ImportError:
24-
delete_temporary_credential = None
22+
2523

2624
MFA_TOKEN = "MFATOKEN"
2725

2826

2927
@pytest.mark.skipif(
30-
IS_LINUX or installed_keyring or not delete_temporary_credential,
31-
reason="Required test env is Mac/Win with no pre-installed keyring package"
32-
"and available delete_temporary_credential.",
28+
IS_LINUX or installed_keyring,
29+
reason="Required test env is Mac/Win with no pre-installed keyring package",
3330
)
3431
@patch("snowflake.connector.network.SnowflakeRestful._post_request")
3532
def test_mfa_no_local_secure_storage(mockSnowflakeRestfulPostRequest):
@@ -91,8 +88,12 @@ def mock_post_request(url, headers, json_body, **kwargs):
9188
"host": "testaccount.snowflakecomputing.com",
9289
}
9390

94-
delete_temporary_credential(
95-
host=conn_cfg["host"], user=conn_cfg["user"], cred_type=MFA_TOKEN
91+
TokenCache.make().remove(
92+
TokenKey(
93+
conn_cfg["host"],
94+
conn_cfg["user"],
95+
TokenType.MFA_TOKEN,
96+
)
9697
)
9798

9899
# first connection, no mfa token cache

0 commit comments

Comments
 (0)