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

[aws|iam] raise correct ValidationError when an empty cert or key is used

This commit is contained in:
Blake Gentry 2011-07-20 16:04:31 -07:00
parent cb8004024e
commit bef207f4ae
3 changed files with 19 additions and 2 deletions

View file

@ -6,6 +6,7 @@ module Fog
class KeyPairMismatch < Fog::AWS::IAM::Error; end
class LimitExceeded < Fog::AWS::IAM::Error; end
class MalformedCertificate < Fog::AWS::IAM::Error; end
class ValidationError < Fog::AWS::IAM::Error; end
requires :aws_access_key_id, :aws_secret_access_key
recognizes :host, :path, :port, :scheme, :persistent
@ -163,6 +164,8 @@ module Fog
raise Fog::AWS::IAM::LimitExceeded.slurp(error, match[2])
when 'MalformedCertificate'
raise Fog::AWS::IAM::MalformedCertificate.slurp(error, match[2])
when 'ValidationError'
raise Fog::AWS::IAM::ValidationError.slurp(error, match[2])
else
raise Fog::AWS::IAM::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1]
raise

View file

@ -44,6 +44,9 @@ module Fog
class Mock
def upload_server_certificate(certificate, private_key, name, options = {})
if certificate.nil? || certificate.empty? || private_key.nil? || private_key.empty?
raise Fog::AWS::IAM::ValidationError.new
end
response = Excon::Response.new
if self.data[:server_certificates][name]

View file

@ -13,10 +13,21 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
'RequestId' => String
}
tests('#upload_server_certificate').formats(@upload_format) do
tests('#upload_server_certificate') do
public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY
private_key = AWS::IAM::SERVER_CERT_PRIVATE_KEY
AWS[:iam].upload_server_certificate(public_key, private_key, @key_name).body
tests('empty public key').raises(Fog::AWS::IAM::ValidationError) do
AWS[:iam].upload_server_certificate('', private_key, @key_name).body
end
tests('empty private key').raises(Fog::AWS::IAM::ValidationError) do
AWS[:iam].upload_server_certificate(public_key, '', @key_name).body
end
tests('format').formats(@upload_format) do
AWS[:iam].upload_server_certificate(public_key, private_key, @key_name).body
end
end
tests('#get_server_certificate').formats(@upload_format) do