diff --git a/lib/fog/aws/requests/iam/get_server_certificate.rb b/lib/fog/aws/requests/iam/get_server_certificate.rb index a6b0be204..8a0766a83 100644 --- a/lib/fog/aws/requests/iam/get_server_certificate.rb +++ b/lib/fog/aws/requests/iam/get_server_certificate.rb @@ -18,10 +18,10 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetServerCertificate.html # - def get_server_certificate(server_certificate_name) + def get_server_certificate(name) request({ 'Action' => 'GetServerCertificate', - 'ServerCertificateName' => server_certificate_name, + 'ServerCertificateName' => name, :parser => Fog::Parsers::AWS::IAM::UploadServerCertificate.new }) end @@ -29,18 +29,16 @@ module Fog end class Mock - def get_server_certificate(server_certificate_name) - raise Fog::AWS::IAM::NotFound unless self.data[:server_certificates].key?(server_certificate_name) + def get_server_certificate(name) + raise Fog::AWS::IAM::NotFound unless certificate = self.data[:server_certificates][name] response = Excon::Response.new response.status = 200 response.body = { - 'Certificate' => self.data[:server_certificates][server_certificate_name], + 'Certificate' => certificate, 'RequestId' => Fog::AWS::Mock.request_id } - self.data[:server_certificates] - response end end diff --git a/lib/fog/aws/requests/iam/upload_server_certificate.rb b/lib/fog/aws/requests/iam/upload_server_certificate.rb index 71d202f54..8357edbd4 100644 --- a/lib/fog/aws/requests/iam/upload_server_certificate.rb +++ b/lib/fog/aws/requests/iam/upload_server_certificate.rb @@ -52,6 +52,7 @@ module Fog # Validate cert and key begin cert = OpenSSL::X509::Certificate.new(certificate) + chain = OpenSSL::X509::Certificate.new(options['CertificateChain']) if options['CertificateChain'] key = OpenSSL::PKey::RSA.new(private_key) rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::RSAError => e message = if e.is_a?(OpenSSL::X509::CertificateError) diff --git a/tests/aws/requests/iam/server_certificate_tests.rb b/tests/aws/requests/iam/server_certificate_tests.rb index 560bcb7ce..229696f67 100644 --- a/tests/aws/requests/iam/server_certificate_tests.rb +++ b/tests/aws/requests/iam/server_certificate_tests.rb @@ -1,17 +1,25 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do @key_name = 'fog-test' + @key_name_chained = 'fog-test-chained' @certificate_format = { - 'Arn' => String, - 'Path' => String, - 'ServerCertificateId' => String, - 'ServerCertificateName' => String, - 'UploadDate' => Time + 'Arn' => String, + 'Path' => String, + 'ServerCertificateId' => String, + 'ServerCertificateName' => String, + 'UploadDate' => Time } @upload_format = { 'Certificate' => @certificate_format, 'RequestId' => String } + @get_server_certificate_format = { + 'Certificate' => @certificate_format, + 'RequestId' => String + } + @list_format = { + 'Certificates' => [@certificate_format] + } tests('#upload_server_certificate') do public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY @@ -42,19 +50,22 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name).body end + tests('format with chain').formats(@upload_format) do + Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name_chained, { 'CertificateChain' => public_key }).body + end + tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name) end end - tests('#get_server_certificate').formats(@upload_format) do + 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") end Fog::AWS::IAM.new.get_server_certificate(@key_name).body end - @list_format = { 'Certificates' => [@certificate_format] } tests('#list_server_certificates').formats(@list_format) do result = Fog::AWS::IAM.new.list_server_certificates.body tests('includes key name') do @@ -74,4 +85,6 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do tests('#delete_server_certificate').formats(AWS::IAM::Formats::BASIC) do Fog::AWS::IAM.new.delete_server_certificate(@key_name).body end + + Fog::AWS::IAM.new.delete_server_certificate(@key_name_chained) end