diff --git a/lib/fog/compute/aws.rb b/lib/fog/compute/aws.rb index df3eabf99..2b24f18f1 100644 --- a/lib/fog/compute/aws.rb +++ b/lib/fog/compute/aws.rb @@ -141,12 +141,12 @@ module Fog @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' + 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] @owner_id = @data[:owner_id] end diff --git a/lib/fog/compute/requests/aws/get_password_data.rb b/lib/fog/compute/requests/aws/get_password_data.rb index 30ca950c6..8a6298a0b 100644 --- a/lib/fog/compute/requests/aws/get_password_data.rb +++ b/lib/fog/compute/requests/aws/get_password_data.rb @@ -33,7 +33,19 @@ module Fog class Mock 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 diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index b7192d821..8ec5bb68b 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -1,5 +1,6 @@ require 'fog/core' require 'fog/core/parser' +require 'openssl' # For RSA key pairs module Fog module AWS @@ -44,7 +45,7 @@ module Fog def self.escape(string) string.gsub( /([^-a-zA-Z0-9_.~]+)/n ) { |match| '%' + match.unpack( 'H2' * match.size ).join( '%' ).upcase } end - + def self.signed_params(params, options = {}) params.merge!({ 'AWSAccessKeyId' => options[:aws_access_key_id], @@ -140,13 +141,7 @@ module Fog end def self.key_material - key_material = ['-----BEGIN RSA PRIVATE KEY-----'] - 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") + OpenSSL::PKey::RSA.generate(1024).to_s end def self.owner_id diff --git a/tests/compute/requests/aws/instance_tests.rb b/tests/compute/requests/aws/instance_tests.rb index 6417fa98e..9ca5b6c69 100644 --- a/tests/compute/requests/aws/instance_tests.rb +++ b/tests/compute/requests/aws/instance_tests.rb @@ -60,7 +60,7 @@ Shindo.tests('AWS::Compute | instance requests', ['aws']) do @get_password_data_format = { 'instanceId' => String, - 'passwordData' => String, + 'passwordData' => Fog::Nullable::String, 'requestId' => String, 'timestamp' => Time } @@ -119,15 +119,18 @@ Shindo.tests('AWS::Compute | instance requests', ['aws']) do end 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['passwordData'].nil? - end + result = AWS[:compute].get_password_data(@instance_id).body 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) String === pkey.private_decrypt(decoded_password) end diff --git a/tests/compute/requests/aws/key_pair_tests.rb b/tests/compute/requests/aws/key_pair_tests.rb index 655f00920..a4f709dba 100644 --- a/tests/compute/requests/aws/key_pair_tests.rb +++ b/tests/compute/requests/aws/key_pair_tests.rb @@ -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 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 end body diff --git a/tests/compute/requests/aws/volume_tests.rb b/tests/compute/requests/aws/volume_tests.rb index d267fdf52..610ce8c9f 100644 --- a/tests/compute/requests/aws/volume_tests.rb +++ b/tests/compute/requests/aws/volume_tests.rb @@ -22,12 +22,12 @@ Shindo.tests('AWS::Compute | volume requests', ['aws']) do @volumes_format = { 'volumeSet' => [{ 'availabilityZone' => String, - 'attachmentSet' => [], + 'attachmentSet' => Array, 'createTime' => Time, 'size' => Integer, 'snapshotId' => Fog::Nullable::String, 'status' => String, - 'tagSet' => {}, + 'tagSet' => Hash, 'volumeId' => String }], 'requestId' => String