Skip to content

Commit 407612e

Browse files
[Async] apply #2210 to async code
1 parent 7f8792b commit 407612e

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/snowflake/connector/aio/auth/_auth.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
from typing import TYPE_CHECKING, Any, Callable
1414

1515
from ...auth import Auth as AuthSync
16-
from ...auth._auth import (
17-
AUTHENTICATION_REQUEST_KEY_WHITELIST,
18-
ID_TOKEN,
19-
MFA_TOKEN,
20-
delete_temporary_credential,
21-
)
16+
from ...auth._auth import AUTHENTICATION_REQUEST_KEY_WHITELIST
2217
from ...compat import urlencode
2318
from ...constants import (
2419
HTTP_HEADER_ACCEPT,
@@ -43,6 +38,7 @@
4338
ReauthenticationRequest,
4439
)
4540
from ...sqlstate import SQLSTATE_CONNECTION_WAS_NOT_ESTABLISHED
41+
from ...token_cache import TokenType
4642
from ._no_auth import AuthNoAuth
4743

4844
if TYPE_CHECKING:
@@ -280,7 +276,9 @@ async def post_request_wrapper(self, url, headers, body) -> None:
280276
# clear stored id_token if failed to connect because of id_token
281277
# raise an exception for reauth without id_token
282278
self._rest.id_token = None
283-
delete_temporary_credential(self._rest._host, user, ID_TOKEN)
279+
self.delete_temporary_credential(
280+
self._rest._host, user, TokenType.ID_TOKEN
281+
)
284282
raise ReauthenticationRequest(
285283
ProgrammingError(
286284
msg=ret["message"],
@@ -301,7 +299,9 @@ async def post_request_wrapper(self, url, headers, body) -> None:
301299
from . import AuthByUsrPwdMfa
302300

303301
if isinstance(auth_instance, AuthByUsrPwdMfa):
304-
delete_temporary_credential(self._rest._host, user, MFA_TOKEN)
302+
self.delete_temporary_credential(
303+
self._rest._host, user, TokenType.MFA_TOKEN
304+
)
305305
Error.errorhandler_wrapper(
306306
self._rest._connection,
307307
None,

test/integ/aio/sso/test_unit_mfa_cache_async.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,9 @@
2323
IS_LINUX = platform.system() == "Linux"
2424
IS_WINDOWS = platform.system() == "Windows"
2525

26-
try:
27-
import keyring # noqa
28-
29-
from snowflake.connector.auth._auth import delete_temporary_credential
30-
except ImportError:
31-
delete_temporary_credential = None
32-
33-
MFA_TOKEN = "MFATOKEN"
34-
3526

3627
# Although this is an unit test, we put it under test/integ/sso, since it needs keyring package installed
37-
@pytest.mark.skipif(
38-
delete_temporary_credential is None,
39-
reason="delete_temporary_credential is not available.",
40-
)
28+
@pytest.mark.skipolddriver
4129
@patch("snowflake.connector.aio._network.SnowflakeRestful._post_request")
4230
async def test_mfa_cache(mockSnowflakeRestfulPostRequest):
4331
"""Connects with (username, pwd, mfa) mock."""
@@ -134,8 +122,10 @@ def mock_get_password(system, user):
134122
mockSnowflakeRestfulPostRequest.side_effect = mock_post_request
135123

136124
async def test_body(conn_cfg):
137-
delete_temporary_credential(
138-
host=conn_cfg["host"], user=conn_cfg["user"], cred_type=MFA_TOKEN
125+
from snowflake.connector.token_cache import TokenCache, TokenKey, TokenType
126+
127+
TokenCache.make().remove(
128+
TokenKey(conn_cfg["host"], conn_cfg["user"], TokenType.MFA_TOKEN)
139129
)
140130

141131
# first connection, no mfa token cache

0 commit comments

Comments
 (0)