Skip to content

Commit 8ebb247

Browse files
sfc-gh-mkubiksfc-gh-pczajka
authored andcommitted
NO-SNOW Add PAT to authenticators allowing empty username, remove handling of PAT in password field (#2264)
1 parent 9fa9787 commit 8ebb247

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
@@ -1161,8 +1161,6 @@ def __open_connection(self):
11611161
backoff_generator=self._backoff_generator,
11621162
)
11631163
elif self._authenticator == PROGRAMMATIC_ACCESS_TOKEN:
1164-
if not self._token and self._password:
1165-
self._token = self._password
11661164
self.auth_class = AuthByPAT(self._token)
11671165
elif self._authenticator == WORKLOAD_IDENTITY_AUTHENTICATOR:
11681166
if ENV_VAR_EXPERIMENTAL_AUTHENTICATION not in os.environ:
@@ -1325,6 +1323,7 @@ def __config(self, **kwargs):
13251323
OAUTH_AUTHENTICATOR,
13261324
NO_AUTH_AUTHENTICATOR,
13271325
WORKLOAD_IDENTITY_AUTHENTICATOR,
1326+
PROGRAMMATIC_ACCESS_TOKEN,
13281327
}
13291328

13301329
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
@@ -47,7 +47,6 @@ def test_valid_pat(wiremock_client: WiremockClient) -> None:
4747
)
4848

4949
cnx = snowflake.connector.connect(
50-
user="testUser",
5150
authenticator=PROGRAMMATIC_ACCESS_TOKEN,
5251
token="some PAT",
5352
account="testAccount",
@@ -74,7 +73,6 @@ def test_invalid_pat(wiremock_client: WiremockClient) -> None:
7473

7574
with pytest.raises(snowflake.connector.errors.DatabaseError) as execinfo:
7675
snowflake.connector.connect(
77-
user="testUser",
7876
authenticator=PROGRAMMATIC_ACCESS_TOKEN,
7977
token="some PAT",
8078
account="testAccount",
@@ -84,42 +82,3 @@ def test_invalid_pat(wiremock_client: WiremockClient) -> None:
8482
)
8583

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

0 commit comments

Comments
 (0)