|
14 | 14 | HTTPError,
|
15 | 15 | Timeout,
|
16 | 16 | )
|
17 |
| -from snowflake.connector.wif_util import AttestationProvider |
| 17 | +from snowflake.connector.wif_util import ( |
| 18 | + AZURE_ISSUER_PREFIXES, |
| 19 | + AttestationProvider, |
| 20 | + get_aws_partition, |
| 21 | + get_aws_sts_hostname, |
| 22 | +) |
18 | 23 |
|
19 | 24 | from ..csp_helpers import FakeAwsEnvironment, FakeGceMetadataService, gen_dummy_id_token
|
20 | 25 |
|
@@ -154,6 +159,73 @@ def test_explicit_aws_generates_unique_assertion_content(
|
154 | 159 | )
|
155 | 160 |
|
156 | 161 |
|
| 162 | +@pytest.mark.parametrize( |
| 163 | + "arn, expected_partition", |
| 164 | + [ |
| 165 | + ("arn:aws:iam::123456789012:role/MyTestRole", "aws"), |
| 166 | + ( |
| 167 | + "arn:aws-cn:ec2:cn-north-1:987654321098:instance/i-1234567890abcdef0", |
| 168 | + "aws-cn", |
| 169 | + ), |
| 170 | + ("arn:aws-us-gov:s3:::my-gov-bucket", "aws-us-gov"), |
| 171 | + ("arn:aws:s3:::my-bucket/my/key", "aws"), |
| 172 | + ("arn:aws:lambda:us-east-1:123456789012:function:my-function", "aws"), |
| 173 | + ("arn:aws:sns:eu-west-1:111122223333:my-topic", "aws"), |
| 174 | + # Edge cases / Invalid inputs |
| 175 | + ("invalid-arn", None), |
| 176 | + ("arn::service:region:account:resource", None), # Missing partition |
| 177 | + ("arn:aws:iam:", "aws"), # Incomplete ARN, but partition is present |
| 178 | + ("", None), # Empty string |
| 179 | + (None, None), # None input |
| 180 | + (123, None), # Non-string input |
| 181 | + ], |
| 182 | +) |
| 183 | +def test_get_aws_partition_valid_and_invalid_arns(arn, expected_partition): |
| 184 | + assert get_aws_partition(arn) == expected_partition |
| 185 | + |
| 186 | + |
| 187 | +@pytest.mark.parametrize( |
| 188 | + "region, partition, expected_hostname", |
| 189 | + [ |
| 190 | + # AWS partition |
| 191 | + ("us-east-1", "aws", "sts.us-east-1.amazonaws.com"), |
| 192 | + ("eu-west-2", "aws", "sts.eu-west-2.amazonaws.com"), |
| 193 | + ("ap-southeast-1", "aws", "sts.ap-southeast-1.amazonaws.com"), |
| 194 | + ( |
| 195 | + "us-east-1", |
| 196 | + "aws", |
| 197 | + "sts.us-east-1.amazonaws.com", |
| 198 | + ), # Redundant but good for coverage |
| 199 | + # AWS China partition |
| 200 | + ("cn-north-1", "aws-cn", "sts.cn-north-1.amazonaws.com.cn"), |
| 201 | + ("cn-northwest-1", "aws-cn", "sts.cn-northwest-1.amazonaws.com.cn"), |
| 202 | + ("", "aws-cn", None), # No global endpoint for 'aws-cn' without region |
| 203 | + # AWS GovCloud partition |
| 204 | + ("us-gov-west-1", "aws-us-gov", "sts.us-gov-west-1.amazonaws.com"), |
| 205 | + ("us-gov-east-1", "aws-us-gov", "sts.us-gov-east-1.amazonaws.com"), |
| 206 | + ("", "aws-us-gov", None), # No global endpoint for 'aws-us-gov' without region |
| 207 | + # Invalid/Edge cases |
| 208 | + ("us-east-1", "unknown-partition", None), # Unknown partition |
| 209 | + ("some-region", "invalid-partition", None), # Invalid partition |
| 210 | + (None, "aws", None), # None region |
| 211 | + ("us-east-1", None, None), # None partition |
| 212 | + (123, "aws", None), # Non-string region |
| 213 | + ("us-east-1", 456, None), # Non-string partition |
| 214 | + ("", "", None), # Empty region and partition |
| 215 | + ("us-east-1", "", None), # Empty partition |
| 216 | + ( |
| 217 | + "invalid-region", |
| 218 | + "aws", |
| 219 | + "sts.invalid-region.amazonaws.com", |
| 220 | + ), # Valid format, invalid region name |
| 221 | + ], |
| 222 | +) |
| 223 | +def test_get_aws_sts_hostname_valid_and_invalid_inputs( |
| 224 | + region, partition, expected_hostname |
| 225 | +): |
| 226 | + assert get_aws_sts_hostname(region, partition) == expected_hostname |
| 227 | + |
| 228 | + |
157 | 229 | # -- GCP Tests --
|
158 | 230 |
|
159 | 231 |
|
@@ -312,6 +384,22 @@ def test_explicit_azure_uses_explicit_entra_resource(fake_azure_metadata_service
|
312 | 384 | assert parsed["aud"] == "api://non-standard"
|
313 | 385 |
|
314 | 386 |
|
| 387 | +@pytest.mark.parametrize( |
| 388 | + "issuer", |
| 389 | + [ |
| 390 | + "https://sts.windows.net/067802cd-8f92-4c7c-bceb-ea8f15d31cc5", |
| 391 | + "https://sts.chinacloudapi.cn/067802cd-8f92-4c7c-bceb-ea8f15d31cc5", |
| 392 | + "https://login.microsoftonline.com/067802cd-8f92-4c7c-bceb-ea8f15d31cc5/v2.0", |
| 393 | + "https://login.microsoftonline.us/067802cd-8f92-4c7c-bceb-ea8f15d31cc5/v2.0", |
| 394 | + "https://login.partner.microsoftonline.cn/067802cd-8f92-4c7c-bceb-ea8f15d31cc5/v2.0", |
| 395 | + ], |
| 396 | +) |
| 397 | +def test_azure_issuer_prefixes(issuer): |
| 398 | + assert any( |
| 399 | + issuer.startswith(issuer_prefix) for issuer_prefix in AZURE_ISSUER_PREFIXES |
| 400 | + ) |
| 401 | + |
| 402 | + |
315 | 403 | # -- Auto-detect Tests --
|
316 | 404 |
|
317 | 405 |
|
|
0 commit comments