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:
parent
1c4c199f1f
commit
2d0d85a431
3 changed files with 26 additions and 14 deletions
|
@ -18,10 +18,10 @@ module Fog
|
||||||
# ==== See Also
|
# ==== See Also
|
||||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetServerCertificate.html
|
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetServerCertificate.html
|
||||||
#
|
#
|
||||||
def get_server_certificate(server_certificate_name)
|
def get_server_certificate(name)
|
||||||
request({
|
request({
|
||||||
'Action' => 'GetServerCertificate',
|
'Action' => 'GetServerCertificate',
|
||||||
'ServerCertificateName' => server_certificate_name,
|
'ServerCertificateName' => name,
|
||||||
:parser => Fog::Parsers::AWS::IAM::UploadServerCertificate.new
|
:parser => Fog::Parsers::AWS::IAM::UploadServerCertificate.new
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -29,18 +29,16 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def get_server_certificate(server_certificate_name)
|
def get_server_certificate(name)
|
||||||
raise Fog::AWS::IAM::NotFound unless self.data[:server_certificates].key?(server_certificate_name)
|
raise Fog::AWS::IAM::NotFound unless certificate = self.data[:server_certificates][name]
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = {
|
response.body = {
|
||||||
'Certificate' => self.data[:server_certificates][server_certificate_name],
|
'Certificate' => certificate,
|
||||||
'RequestId' => Fog::AWS::Mock.request_id
|
'RequestId' => Fog::AWS::Mock.request_id
|
||||||
}
|
}
|
||||||
|
|
||||||
self.data[:server_certificates]
|
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,7 @@ module Fog
|
||||||
# Validate cert and key
|
# Validate cert and key
|
||||||
begin
|
begin
|
||||||
cert = OpenSSL::X509::Certificate.new(certificate)
|
cert = OpenSSL::X509::Certificate.new(certificate)
|
||||||
|
chain = OpenSSL::X509::Certificate.new(options['CertificateChain']) if options['CertificateChain']
|
||||||
key = OpenSSL::PKey::RSA.new(private_key)
|
key = OpenSSL::PKey::RSA.new(private_key)
|
||||||
rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::RSAError => e
|
rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::RSAError => e
|
||||||
message = if e.is_a?(OpenSSL::X509::CertificateError)
|
message = if e.is_a?(OpenSSL::X509::CertificateError)
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
||||||
@key_name = 'fog-test'
|
@key_name = 'fog-test'
|
||||||
|
@key_name_chained = 'fog-test-chained'
|
||||||
|
|
||||||
@certificate_format = {
|
@certificate_format = {
|
||||||
'Arn' => String,
|
'Arn' => String,
|
||||||
'Path' => String,
|
'Path' => String,
|
||||||
'ServerCertificateId' => String,
|
'ServerCertificateId' => String,
|
||||||
'ServerCertificateName' => String,
|
'ServerCertificateName' => String,
|
||||||
'UploadDate' => Time
|
'UploadDate' => Time
|
||||||
}
|
}
|
||||||
@upload_format = {
|
@upload_format = {
|
||||||
'Certificate' => @certificate_format,
|
'Certificate' => @certificate_format,
|
||||||
'RequestId' => String
|
'RequestId' => String
|
||||||
}
|
}
|
||||||
|
@get_server_certificate_format = {
|
||||||
|
'Certificate' => @certificate_format,
|
||||||
|
'RequestId' => String
|
||||||
|
}
|
||||||
|
@list_format = {
|
||||||
|
'Certificates' => [@certificate_format]
|
||||||
|
}
|
||||||
|
|
||||||
tests('#upload_server_certificate') do
|
tests('#upload_server_certificate') do
|
||||||
public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY
|
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
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name).body
|
||||||
end
|
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
|
tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do
|
||||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name)
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name)
|
||||||
end
|
end
|
||||||
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
|
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
|
||||||
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
||||||
end
|
end
|
||||||
Fog::AWS::IAM.new.get_server_certificate(@key_name).body
|
Fog::AWS::IAM.new.get_server_certificate(@key_name).body
|
||||||
end
|
end
|
||||||
|
|
||||||
@list_format = { 'Certificates' => [@certificate_format] }
|
|
||||||
tests('#list_server_certificates').formats(@list_format) do
|
tests('#list_server_certificates').formats(@list_format) do
|
||||||
result = Fog::AWS::IAM.new.list_server_certificates.body
|
result = Fog::AWS::IAM.new.list_server_certificates.body
|
||||||
tests('includes key name') do
|
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
|
tests('#delete_server_certificate').formats(AWS::IAM::Formats::BASIC) do
|
||||||
Fog::AWS::IAM.new.delete_server_certificate(@key_name).body
|
Fog::AWS::IAM.new.delete_server_certificate(@key_name).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Fog::AWS::IAM.new.delete_server_certificate(@key_name_chained)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue