2011-05-07 14:09:33 -04:00
|
|
|
Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|
|
|
@key_name = 'fog-test'
|
2011-10-03 15:21:09 -07:00
|
|
|
@key_name_chained = 'fog-test-chained'
|
2011-05-07 14:09:33 -04:00
|
|
|
|
2011-05-07 14:59:30 -04:00
|
|
|
@certificate_format = {
|
2011-10-03 15:21:09 -07:00
|
|
|
'Arn' => String,
|
|
|
|
'Path' => String,
|
|
|
|
'ServerCertificateId' => String,
|
|
|
|
'ServerCertificateName' => String,
|
|
|
|
'UploadDate' => Time
|
2011-07-06 14:34:43 -07:00
|
|
|
}
|
2011-05-07 14:09:33 -04:00
|
|
|
@upload_format = {
|
2011-05-07 14:59:30 -04:00
|
|
|
'Certificate' => @certificate_format,
|
2011-05-07 14:09:33 -04:00
|
|
|
'RequestId' => String
|
|
|
|
}
|
2011-10-03 15:21:09 -07:00
|
|
|
@get_server_certificate_format = {
|
|
|
|
'Certificate' => @certificate_format,
|
|
|
|
'RequestId' => String
|
|
|
|
}
|
|
|
|
@list_format = {
|
|
|
|
'Certificates' => [@certificate_format]
|
|
|
|
}
|
2011-07-06 14:34:43 -07:00
|
|
|
|
2011-07-20 16:04:31 -07:00
|
|
|
tests('#upload_server_certificate') do
|
2011-05-07 14:09:33 -04:00
|
|
|
public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY
|
|
|
|
private_key = AWS::IAM::SERVER_CERT_PRIVATE_KEY
|
2012-02-15 14:12:29 -04:00
|
|
|
private_key_pkcs8 = AWS::IAM::SERVER_CERT_PRIVATE_KEY_PKCS8
|
2011-07-20 17:24:34 -07:00
|
|
|
private_key_mismatch = AWS::IAM::SERVER_CERT_PRIVATE_KEY_MISMATCHED
|
2011-07-20 16:04:31 -07:00
|
|
|
|
|
|
|
tests('empty public key').raises(Fog::AWS::IAM::ValidationError) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate('', private_key, @key_name)
|
2011-07-20 16:04:31 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('empty private key').raises(Fog::AWS::IAM::ValidationError) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, '', @key_name)
|
2011-07-20 17:24:34 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('invalid public key').raises(Fog::AWS::IAM::MalformedCertificate) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate('abcde', private_key, @key_name)
|
2011-07-20 17:24:34 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('invalid private key').raises(Fog::AWS::IAM::MalformedCertificate) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, 'abcde', @key_name)
|
2011-07-20 17:24:34 -07:00
|
|
|
end
|
|
|
|
|
2012-02-15 14:12:29 -04:00
|
|
|
tests('non-RSA private key').raises(Fog::AWS::IAM::MalformedCertificate) do
|
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key_pkcs8, @key_name)
|
|
|
|
end
|
|
|
|
|
2011-07-20 17:24:34 -07:00
|
|
|
tests('mismatched private key').raises(Fog::AWS::IAM::KeyPairMismatch) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key_mismatch, @key_name)
|
2011-07-20 16:04:31 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('format').formats(@upload_format) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name).body
|
2011-07-20 16:04:31 -07:00
|
|
|
end
|
2011-07-20 16:18:15 -07:00
|
|
|
|
2011-10-03 15:21:09 -07:00
|
|
|
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
|
|
|
|
|
2011-07-20 16:18:15 -07:00
|
|
|
tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name)
|
2011-07-20 16:18:15 -07:00
|
|
|
end
|
2011-05-07 14:09:33 -04:00
|
|
|
end
|
|
|
|
|
2011-10-03 15:21:09 -07:00
|
|
|
tests('#get_server_certificate').formats(@get_server_certificate_format) do
|
2011-07-18 17:04:40 -07:00
|
|
|
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
2011-07-18 17:04:40 -07:00
|
|
|
end
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.get_server_certificate(@key_name).body
|
2011-07-18 17:04:40 -07:00
|
|
|
end
|
|
|
|
|
2011-05-07 14:59:30 -04:00
|
|
|
tests('#list_server_certificates').formats(@list_format) do
|
2011-09-22 10:21:08 +01:00
|
|
|
result = Fog::AWS::IAM.new.list_server_certificates.body
|
|
|
|
tests('includes key name') do
|
|
|
|
returns(true) { result['Certificates'].any?{|c| c['ServerCertificateName'] == @key_name} }
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#list_server_certificates('path-prefix' => '/'").formats(@list_format) do
|
|
|
|
result = Fog::AWS::IAM.new.list_server_certificates('PathPrefix' => '/').body
|
2011-05-07 14:59:30 -04:00
|
|
|
tests('includes key name') do
|
|
|
|
returns(true) { result['Certificates'].any?{|c| c['ServerCertificateName'] == @key_name} }
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2011-05-07 14:09:33 -04:00
|
|
|
tests('#delete_server_certificate').formats(AWS::IAM::Formats::BASIC) do
|
2011-09-22 10:21:08 +01:00
|
|
|
Fog::AWS::IAM.new.delete_server_certificate(@key_name).body
|
2011-05-07 14:09:33 -04:00
|
|
|
end
|
2011-10-03 15:21:09 -07:00
|
|
|
|
|
|
|
Fog::AWS::IAM.new.delete_server_certificate(@key_name_chained)
|
2011-05-07 14:09:33 -04:00
|
|
|
end
|