From 67326ace4fb6a01f522ee390a6e225c4ce11ccac Mon Sep 17 00:00:00 2001 From: wndhydrnt Date: Sun, 7 Jul 2019 21:45:51 +0200 Subject: [PATCH] Raise exception if a role policy is not found --- moto/iam/models.py | 1 + tests/test_iam/test_iam.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/moto/iam/models.py b/moto/iam/models.py index 4575351489f..f92568df415 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -685,6 +685,7 @@ def get_role_policy(self, role_name, policy_name): for p, d in role.policies.items(): if p == policy_name: return p, d + raise IAMNotFoundException("Policy Document {0} not attached to role {1}".format(policy_name, role_name)) def list_role_policies(self, role_name): role = self.get_role(role_name) diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 3dfc05267af..e7507e2e520 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -311,6 +311,15 @@ def test_put_role_policy(): policy.should.equal("test policy") +@mock_iam +def test_get_role_policy(): + conn = boto3.client('iam', region_name='us-east-1') + conn.create_role( + RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="my-path") + with assert_raises(conn.exceptions.NoSuchEntityException): + conn.get_role_policy(RoleName="my-role", PolicyName="does-not-exist") + + @mock_iam_deprecated() def test_update_assume_role_policy(): conn = boto.connect_iam()