Skip to content

Commit 9f139a0

Browse files
committed
move change to update_body() and modify unit tests
1 parent bfd1929 commit 9f139a0

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/snowflake/connector/auth/_auth.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ def authenticate(
226226
if session_parameters:
227227
body["data"]["SESSION_PARAMETERS"] = session_parameters
228228

229-
from . import AuthByWorkloadIdentity
230-
231-
if isinstance(auth_instance, AuthByWorkloadIdentity):
232-
body["data"]["IMPERSONATION_PATH_LENGTH"] = len(
233-
auth_instance.impersonation_path or []
234-
)
235-
236229
logger.debug(
237230
"body['data']: %s",
238231
{

src/snowflake/connector/auth/workload_identity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def update_body(self, body: dict[typing.Any, typing.Any]) -> None:
7878
self.attestation
7979
).value
8080
body["data"]["TOKEN"] = self.attestation.credential
81+
body["data"].setdefault("CLIENT_ENVIRONMENT", {})[
82+
"IMPERSONATION_PATH_LENGTH"
83+
] = len(self.impersonation_path or [])
8184

8285
def prepare(
8386
self, *, conn: SnowflakeConnection | None, **kwargs: typing.Any

test/unit/test_auth_workload_identity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_explicit_oidc_valid_inline_token_plumbed_to_api():
136136
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
137137
"PROVIDER": "OIDC",
138138
"TOKEN": dummy_token,
139+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 0},
139140
}
140141

141142

@@ -191,6 +192,7 @@ def test_explicit_aws_encodes_audience_host_signature_to_api(
191192
data = extract_api_data(auth_class)
192193
assert data["AUTHENTICATOR"] == "WORKLOAD_IDENTITY"
193194
assert data["PROVIDER"] == "AWS"
195+
assert data["CLIENT_ENVIRONMENT"]["IMPERSONATION_PATH_LENGTH"] == 0
194196
verify_aws_token(data["TOKEN"], fake_aws_environment.region)
195197

196198

@@ -324,6 +326,7 @@ def test_explicit_gcp_plumbs_token_to_api(
324326
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
325327
"PROVIDER": "GCP",
326328
"TOKEN": fake_gce_metadata_service.token,
329+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 0},
327330
}
328331

329332

@@ -373,6 +376,7 @@ def test_gcp_calls_correct_apis_and_populates_auth_data_for_final_sa(
373376
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
374377
"PROVIDER": "GCP",
375378
"TOKEN": sa3_id_token,
379+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 2},
376380
}
377381

378382

@@ -425,6 +429,7 @@ def test_explicit_azure_plumbs_token_to_api(fake_azure_metadata_service):
425429
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
426430
"PROVIDER": "AZURE",
427431
"TOKEN": fake_azure_metadata_service.token,
432+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 0},
428433
}
429434

430435

0 commit comments

Comments
 (0)