From bef207f4ae1169504fb8234ed417d141d008ed2e Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Wed, 20 Jul 2011 16:04:31 -0700 Subject: [PATCH] [aws|iam] raise correct ValidationError when an empty cert or key is used --- lib/fog/aws/iam.rb | 3 +++ .../aws/requests/iam/upload_server_certificate.rb | 3 +++ .../aws/requests/iam/server_certificate_tests.rb | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 77f39f7f9..e39ad7c3a 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -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 diff --git a/lib/fog/aws/requests/iam/upload_server_certificate.rb b/lib/fog/aws/requests/iam/upload_server_certificate.rb index f592feab7..67bd05024 100644 --- a/lib/fog/aws/requests/iam/upload_server_certificate.rb +++ b/lib/fog/aws/requests/iam/upload_server_certificate.rb @@ -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] diff --git a/tests/aws/requests/iam/server_certificate_tests.rb b/tests/aws/requests/iam/server_certificate_tests.rb index 894bed287..34880338f 100644 --- a/tests/aws/requests/iam/server_certificate_tests.rb +++ b/tests/aws/requests/iam/server_certificate_tests.rb @@ -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