1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|iam] slight cleanup and test with a certificate chain. 🍰

This commit is contained in:
Dylan Egan 2011-10-03 15:21:09 -07:00
parent 1c4c199f1f
commit 2d0d85a431
3 changed files with 26 additions and 14 deletions

View file

@ -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

View file

@ -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)

View file

@ -1,5 +1,6 @@
Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
@key_name = 'fog-test'
@key_name_chained = 'fog-test-chained'
@certificate_format = {
'Arn' => String,
@ -12,6 +13,13 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
'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