Skip to content

Commit c3cffb2

Browse files
require SF_ENABLE_EXPERIMENTAL_AUTHENTICATION to be set to true (#2261)
1 parent 2500646 commit c3cffb2

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/snowflake/connector/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,13 +2235,13 @@ def is_valid(self) -> bool:
22352235
return False
22362236

22372237
def _check_experimental_authentication_flag(self) -> None:
2238-
if ENV_VAR_EXPERIMENTAL_AUTHENTICATION not in os.environ:
2238+
if os.getenv(ENV_VAR_EXPERIMENTAL_AUTHENTICATION, "false").lower() != "true":
22392239
Error.errorhandler_wrapper(
22402240
self,
22412241
None,
22422242
ProgrammingError,
22432243
{
2244-
"msg": f"Please set the '{ENV_VAR_EXPERIMENTAL_AUTHENTICATION}' environment variable to use the '{self._authenticator}' authenticator.",
2244+
"msg": f"Please set the '{ENV_VAR_EXPERIMENTAL_AUTHENTICATION}' environment variable true to use the '{self._authenticator}' authenticator.",
22452245
"errno": ER_EXPERIMENTAL_AUTHENTICATION_NOT_SUPPORTED,
22462246
},
22472247
)

test/unit/test_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def test_cannot_set_wlid_authenticator_without_env_variable(mock_post_requests):
626626
account="account", authenticator="WORKLOAD_IDENTITY"
627627
)
628628
assert (
629-
"Please set the 'SF_ENABLE_EXPERIMENTAL_AUTHENTICATION' environment variable to use the 'WORKLOAD_IDENTITY' authenticator"
629+
"Please set the 'SF_ENABLE_EXPERIMENTAL_AUTHENTICATION' environment variable true to use the 'WORKLOAD_IDENTITY' authenticator"
630630
in str(excinfo.value)
631631
)
632632

@@ -636,7 +636,7 @@ def test_connection_params_are_plumbed_into_authbyworkloadidentity(monkeypatch):
636636
m.setattr(
637637
"snowflake.connector.SnowflakeConnection._authenticate", lambda *_: None
638638
)
639-
m.setenv("SF_ENABLE_EXPERIMENTAL_AUTHENTICATION", "") # Can be set to anything.
639+
m.setenv("SF_ENABLE_EXPERIMENTAL_AUTHENTICATION", "true")
640640

641641
conn = snowflake.connector.connect(
642642
account="my_account_1",
@@ -678,7 +678,7 @@ def test_toml_connection_params_are_plumbed_into_authbyworkloadidentity(
678678
m.setattr(
679679
"snowflake.connector.SnowflakeConnection._authenticate", lambda *_: None
680680
)
681-
m.setenv("SF_ENABLE_EXPERIMENTAL_AUTHENTICATION", "")
681+
m.setenv("SF_ENABLE_EXPERIMENTAL_AUTHENTICATION", "true")
682682

683683
conn = snowflake.connector.connect(connections_file_path=connections_file)
684684
assert conn.auth_class.provider == AttestationProvider.OIDC

test/unit/test_oauth_token.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,24 @@ def test_auth_is_experimental(
706706
account="testAccount",
707707
authenticator=authenticator,
708708
)
709+
710+
711+
@pytest.mark.skipolddriver
712+
@pytest.mark.skipolddriver
713+
@pytest.mark.parametrize(
714+
"authenticator", ["OAUTH_AUTHORIZATION_CODE", "OAUTH_CLIENT_CREDENTIALS"]
715+
)
716+
def test_auth_experimental_when_variable_set_to_false(
717+
authenticator,
718+
monkeypatch,
719+
) -> None:
720+
monkeypatch.setenv("SF_ENABLE_EXPERIMENTAL_AUTHENTICATION", "false")
721+
with pytest.raises(
722+
snowflake.connector.ProgrammingError,
723+
match=r"SF_ENABLE_EXPERIMENTAL_AUTHENTICATION",
724+
):
725+
snowflake.connector.connect(
726+
user="testUser",
727+
account="testAccount",
728+
authenticator="OAUTH_CLIENT_CREDENTIALS",
729+
)

0 commit comments

Comments
 (0)