Skip to content

Commit 05434dd

Browse files
NO-SNOW Add PAT to authenticators allowing empty username, remove handling of PAT in password field (#2264)
1 parent ed7ad49 commit 05434dd

File tree

4 files changed

+1
-45
lines changed

4 files changed

+1
-45
lines changed

src/snowflake/connector/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,6 @@ def __open_connection(self):
11711171
backoff_generator=self._backoff_generator,
11721172
)
11731173
elif self._authenticator == PROGRAMMATIC_ACCESS_TOKEN:
1174-
if not self._token and self._password:
1175-
self._token = self._password
11761174
self.auth_class = AuthByPAT(self._token)
11771175
elif self._authenticator == WORKLOAD_IDENTITY_AUTHENTICATOR:
11781176
if ENV_VAR_EXPERIMENTAL_AUTHENTICATION not in os.environ:
@@ -1340,6 +1338,7 @@ def __config(self, **kwargs):
13401338
OAUTH_AUTHENTICATOR,
13411339
NO_AUTH_AUTHENTICATOR,
13421340
WORKLOAD_IDENTITY_AUTHENTICATOR,
1341+
PROGRAMMATIC_ACCESS_TOKEN,
13431342
}
13441343

13451344
if not (self._master_token and self._session_token):

test/data/wiremock/mappings/auth/pat/invalid_token.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{
1212
"equalToJson" : {
1313
"data": {
14-
"LOGIN_NAME": "testUser",
1514
"AUTHENTICATOR": "PROGRAMMATIC_ACCESS_TOKEN",
1615
"TOKEN": "some PAT"
1716
}

test/data/wiremock/mappings/auth/pat/successful_flow.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{
1212
"equalToJson" : {
1313
"data": {
14-
"LOGIN_NAME": "testUser",
1514
"AUTHENTICATOR": "PROGRAMMATIC_ACCESS_TOKEN",
1615
"TOKEN": "some PAT"
1716
}

test/unit/test_programmatic_access_token.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def test_valid_pat(wiremock_client: WiremockClient) -> None:
4343
)
4444

4545
cnx = snowflake.connector.connect(
46-
user="testUser",
4746
authenticator=PROGRAMMATIC_ACCESS_TOKEN,
4847
token="some PAT",
4948
account="testAccount",
@@ -70,7 +69,6 @@ def test_invalid_pat(wiremock_client: WiremockClient) -> None:
7069

7170
with pytest.raises(snowflake.connector.errors.DatabaseError) as execinfo:
7271
snowflake.connector.connect(
73-
user="testUser",
7472
authenticator=PROGRAMMATIC_ACCESS_TOKEN,
7573
token="some PAT",
7674
account="testAccount",
@@ -80,42 +78,3 @@ def test_invalid_pat(wiremock_client: WiremockClient) -> None:
8078
)
8179

8280
assert str(execinfo.value).endswith("Programmatic access token is invalid.")
83-
84-
85-
@pytest.mark.skipolddriver
86-
def test_pat_as_password(wiremock_client: WiremockClient) -> None:
87-
wiremock_data_dir = (
88-
pathlib.Path(__file__).parent.parent
89-
/ "data"
90-
/ "wiremock"
91-
/ "mappings"
92-
/ "auth"
93-
/ "pat"
94-
)
95-
96-
wiremock_generic_data_dir = (
97-
pathlib.Path(__file__).parent.parent
98-
/ "data"
99-
/ "wiremock"
100-
/ "mappings"
101-
/ "generic"
102-
)
103-
104-
wiremock_client.import_mapping(wiremock_data_dir / "successful_flow.json")
105-
wiremock_client.add_mapping(
106-
wiremock_generic_data_dir / "snowflake_disconnect_successful.json"
107-
)
108-
109-
cnx = snowflake.connector.connect(
110-
user="testUser",
111-
authenticator=PROGRAMMATIC_ACCESS_TOKEN,
112-
token=None,
113-
password="some PAT",
114-
account="testAccount",
115-
protocol="http",
116-
host=wiremock_client.wiremock_host,
117-
port=wiremock_client.wiremock_http_port,
118-
)
119-
120-
assert cnx, "invalid cnx"
121-
cnx.close()

0 commit comments

Comments
 (0)