Skip to content

Commit

Permalink
SNOW-1571763 fix login timeout read pattern (#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-aalam authored Aug 13, 2024
1 parent 7b596b2 commit 416ff57
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
- v3.12.1(TBD)
- Fixed a bug that session token is logged when renewing session.
- Fixed a bug that disabling client telemetry does not work.
- Fixed a bug where `login_timeout` when passed as string raised `TypeError` during login retry step.
- Use `pathlib` instead of `os` for default config file location resolution.
- Removed upper `cryptogaphy` version pin.
- Removed reference to script `snowflake-export-certs` (its backing module was already removed long ago)
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/connector/auth/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def authenticate(
self._rest._connection._internal_application_name,
self._rest._connection._internal_application_version,
self._rest._connection._ocsp_mode(),
self._rest._connection._login_timeout,
self._rest._connection.login_timeout,
self._rest._connection._network_timeout,
self._rest._connection._socket_timeout,
)
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/connector/auth/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _step1(
conn._internal_application_name,
conn._internal_application_version,
conn._ocsp_mode(),
conn._login_timeout,
conn.login_timeout,
conn._network_timeout,
)

Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/connector/auth/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _get_sso_url(
conn._rest._connection._internal_application_name,
conn._rest._connection._internal_application_version,
conn._rest._connection._ocsp_mode(),
conn._rest._connection._login_timeout,
conn._rest._connection.login_timeout,
conn._rest._connection._network_timeout,
)

Expand Down
14 changes: 7 additions & 7 deletions src/snowflake/connector/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def __open_connection(self):
elif self._authenticator == DEFAULT_AUTHENTICATOR:
self.auth_class = AuthByDefault(
password=self._password,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)
elif self._authenticator == EXTERNAL_BROWSER_AUTHENTICATOR:
Expand All @@ -1038,7 +1038,7 @@ def __open_connection(self):
protocol=self._protocol,
host=self.host,
port=self.port,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)
else:
Expand All @@ -1048,7 +1048,7 @@ def __open_connection(self):
protocol=self._protocol,
host=self.host,
port=self.port,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)

Expand All @@ -1063,13 +1063,13 @@ def __open_connection(self):

self.auth_class = AuthByKeyPair(
private_key=private_key,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)
elif self._authenticator == OAUTH_AUTHENTICATOR:
self.auth_class = AuthByOAuth(
oauth_token=self._token,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)
elif self._authenticator == USR_PWD_MFA_AUTHENTICATOR:
Expand All @@ -1085,14 +1085,14 @@ def __open_connection(self):
self.auth_class = AuthByUsrPwdMfa(
password=self._password,
mfa_token=self.rest.mfa_token,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)
else:
# okta URL, e.g., https://<account>.okta.com/
self.auth_class = AuthByOkta(
application=self.application,
timeout=self._login_timeout,
timeout=self.login_timeout,
backoff_generator=self._backoff_generator,
)

Expand Down
19 changes: 19 additions & 0 deletions test/integ/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,25 @@ def test_bad_db(db_parameters):
cnx.close()


def test_with_string_login_timeout(db_parameters):
"""Test that login_timeout when passed as string does not raise TypeError.
In this test, we pass bad login credentials to raise error and trigger login
timeout calculation. We expect to see DatabaseError instead of TypeError that
comes from str - int arithmetic.
"""
with pytest.raises(DatabaseError):
snowflake.connector.connect(
protocol="http",
user="bogus",
password="bogus",
host=db_parameters["host"],
port=db_parameters["port"],
account=db_parameters["account"],
login_timeout="5",
)


def test_bogus(db_parameters):
"""Attempts to login with invalid user name and password.
Expand Down

0 comments on commit 416ff57

Please sign in to comment.