-
Notifications
You must be signed in to change notification settings - Fork 516
SNOW-2235955: adding MFA test in Python #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e235c8d
adding mfa test
sfc-gh-pcyrek 92ae31d
update docker image
sfc-gh-pcyrek b58c760
trigger_cicd
sfc-gh-pcyrek 2fdeea2
Merge branch 'main' into SNOW-2235955-adding-mfa-tests-in-python
sfc-gh-pcyrek 41b46f0
trigger_cicd
sfc-gh-pcyrek 667ba72
review1
sfc-gh-pcyrek ec8c209
linitng
sfc-gh-pcyrek b7cfafc
trigger cicd
sfc-gh-pcyrek c0b0689
Merge branch 'main' into SNOW-2235955-adding-mfa-tests-in-python
sfc-gh-pcyrek bd23f09
trigger cicd
sfc-gh-pcyrek a0d9efd
Merge branch 'main' into SNOW-2235955-adding-mfa-tests-in-python
sfc-gh-pcyrek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+70 Bytes
(110%)
.github/workflows/parameters/private/parameters_aws_auth_tests.json.gpg
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
from test.auth.authorization_parameters import AuthConnectionParameters | ||
from test.auth.authorization_test_helper import AuthorizationTestHelper | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.auth | ||
def test_mfa_successful(): | ||
connection_parameters = AuthConnectionParameters().get_mfa_connection_parameters() | ||
connection_parameters["client_request_mfa_token"] = True | ||
test_helper = AuthorizationTestHelper(connection_parameters) | ||
totp_codes = test_helper.get_totp() | ||
logging.info(f"Got {len(totp_codes)} TOTP codes to try") | ||
|
||
connection_success = False | ||
last_error = "" | ||
|
||
# Try each TOTP code until one works | ||
for i, totp_code in enumerate(totp_codes): | ||
logging.info(f"Trying TOTP code {i+1}/{len(totp_codes)}") | ||
|
||
# Update the passcode in connection parameters | ||
connection_parameters["passcode"] = totp_code | ||
test_helper.update_config(connection_parameters) | ||
|
||
# Clear any previous error | ||
test_helper.error_msg = "" | ||
|
||
# Try to connect | ||
connection_success = test_helper.connect_and_execute_simple_query() | ||
|
||
if connection_success: | ||
logging.info(f"Successfully connected with TOTP code {i+1}") | ||
break | ||
else: | ||
last_error = str(test_helper.error_msg) | ||
logging.warning(f"TOTP code {i+1} failed: {last_error}") | ||
|
||
# Check if it's a TOTP-related error before continuing | ||
if "TOTP Invalid" in last_error: | ||
logging.info("TOTP/MFA error detected, trying next code...") | ||
continue | ||
else: | ||
# If it's not a TOTP error, no point trying other codes | ||
logging.error(f"Non-TOTP error detected: {last_error}") | ||
break | ||
|
||
assert ( | ||
connection_success | ||
), f"Failed to connect with any of the {len(totp_codes)} TOTP codes. Last error: {last_error}" | ||
assert ( | ||
test_helper.error_msg == "" | ||
), f"Final error message should be empty but got: {test_helper.error_msg}" | ||
|
||
logging.info("Testing MFA token caching with second connection...") | ||
|
||
# Create fresh connection parameters for cache test - but use same exact config | ||
cache_test_parameters = connection_parameters.copy() | ||
|
||
# Remove the passcode that was set in the loop - should use cached MFA token instead | ||
if "passcode" in cache_test_parameters: | ||
del cache_test_parameters["passcode"] | ||
|
||
# Create new helper for cache test | ||
cache_test_helper = AuthorizationTestHelper(cache_test_parameters) | ||
cache_test_helper.error_msg = "" | ||
cache_connection_success = cache_test_helper.connect_and_execute_simple_query() | ||
|
||
assert ( | ||
cache_connection_success | ||
), f"Failed to connect with cached MFA token. Error: {cache_test_helper.error_msg}" | ||
assert ( | ||
cache_test_helper.error_msg == "" | ||
), f"Cache test error message should be empty but got: {cache_test_helper.error_msg}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.