Skip to content

Commit 0a64331

Browse files
SNOW-2110470: Check if integ test would work
1 parent ecab866 commit 0a64331

File tree

4 files changed

+11
-57
lines changed

4 files changed

+11
-57
lines changed

.github/workflows/build_test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ jobs:
172172
run: python -m pip install tox>=4
173173
- name: Run tests
174174
# To run a single test on GHA use the below command:
175-
run: python -m tox run -e `echo py${PYTHON_VERSION/\./}-single-ci | sed 's/ /,/g'`
176-
# run: python -m tox run -e `echo py${PYTHON_VERSION/\./}-{extras,unit,integ,pandas,sso}-ci | sed 's/ /,/g'`
175+
# run: python -m tox run -e `echo py${PYTHON_VERSION/\./}-single-ci | sed 's/ /,/g'`
176+
run: python -m tox run -e `echo py${PYTHON_VERSION/\./}-{extras,unit,integ,pandas,sso}-ci | sed 's/ /,/g'`
177177

178178
env:
179179
PYTHON_VERSION: ${{ matrix.python-version }}
180180
cloud_provider: ${{ matrix.cloud-provider }}
181181
PYTEST_ADDOPTS: --color=yes --tb=short
182182
TOX_PARALLEL_NO_SPINNER: 1
183183
# To specify the test name (in single test mode) pass this env variable:
184-
SINGLE_TEST_NAME: test/auth/test_snowflake_authorization_code.py::test_snowflake_authorization_code_local_application_successful
184+
# SINGLE_TEST_NAME: test/path/filename.py::test_name
185185
shell: bash
186186
- name: Combine coverages
187187
run: python -m tox run -e coverage --skip-missing-interpreters false

src/snowflake/connector/auth/oauth_credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def __init__(
2929
scope: str,
3030
token_cache: TokenCache | None = None,
3131
refresh_token_enabled: bool = False,
32+
connection: SnowflakeConnection | None = None,
3233
**kwargs,
3334
) -> None:
35+
self._validate_client_credentials_present(client_id, client_secret, connection)
3436
super().__init__(
3537
client_id=client_id,
3638
client_secret=client_secret,

src/snowflake/connector/connection.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292
ER_INVALID_VALUE,
9393
ER_INVALID_WIF_SETTINGS,
9494
ER_NO_ACCOUNT_NAME,
95-
ER_NO_CLIENT_ID,
96-
ER_NO_CLIENT_SECRET,
9795
ER_NO_NUMPY,
9896
ER_NO_PASSWORD,
9997
ER_NO_USER,
@@ -1203,7 +1201,6 @@ def __open_connection(self):
12031201
backoff_generator=self._backoff_generator,
12041202
)
12051203
elif self._authenticator == OAUTH_AUTHORIZATION_CODE:
1206-
self._check_oauth_parameters()
12071204
if self._role and (self._oauth_scope == ""):
12081205
# if role is known then let's inject it into scope
12091206
self._oauth_scope = _OAUTH_DEFAULT_SCOPE.format(role=self._role)
@@ -1231,7 +1228,6 @@ def __open_connection(self):
12311228
enable_single_use_refresh_tokens=self._oauth_enable_single_use_refresh_tokens,
12321229
)
12331230
elif self._authenticator == OAUTH_CLIENT_CREDENTIALS:
1234-
self._check_oauth_parameters()
12351231
if self._role and (self._oauth_scope == ""):
12361232
# if role is known then let's inject it into scope
12371233
self._oauth_scope = _OAUTH_DEFAULT_SCOPE.format(role=self._role)
@@ -1249,6 +1245,7 @@ def __open_connection(self):
12491245
else None
12501246
),
12511247
refresh_token_enabled=self._oauth_enable_refresh_tokens,
1248+
connection=self,
12521249
)
12531250
elif self._authenticator == USR_PWD_MFA_AUTHENTICATOR:
12541251
self._session_parameters[PARAMETER_CLIENT_REQUEST_MFA_TOKEN] = (
@@ -2236,54 +2233,6 @@ def _check_experimental_authentication_flag(self) -> None:
22362233
},
22372234
)
22382235

2239-
def _check_oauth_parameters(self) -> None:
2240-
if self._oauth_client_id is None:
2241-
Error.errorhandler_wrapper(
2242-
self,
2243-
None,
2244-
ProgrammingError,
2245-
{
2246-
"msg": "Oauth code flow requirement 'client_id' is empty",
2247-
"errno": ER_NO_CLIENT_ID,
2248-
},
2249-
)
2250-
if self._oauth_client_secret is None:
2251-
Error.errorhandler_wrapper(
2252-
self,
2253-
None,
2254-
ProgrammingError,
2255-
{
2256-
"msg": "Oauth code flow requirement 'client_secret' is empty",
2257-
"errno": ER_NO_CLIENT_SECRET,
2258-
},
2259-
)
2260-
if (
2261-
self._oauth_authorization_url
2262-
and not self._oauth_authorization_url.startswith("https://")
2263-
):
2264-
Error.errorhandler_wrapper(
2265-
self,
2266-
None,
2267-
ProgrammingError,
2268-
{
2269-
"msg": "OAuth supports only authorization urls that use 'https' scheme",
2270-
"errno": ER_INVALID_VALUE,
2271-
},
2272-
)
2273-
if self._oauth_redirect_uri and not (
2274-
self._oauth_redirect_uri.startswith("http://")
2275-
or self._oauth_redirect_uri.startswith("https://")
2276-
):
2277-
Error.errorhandler_wrapper(
2278-
self,
2279-
None,
2280-
ProgrammingError,
2281-
{
2282-
"msg": "OAuth supports only authorization urls that use 'http(s)' scheme",
2283-
"errno": ER_INVALID_VALUE,
2284-
},
2285-
)
2286-
22872236
@staticmethod
22882237
def _detect_application() -> None | str:
22892238
if ENV_VAR_PARTNER in os.environ.keys():

test/unit/test_oauth_token.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ def remove(self, key: TokenKey) -> None:
121121

122122
@pytest.fixture()
123123
def omit_oauth_urls_check():
124+
def get_first_two_args(authorization_url: str, redirect_uri: str, *args, **kwargs):
125+
return authorization_url, redirect_uri
126+
124127
with mock.patch(
125-
"snowflake.connector.SnowflakeConnection._check_oauth_parameters",
126-
return_value=None,
128+
"snowflake.connector.auth.oauth_code.AuthByOauthCode._validate_oauth_code_uris",
129+
side_effect=get_first_two_args,
127130
):
128131
yield
129132

0 commit comments

Comments
 (0)