|
12 | 12 | ensure_default_product, fill_standard_tags, extract_subnets,
|
13 | 13 | extract_load_balancer_name, extract_public_ips,
|
14 | 14 | extract_image_id, extract_security_group_ids, extract_instance_types,
|
15 |
| - extract_instance_profile, patch_cross_stack_policy) |
| 15 | + extract_instance_profile) |
16 | 16 |
|
17 | 17 |
|
18 | 18 | def test_component_elastigroup_defaults(monkeypatch):
|
@@ -799,142 +799,6 @@ def test_extract_instance_profile(monkeypatch):
|
799 | 799 | assert test_case["expected_config"] == got
|
800 | 800 |
|
801 | 801 |
|
802 |
| -def test_patch_cross_stack_policy(monkeypatch): |
803 |
| - test_cases = [ |
804 |
| - { # No instance profile in definition |
805 |
| - "elastigroup_config": {"compute": {"launchSpecification": {}}}, |
806 |
| - "definition": {}, |
807 |
| - "expected_output": {} |
808 |
| - }, |
809 |
| - { # Instance profile definition references a managed instance profile |
810 |
| - "elastigroup_config": {"compute": {"launchSpecification": {"iamRole": { |
811 |
| - "arn": "arn:aws:iam::12345667:instance-profile/foo"}}}}, |
812 |
| - "definition": {}, |
813 |
| - "expected_output": {} |
814 |
| - }, |
815 |
| - { # Instance profile Role definition references a managed role |
816 |
| - "elastigroup_config": {"compute": {"launchSpecification": {"iamRole": { |
817 |
| - "name": {"Ref": "my-instance-profile"}}}}}, |
818 |
| - "definition": {"Resources": {"my-instance-profile": { |
819 |
| - "Type": "AWS::IAM::InstanceProfile", |
820 |
| - "Properties": {"Path": "/", "Roles": ['a-managed-role']}}}}, |
821 |
| - "expected_output": {"Resources": {"my-instance-profile": { |
822 |
| - "Type": "AWS::IAM::InstanceProfile", |
823 |
| - "Properties": {"Path": "/", "Roles": ['a-managed-role']}}}} |
824 |
| - }, |
825 |
| - { # Policy not in policies list of role |
826 |
| - "elastigroup_config": {"compute": {"launchSpecification": {"iamRole": { |
827 |
| - "name": {"Ref": "my-instance-profile1"}}}}}, |
828 |
| - "definition": {"Resources": { |
829 |
| - "my-instance-profile1": { |
830 |
| - "Type": "AWS::IAM::InstanceProfile", |
831 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role1"}]} |
832 |
| - }, |
833 |
| - "my-role1": { |
834 |
| - "Type": "AWS::IAM::Role", |
835 |
| - "Properties": {} |
836 |
| - } |
837 |
| - }}, |
838 |
| - "expected_output": {"Resources": { |
839 |
| - "my-instance-profile1": { |
840 |
| - "Type": "AWS::IAM::InstanceProfile", |
841 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role1"}]} |
842 |
| - }, |
843 |
| - "my-role1": { |
844 |
| - "Type": "AWS::IAM::Role", |
845 |
| - "Properties": {"ManagedPolicyArns": ['arn:aws:iam::aws:policy/zed']} |
846 |
| - } |
847 |
| - }} |
848 |
| - }, |
849 |
| - { # Policy already in policies list of role |
850 |
| - "elastigroup_config": {"compute": {"launchSpecification": {"iamRole": { |
851 |
| - "name": {"Ref": "my-instance-profile2"}}}}}, |
852 |
| - "definition": {"Resources": { |
853 |
| - "my-instance-profile2": { |
854 |
| - "Type": "AWS::IAM::InstanceProfile", |
855 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role2"}]} |
856 |
| - }, |
857 |
| - "my-role2": { |
858 |
| - "Type": "AWS::IAM::Role", |
859 |
| - "Properties": {"ManagedPolicyArns": ['arn:aws:iam::aws:policy/zed']} |
860 |
| - } |
861 |
| - }}, |
862 |
| - "expected_output": {"Resources": { |
863 |
| - "my-instance-profile2": { |
864 |
| - "Type": "AWS::IAM::InstanceProfile", |
865 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role2"}]} |
866 |
| - }, |
867 |
| - "my-role2": { |
868 |
| - "Type": "AWS::IAM::Role", |
869 |
| - "Properties": {"ManagedPolicyArns": ['arn:aws:iam::aws:policy/zed']} |
870 |
| - } |
871 |
| - }} |
872 |
| - } |
873 |
| - ] |
874 |
| - |
875 |
| - cross_stack_policy_mock = MagicMock() |
876 |
| - cross_stack_policy_mock.return_value = {"PolicyName": "zed", "Arn": "arn:aws:iam::aws:policy/zed"} |
877 |
| - monkeypatch.setattr("senza.manaus.iam.find_or_create_policy", cross_stack_policy_mock) |
878 |
| - |
879 |
| - for test_case in test_cases: |
880 |
| - definition = test_case["definition"] |
881 |
| - patch_cross_stack_policy(definition, test_case["elastigroup_config"]) |
882 |
| - |
883 |
| - assert definition == test_case["expected_output"] |
884 |
| - |
885 |
| - |
886 |
| -def test_patch_cross_stack_policy_errors(): |
887 |
| - # Error case 1 :: Instance profile not in Resources |
888 |
| - with pytest.raises(click.UsageError): |
889 |
| - elastigroup_config = {"compute": {"launchSpecification": {"iamRole": { |
890 |
| - "name": {"Ref": "my-instance-profile"}}}}} |
891 |
| - definition = {"Resources": {}} |
892 |
| - |
893 |
| - patch_cross_stack_policy(definition, elastigroup_config) |
894 |
| - |
895 |
| - # Error case 2 :: Instance profile not of type AWS::IAM::InstanceProfile |
896 |
| - with pytest.raises(click.UsageError): |
897 |
| - elastigroup_config = {"compute": {"launchSpecification": {"iamRole": { |
898 |
| - "name": {"Ref": "my-instance-profile"}}}}} |
899 |
| - definition = {"Resources": { |
900 |
| - "my-instance-profile": { |
901 |
| - "Type": "AWS::IAM::SomeOtherResource", |
902 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role"}]} |
903 |
| - }}} |
904 |
| - |
905 |
| - patch_cross_stack_policy(definition, elastigroup_config) |
906 |
| - |
907 |
| - # Error case 3 :: Instance profile Role not in Resources |
908 |
| - with pytest.raises(click.UsageError): |
909 |
| - elastigroup_config = {"compute": {"launchSpecification": {"iamRole": { |
910 |
| - "name": {"Ref": "my-instance-profile"}}}}} |
911 |
| - definition = {"Resources": { |
912 |
| - "my-instance-profile": { |
913 |
| - "Type": "AWS::IAM::InstanceProfile", |
914 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role"}]} |
915 |
| - } |
916 |
| - }} |
917 |
| - |
918 |
| - patch_cross_stack_policy(definition, elastigroup_config) |
919 |
| - |
920 |
| - # Error case 4 :: Instance profile Role not of type AWS::IAM::Role |
921 |
| - with pytest.raises(click.UsageError): |
922 |
| - elastigroup_config = {"compute": {"launchSpecification": {"iamRole": { |
923 |
| - "name": {"Ref": "my-instance-profile"}}}}} |
924 |
| - definition = {"Resources": { |
925 |
| - "my-instance-profile": { |
926 |
| - "Type": "AWS::IAM::InstanceProfile", |
927 |
| - "Properties": {"Path": "/", "Roles": [{"Ref": "my-role"}]} |
928 |
| - }, |
929 |
| - "my-role": { |
930 |
| - "Type": "AWS::IAM::SomeOtherResource", |
931 |
| - "Properties": {"ManagedPolicyArns": ['arn:aws:iam::aws:policy/zed']} |
932 |
| - } |
933 |
| - }} |
934 |
| - |
935 |
| - patch_cross_stack_policy(definition, elastigroup_config) |
936 |
| - |
937 |
| - |
938 | 802 | def test_multiple_elastigroups(monkeypatch):
|
939 | 803 | config1 = {
|
940 | 804 | "Name": "eg1",
|
|
0 commit comments