diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 6be7375db..b3caf5be3 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -1906,7 +1906,7 @@ - [X] delete_role - [X] delete_role_policy - [ ] delete_saml_provider -- [ ] delete_server_certificate +- [X] delete_server_certificate - [ ] delete_service_linked_role - [ ] delete_service_specific_credential - [ ] delete_signing_certificate diff --git a/moto/iam/models.py b/moto/iam/models.py index 22bdfdb4b..7839d3a74 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -663,6 +663,20 @@ class IAMBackend(BaseBackend): "The Server Certificate with name {0} cannot be " "found.".format(name)) + def delete_server_certificate(self, name): + cert_id = None + for key, cert in self.certificates.items(): + if name == cert.cert_name: + cert_id = key + break + + if cert_id is None: + raise IAMNotFoundException( + "The Server Certificate with name {0} cannot be " + "found.".format(name)) + + self.certificates.pop(cert_id, None) + def create_group(self, group_name, path='/'): if group_name in self.groups: raise IAMConflictException( diff --git a/moto/iam/responses.py b/moto/iam/responses.py index df32732a0..0e11c09d5 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -271,6 +271,12 @@ class IamResponse(BaseResponse): template = self.response_template(GET_SERVER_CERTIFICATE_TEMPLATE) return template.render(certificate=cert) + def delete_server_certificate(self): + cert_name = self._get_param('ServerCertificateName') + iam_backend.delete_server_certificate(cert_name) + template = self.response_template(GENERIC_EMPTY_TEMPLATE) + return template.render(name="DeleteServerCertificate") + def create_group(self): group_name = self._get_param('GroupName') path = self._get_param('Path') diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index a80768101..d50f6999e 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -58,6 +58,19 @@ def test_upload_server_cert(): "arn:aws:iam::123456789012:server-certificate/certname") +@mock_iam_deprecated() +def test_delete_server_cert(): + conn = boto.connect_iam() + + conn.upload_server_cert("certname", "certbody", "privatekey") + conn.get_server_certificate("certname") + conn.delete_server_cert("certname") + with assert_raises(BotoServerError): + conn.get_server_certificate("certname") + with assert_raises(BotoServerError): + conn.delete_server_cert("certname") + + @mock_iam_deprecated() @raises(BotoServerError) def test_get_role__should_throw__when_role_does_not_exist():