mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[compute|aws] Better key_pair tests
Also, Fog::AWS::Mock.key_material returns a valid RSA key
This commit is contained in:
parent
59a46d8299
commit
b0f4d2448c
3 changed files with 15 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue