From 9bf2570401982e024743150ee4a23bf8e858da1a Mon Sep 17 00:00:00 2001 From: Adam Stus Date: Tue, 11 Jun 2024 17:28:43 +0200 Subject: [PATCH] =?UTF-8?q?Added=20required=20parameter=20for=20MFA=20cach?= =?UTF-8?q?ing=20and=20removed=20internal=20app=20par=E2=80=A6=20(#1187)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RELEASE-NOTES.md | 1 + src/snowflake/cli/app/constants.py | 1 - src/snowflake/cli/app/snow_connector.py | 7 +++---- tests/test_connection.py | 26 ++++++++++++------------- tests/test_main.py | 2 -- tests/test_snow_connector.py | 2 -- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index a124e04ce4..9d330e27c0 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -33,6 +33,7 @@ * Fixed error handling for malformatted `config.toml` * Fixed ZIP packaging of Snowpark project dependencies containing implicit namespace packages like `snowflake`. * Deploying function/procedure with `--replace` flag now copies all grants +* Fixed MFA caching # v2.4.0 ## Backward incompatibility diff --git a/src/snowflake/cli/app/constants.py b/src/snowflake/cli/app/constants.py index 52d46d5dd4..6f716e0d8d 100644 --- a/src/snowflake/cli/app/constants.py +++ b/src/snowflake/cli/app/constants.py @@ -17,4 +17,3 @@ from typing import Literal PARAM_APPLICATION_NAME: Literal["snowcli"] = "snowcli" -PARAM_INTERNAL_APPLICATION_NAME: Literal["snowcli"] = "snowcli" diff --git a/src/snowflake/cli/app/snow_connector.py b/src/snowflake/cli/app/snow_connector.py index 4ba69762ba..d2806b7cd5 100644 --- a/src/snowflake/cli/app/snow_connector.py +++ b/src/snowflake/cli/app/snow_connector.py @@ -30,7 +30,6 @@ from snowflake.cli.api.secure_path import SecurePath from snowflake.cli.app.constants import ( PARAM_APPLICATION_NAME, - PARAM_INTERNAL_APPLICATION_NAME, ) from snowflake.cli.app.telemetry import command_info from snowflake.connector import SnowflakeConnection @@ -38,7 +37,6 @@ log = logging.getLogger(__name__) -from snowflake.cli.__about__ import VERSION ENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN ENCRYPTED PRIVATE KEY-----" UNENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN PRIVATE KEY-----" @@ -98,6 +96,9 @@ def connect_to_snowflake( if mfa_passcode: connection_parameters["passcode"] = mfa_passcode + if connection_parameters.get("authenticator") == "username_password_mfa": + connection_parameters["client_request_mfa_token"] = True + if enable_diag: connection_parameters["enable_connection_diag"] = enable_diag if diag_log_path: @@ -171,8 +172,6 @@ def _update_connection_application_name(connection_parameters: Dict): """Update version and name of app handling connection.""" connection_application_params = { "application_name": PARAM_APPLICATION_NAME, - "internal_application_name": PARAM_INTERNAL_APPLICATION_NAME, - "internal_application_version": VERSION, } connection_parameters.update(connection_application_params) diff --git a/tests/test_connection.py b/tests/test_connection.py index 65ee6bc7aa..f275cda8a4 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -405,8 +405,6 @@ def test_temporary_connection(mock_connector, mock_ctx, option, runner): schema="PUBLIC", warehouse="xsmall", application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", ) @@ -487,8 +485,6 @@ def test_key_pair_authentication(mock_connector, mock_ctx, runner): schema="PUBLIC", warehouse="xsmall", application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", ) @@ -537,8 +533,6 @@ def test_session_and_master_tokens(mock_connector, mock_ctx, runner): warehouse="xsmall", server_session_keep_alive=True, application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", ) @@ -586,8 +580,6 @@ def test_key_pair_authentication_from_config( authenticator="SNOWFLAKE_JWT", private_key="secret value", application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", ) @@ -673,6 +665,18 @@ def test_no_mfa_passcode(mock_connect, runner): assert kwargs.get("passcode") is None +@mock.patch("snowflake.connector.connect") +def test_mfa_cache(mock_connect, runner): + result = runner.invoke( + ["sql", "-q", "select 1", "--authenticator", "username_password_mfa"] + ) + + assert result.exit_code == 0, result.output + args, kwargs = mock_connect.call_args + assert kwargs["authenticator"] == "username_password_mfa" + assert kwargs["client_request_mfa_token"] + + @pytest.mark.parametrize( "env", [ @@ -713,8 +717,6 @@ def test_connection_details_are_resolved_using_environment_variables( "role": "role", "password": "dummy", "application_name": "snowcli", - "internal_application_name": "snowcli", - "internal_application_version": "0.0.0-test_patched", } @@ -774,8 +776,6 @@ def test_flags_take_precedence_before_environment_variables( "password": "password_from_flag", "role": "role_from_flag", "application_name": "snowcli", - "internal_application_name": "snowcli", - "internal_application_version": "0.0.0-test_patched", } @@ -813,8 +813,6 @@ def test_source_precedence(mock_connect, runner): "database": "database_from_connection_env", "role": "role_from_global_env", "application_name": "snowcli", - "internal_application_name": "snowcli", - "internal_application_version": "0.0.0-test_patched", } diff --git a/tests/test_main.py b/tests/test_main.py index 0fc0e60ca0..eb9daed455 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -63,8 +63,6 @@ def test_custom_config_path(mock_conn, runner, mock_cursor): warehouse="xs", password="dummy_password", application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", ) diff --git a/tests/test_snow_connector.py b/tests/test_snow_connector.py index 1f5a344746..b26d7b150a 100644 --- a/tests/test_snow_connector.py +++ b/tests/test_snow_connector.py @@ -63,8 +63,6 @@ def test_command_context_is_passed_to_snowflake_connection( warehouse="xs", password="dummy_password", application_name="snowcli", - internal_application_name="snowcli", - internal_application_version="0.0.0-test_patched", )