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

Merge pull request #313 from ktheory/better_aws_tests

Better aws tests
This commit is contained in:
Wesley Beary 2011-05-18 14:46:43 -07:00
commit 8ad1fc81c4
6 changed files with 34 additions and 24 deletions

View file

@ -141,12 +141,12 @@ module Fog
@aws_access_key_id = options[:aws_access_key_id] @aws_access_key_id = options[:aws_access_key_id]
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1'].include?(options[:region])
raise ArgumentError, "Unknown region: #{options[:region].inspect}"
end
@region = options[:region] || 'us-east-1' @region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
@data = self.class.data[@region][@aws_access_key_id] @data = self.class.data[@region][@aws_access_key_id]
@owner_id = @data[:owner_id] @owner_id = @data[:owner_id]
end end

View file

@ -33,7 +33,19 @@ module Fog
class Mock class Mock
def get_password_data(instance_id) def get_password_data(instance_id)
Fog::Mock.not_implemented response = Excon::Response.new
if instance = @data[:instances][instance_id]
response.status = 200
response.body = {
'instanceId' => instance_id,
'passwordData' => nil,
'requestId' => Fog::AWS::Mock.request_id,
'timestamp' => Time.now
}
response
else;
raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_id}' does not exist")
end
end end
end end

View file

@ -1,5 +1,6 @@
require 'fog/core' require 'fog/core'
require 'fog/core/parser' require 'fog/core/parser'
require 'openssl' # For RSA key pairs
module Fog module Fog
module AWS module AWS
@ -140,13 +141,7 @@ module Fog
end end
def self.key_material def self.key_material
key_material = ['-----BEGIN RSA PRIVATE KEY-----'] OpenSSL::PKey::RSA.generate(1024).to_s
20.times do
key_material << Fog::Mock.random_base64(76)
end
key_material << Fog::Mock.random_base64(67) + '='
key_material << '-----END RSA PRIVATE KEY-----'
key_material.join("\n")
end end
def self.owner_id def self.owner_id

View file

@ -60,7 +60,7 @@ Shindo.tests('AWS::Compute | instance requests', ['aws']) do
@get_password_data_format = { @get_password_data_format = {
'instanceId' => String, 'instanceId' => String,
'passwordData' => String, 'passwordData' => Fog::Nullable::String,
'requestId' => String, 'requestId' => String,
'timestamp' => Time 'timestamp' => Time
} }
@ -119,15 +119,18 @@ Shindo.tests('AWS::Compute | instance requests', ['aws']) do
end end
tests("#get_password_data('#{@instance_id}')").formats(@get_password_data_format) do tests("#get_password_data('#{@instance_id}')").formats(@get_password_data_format) do
pending if Fog.mock?
result = nil
Fog.wait_for do
result = AWS[:compute].get_password_data(@instance_id).body result = AWS[:compute].get_password_data(@instance_id).body
!result['passwordData'].nil?
end
tests("key can decrypt passwordData").returns(true) do tests("key can decrypt passwordData").returns(true) do
decoded_password = Base64.decode64(result['passwordData'])
pending if Fog.mocking?
password_data = result['passwordData']
Fog.wait_for do
password_data ||= AWS[:compute].get_password_data(@instance_id).body['passwordData']
end
decoded_password = Base64.decode64(password_data)
pkey = OpenSSL::PKey::RSA.new(key.private_key) pkey = OpenSSL::PKey::RSA.new(key.private_key)
String === pkey.private_decrypt(decoded_password) String === pkey.private_decrypt(decoded_password)
end end

View file

@ -21,7 +21,7 @@ Shindo.tests('AWS::Compute | key pair requests', ['aws']) do
tests("#create_key_pair('#{@key_pair_name}')").formats(@keypair_format.merge({'keyMaterial' => String})) do tests("#create_key_pair('#{@key_pair_name}')").formats(@keypair_format.merge({'keyMaterial' => String})) do
body = AWS[:compute].create_key_pair(@key_pair_name).body body = AWS[:compute].create_key_pair(@key_pair_name).body
tests("private key is valid RSA key").returns(OpenSSL::PKey::RSA) do tests("key material").returns(OpenSSL::PKey::RSA, "is a valid private RSA key") do
OpenSSL::PKey::RSA.new(body['keyMaterial']).class OpenSSL::PKey::RSA.new(body['keyMaterial']).class
end end
body body

View file

@ -22,12 +22,12 @@ Shindo.tests('AWS::Compute | volume requests', ['aws']) do
@volumes_format = { @volumes_format = {
'volumeSet' => [{ 'volumeSet' => [{
'availabilityZone' => String, 'availabilityZone' => String,
'attachmentSet' => [], 'attachmentSet' => Array,
'createTime' => Time, 'createTime' => Time,
'size' => Integer, 'size' => Integer,
'snapshotId' => Fog::Nullable::String, 'snapshotId' => Fog::Nullable::String,
'status' => String, 'status' => String,
'tagSet' => {}, 'tagSet' => Hash,
'volumeId' => String 'volumeId' => String
}], }],
'requestId' => String 'requestId' => String