diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 184ee1dc2..1b9896661 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -3286,7 +3286,7 @@ - [X] deactivate_mfa_device - [X] delete_access_key - [X] delete_account_alias -- [ ] delete_account_password_policy +- [X] delete_account_password_policy - [ ] delete_group - [ ] delete_group_policy - [ ] delete_instance_profile diff --git a/moto/iam/models.py b/moto/iam/models.py index 4a4881bf0..c032e1e24 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -1678,5 +1678,11 @@ class IAMBackend(BaseBackend): return self.account_password_policy + def delete_account_password_policy(self): + if not self.account_password_policy: + raise NoSuchEntity('The account policy with name PasswordPolicy cannot be found.') + + self.account_password_policy = None + iam_backend = IAMBackend() diff --git a/moto/iam/responses.py b/moto/iam/responses.py index d34e7f599..27fbea990 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -863,6 +863,12 @@ class IamResponse(BaseResponse): template = self.response_template(GET_ACCOUNT_PASSWORD_POLICY_TEMPLATE) return template.render(password_policy=account_password_policy) + def delete_account_password_policy(self): + iam_backend.delete_account_password_policy() + + template = self.response_template(DELETE_ACCOUNT_PASSWORD_POLICY_TEMPLATE) + return template.render() + LIST_ENTITIES_FOR_POLICY_TEMPLATE = """ @@ -2229,3 +2235,10 @@ GET_ACCOUNT_PASSWORD_POLICY_TEMPLATE = """7a62c49f-347e-4fc4-9331-6e8eEXAMPLE """ + + +DELETE_ACCOUNT_PASSWORD_POLICY_TEMPLATE = """ + + 7a62c49f-347e-4fc4-9331-6e8eEXAMPLE + +""" diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 943baa204..a05ec8624 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -2274,3 +2274,30 @@ def test_get_account_password_policy_errors(): ClientError, 'The Password Policy with domain name 123456789012 cannot be found.' ) + + +@mock_iam +def test_delete_account_password_policy(): + client = boto3.client('iam', region_name='us-east-1') + client.update_account_password_policy() + + response = client.get_account_password_policy() + + response.should.have.key('PasswordPolicy').which.should.be.a(dict) + + client.delete_account_password_policy() + + client.get_account_password_policy.when.called_with().should.throw( + ClientError, + 'The Password Policy with domain name 123456789012 cannot be found.' + ) + + +@mock_iam +def test_delete_account_password_policy_errors(): + client = boto3.client('iam', region_name='us-east-1') + + client.delete_account_password_policy.when.called_with().should.throw( + ClientError, + 'The account policy with name PasswordPolicy cannot be found.' + )