diff --git a/lib/fog/aws/requests/iam/update_server_certificate.rb b/lib/fog/aws/requests/iam/update_server_certificate.rb index d7bc6e04e..0b6a9ec2f 100644 --- a/lib/fog/aws/requests/iam/update_server_certificate.rb +++ b/lib/fog/aws/requests/iam/update_server_certificate.rb @@ -32,6 +32,33 @@ module Fog end end + + class Mock + def update_server_certificate(server_certificate_name, options = {}) + new_server_certificate_name = options['NewServerCertificateName'] + if self.data[:server_certificates][new_server_certificate_name] + raise Fog::AWS::IAM::EntityAlreadyExists.new("The Server Certificate with name #{server_certificate_name} already exists.") + end + unless certificate = self.data[:server_certificates].delete(server_certificate_name) + raise Fog::AWS::IAM::NotFound.new("The Server Certificate with name #{server_certificate_name} cannot be found.") + end + + if new_server_certificate_name + certificate['ServerCertificateName'] = new_server_certificate_name + end + + if new_path = options['NewPath'] + certificate['Path'] = new_path + end + + self.data[:server_certificates][certificate['ServerCertificateName']] = certificate + + Excon::Response.new.tap do |response| + response.body = { 'RequestId' => Fog::AWS::Mock.request_id } + response.status = 200 + end + end + end end end end diff --git a/tests/aws/requests/iam/server_certificate_tests.rb b/tests/aws/requests/iam/server_certificate_tests.rb index 6f835863d..aec71b3db 100644 --- a/tests/aws/requests/iam/server_certificate_tests.rb +++ b/tests/aws/requests/iam/server_certificate_tests.rb @@ -13,6 +13,9 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do 'Certificate' => @certificate_format, 'RequestId' => String } + @update_format = { + 'RequestId' => String + } @get_server_certificate_format = { 'Certificate' => @certificate_format, 'RequestId' => String @@ -64,6 +67,35 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do end end + tests('#update_server_certificate') do + public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY + private_key = AWS::IAM::SERVER_CERT_PRIVATE_KEY + key_name = "update-key" + + Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, key_name) + + tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do + other_key_name = "other-key-name" + Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, other_key_name) + + Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name}) + end + + tests('unknown name').raises(Fog::AWS::IAM::NotFound) do + Fog::AWS::IAM.new.update_server_certificate("unknown-key-name", {'NewServerCertificateName' => "other-keyname"}) + end + + tests('format').formats(@update_format) do + Fog::AWS::IAM.new.update_server_certificate(key_name).body + end + + tests('updates name') do + other_key_name = "successful-update-key-name" + Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name}) + returns(true) { Fog::AWS::IAM.new.get_server_certificate(other_key_name).body['Certificate']['ServerCertificateName'] == other_key_name } + end + end + tests('#get_server_certificate').formats(@get_server_certificate_format) do tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")