mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws] mock update_server_certificate
This commit is contained in:
parent
13655f1056
commit
426037e87d
2 changed files with 59 additions and 0 deletions
|
@ -32,6 +32,33 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_server_certificate(server_certificate_name, options = {})
|
||||
new_server_certificate_name = options['NewServerCertificateName']
|
||||
if self.data[:server_certificates][new_server_certificate_name]
|
||||
raise Fog::AWS::IAM::EntityAlreadyExists.new("The Server Certificate with name #{server_certificate_name} already exists.")
|
||||
end
|
||||
unless certificate = self.data[:server_certificates].delete(server_certificate_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The Server Certificate with name #{server_certificate_name} cannot be found.")
|
||||
end
|
||||
|
||||
if new_server_certificate_name
|
||||
certificate['ServerCertificateName'] = new_server_certificate_name
|
||||
end
|
||||
|
||||
if new_path = options['NewPath']
|
||||
certificate['Path'] = new_path
|
||||
end
|
||||
|
||||
self.data[:server_certificates][certificate['ServerCertificateName']] = certificate
|
||||
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,9 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
'Certificate' => @certificate_format,
|
||||
'RequestId' => String
|
||||
}
|
||||
@update_format = {
|
||||
'RequestId' => String
|
||||
}
|
||||
@get_server_certificate_format = {
|
||||
'Certificate' => @certificate_format,
|
||||
'RequestId' => String
|
||||
|
@ -64,6 +67,35 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
end
|
||||
end
|
||||
|
||||
tests('#update_server_certificate') do
|
||||
public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY
|
||||
private_key = AWS::IAM::SERVER_CERT_PRIVATE_KEY
|
||||
key_name = "update-key"
|
||||
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, key_name)
|
||||
|
||||
tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do
|
||||
other_key_name = "other-key-name"
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, other_key_name)
|
||||
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name})
|
||||
end
|
||||
|
||||
tests('unknown name').raises(Fog::AWS::IAM::NotFound) do
|
||||
Fog::AWS::IAM.new.update_server_certificate("unknown-key-name", {'NewServerCertificateName' => "other-keyname"})
|
||||
end
|
||||
|
||||
tests('format').formats(@update_format) do
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name).body
|
||||
end
|
||||
|
||||
tests('updates name') do
|
||||
other_key_name = "successful-update-key-name"
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name})
|
||||
returns(true) { Fog::AWS::IAM.new.get_server_certificate(other_key_name).body['Certificate']['ServerCertificateName'] == other_key_name }
|
||||
end
|
||||
end
|
||||
|
||||
tests('#get_server_certificate').formats(@get_server_certificate_format) do
|
||||
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
|
||||
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
||||
|
|
Loading…
Reference in a new issue