mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] implement correct path behaviour in mocking.
This commit is contained in:
parent
ff7fccfa6f
commit
5f438e73dd
3 changed files with 24 additions and 14 deletions
|
@ -40,10 +40,12 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def list_server_certificates(options = {})
|
||||
certificates = self.data[:server_certificates].values
|
||||
certificates = certificates.select { |certificate| certificate['Path'] =~ Regexp.new("^#{options['PathPrefix']}") } if options['PathPrefix']
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'Certificates' => self.data[:server_certificates].values
|
||||
'Certificates' => certificates
|
||||
}
|
||||
|
||||
response
|
||||
|
|
|
@ -70,9 +70,9 @@ module Fog
|
|||
raise Fog::AWS::IAM::EntityAlreadyExists.new
|
||||
else
|
||||
response.status = 200
|
||||
path = "server-certificates/#{name}"
|
||||
path = options['path'] || "/"
|
||||
data = {
|
||||
'Arn' => Fog::AWS::Mock.arn('iam', self.data[:owner_id], path),
|
||||
'Arn' => Fog::AWS::Mock.arn('iam', self.data[:owner_id], "server-certificate/#{name}"),
|
||||
'Path' => path,
|
||||
'ServerCertificateId' => Fog::AWS::IAM::Mock.server_certificate_id,
|
||||
'ServerCertificateName' => name,
|
||||
|
|
|
@ -19,44 +19,52 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
private_key_mismatch = AWS::IAM::SERVER_CERT_PRIVATE_KEY_MISMATCHED
|
||||
|
||||
tests('empty public key').raises(Fog::AWS::IAM::ValidationError) do
|
||||
Fog::AWS[:iam].upload_server_certificate('', private_key, @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate('', private_key, @key_name)
|
||||
end
|
||||
|
||||
tests('empty private key').raises(Fog::AWS::IAM::ValidationError) do
|
||||
Fog::AWS[:iam].upload_server_certificate(public_key, '', @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, '', @key_name)
|
||||
end
|
||||
|
||||
tests('invalid public key').raises(Fog::AWS::IAM::MalformedCertificate) do
|
||||
Fog::AWS[:iam].upload_server_certificate('abcde', private_key, @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate('abcde', private_key, @key_name)
|
||||
end
|
||||
|
||||
tests('invalid private key').raises(Fog::AWS::IAM::MalformedCertificate) do
|
||||
Fog::AWS[:iam].upload_server_certificate(public_key, 'abcde', @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, 'abcde', @key_name)
|
||||
end
|
||||
|
||||
tests('mismatched private key').raises(Fog::AWS::IAM::KeyPairMismatch) do
|
||||
Fog::AWS[:iam].upload_server_certificate(public_key, private_key_mismatch, @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key_mismatch, @key_name)
|
||||
end
|
||||
|
||||
tests('format').formats(@upload_format) do
|
||||
Fog::AWS[:iam].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
|
||||
|
||||
tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do
|
||||
Fog::AWS[:iam].upload_server_certificate(public_key, private_key, @key_name)
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, @key_name)
|
||||
end
|
||||
end
|
||||
|
||||
tests('#get_server_certificate').formats(@upload_format) do
|
||||
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
|
||||
Fog::AWS[:iam].get_server_certificate("#{@key_name}fake")
|
||||
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
||||
end
|
||||
Fog::AWS[:iam].get_server_certificate(@key_name).body
|
||||
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].list_server_certificates.body
|
||||
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
|
||||
tests('includes key name') do
|
||||
returns(true) { result['Certificates'].any?{|c| c['ServerCertificateName'] == @key_name} }
|
||||
end
|
||||
|
@ -64,6 +72,6 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
end
|
||||
|
||||
tests('#delete_server_certificate').formats(AWS::IAM::Formats::BASIC) do
|
||||
Fog::AWS[:iam].delete_server_certificate(@key_name).body
|
||||
Fog::AWS::IAM.new.delete_server_certificate(@key_name).body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue