|
17 | 17 | from pytest_shell import fs |
18 | 18 |
|
19 | 19 | from opentaskpy import exceptions |
| 20 | +from opentaskpy.addons.aws.remotehandlers.creds import get_aws_client |
20 | 21 | from opentaskpy.addons.aws.remotehandlers.s3 import S3Transfer |
21 | 22 | from tests.fixtures.localstack import * |
22 | 23 |
|
@@ -611,6 +612,66 @@ def fake_get_aws_client( |
611 | 612 | assert handler.s3_client is None |
612 | 613 |
|
613 | 614 |
|
| 615 | +def test_get_aws_client_passes_region_to_sts(monkeypatch): |
| 616 | + captured = {} |
| 617 | + |
| 618 | + class DummySTSClient: |
| 619 | + def assume_role(self, **kwargs): |
| 620 | + captured["assume_role_kwargs"] = kwargs |
| 621 | + return { |
| 622 | + "Credentials": { |
| 623 | + "AccessKeyId": "assumed-key", |
| 624 | + "SecretAccessKey": "assumed-secret", |
| 625 | + "SessionToken": "assumed-token", |
| 626 | + } |
| 627 | + } |
| 628 | + |
| 629 | + class DummySession: |
| 630 | + def __init__(self, **kwargs): |
| 631 | + captured["session_kwargs"] = kwargs |
| 632 | + |
| 633 | + def client(self, client_type, **kwargs): |
| 634 | + captured["session_client_type"] = client_type |
| 635 | + captured["session_client_kwargs"] = kwargs |
| 636 | + return object() |
| 637 | + |
| 638 | + def fake_boto3_client(service_name, **kwargs): |
| 639 | + captured["sts_service_name"] = service_name |
| 640 | + captured["sts_client_kwargs"] = kwargs |
| 641 | + return DummySTSClient() |
| 642 | + |
| 643 | + monkeypatch.setenv("AWS_ENDPOINT_URL", "http://floci.test") |
| 644 | + monkeypatch.setattr( |
| 645 | + "opentaskpy.addons.aws.remotehandlers.creds.boto3.client", |
| 646 | + fake_boto3_client, |
| 647 | + ) |
| 648 | + monkeypatch.setattr( |
| 649 | + "opentaskpy.addons.aws.remotehandlers.creds.boto3.session.Session", |
| 650 | + DummySession, |
| 651 | + ) |
| 652 | + |
| 653 | + result = get_aws_client( |
| 654 | + "s3", |
| 655 | + { |
| 656 | + "AccessKeyId": "test-key", |
| 657 | + "SecretAccessKey": "test-secret", |
| 658 | + "region_name": "eu-west-1", |
| 659 | + }, |
| 660 | + assume_role_arn="arn:aws:iam::012345678900:role/dummy-role", |
| 661 | + ) |
| 662 | + |
| 663 | + assert captured["sts_service_name"] == "sts" |
| 664 | + assert captured["sts_client_kwargs"]["endpoint_url"] == "http://floci.test" |
| 665 | + assert captured["sts_client_kwargs"]["region_name"] == "eu-west-1" |
| 666 | + assert captured["assume_role_kwargs"]["RoleArn"] == ( |
| 667 | + "arn:aws:iam::012345678900:role/dummy-role" |
| 668 | + ) |
| 669 | + assert captured["session_kwargs"]["aws_access_key_id"] == "assumed-key" |
| 670 | + assert captured["session_client_type"] == "s3" |
| 671 | + assert captured["session_client_kwargs"]["endpoint_url"] == "http://floci.test" |
| 672 | + assert result["temporary_creds"]["AccessKeyId"] == "assumed-key" |
| 673 | + |
| 674 | + |
614 | 675 | def test_s3_file_watch(s3_client, setup_bucket, tmp_path): |
615 | 676 | transfer_obj = transfer.Transfer( |
616 | 677 | None, "s3-file-watch", s3_file_watch_task_definition |
|
0 commit comments