Skip to content

Commit 31f6d3c

Browse files
committed
move change to update_body() and modify unit tests
1 parent 890bb6f commit 31f6d3c

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

@@ -308,6 +310,7 @@ def test_explicit_gcp_plumbs_token_to_api(
308310
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
309311
"PROVIDER": "GCP",
310312
"TOKEN": fake_gce_metadata_service.token,
313+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 0},
311314
}
312315

313316

@@ -357,6 +360,7 @@ def test_gcp_calls_correct_apis_and_populates_auth_data_for_final_sa(
357360
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
358361
"PROVIDER": "GCP",
359362
"TOKEN": sa3_id_token,
363+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 2},
360364
}
361365

362366

@@ -409,6 +413,7 @@ def test_explicit_azure_plumbs_token_to_api(fake_azure_metadata_service):
409413
"AUTHENTICATOR": "WORKLOAD_IDENTITY",
410414
"PROVIDER": "AZURE",
411415
"TOKEN": fake_azure_metadata_service.token,
416+
"CLIENT_ENVIRONMENT": {"IMPERSONATION_PATH_LENGTH": 0},
412417
}
413418

414419

0 commit comments

Comments
 (0)