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

Modernize various tests to Ruby 2.x syntax

Also fix up various things that rubocop called out, though not
everything. Mostly whitespace fixes, changing double-quotes to single if
double wasn't required, changing to use ruby 2.x hash syntax where
possible, etc. While tests don't run, they are no more broken than
before (at least, as far as I can tell).
This commit is contained in:
David Bishop 2018-10-16 16:12:42 -06:00
parent 4a1fbb0e4d
commit 62256219f4
19 changed files with 311 additions and 324 deletions

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
Shindo.tests('AWS | credentials', ['aws']) do Shindo.tests('AWS | credentials', ['aws']) do
old_mock_value = Excon.defaults[:mock] old_mock_value = Excon.defaults[:mock]
fog_was_mocked = Fog.mocking? fog_was_mocked = Fog.mocking?
@ -5,8 +7,8 @@ Shindo.tests('AWS | credentials', ['aws']) do
Fog.unmock! Fog.unmock!
begin begin
Excon.defaults[:mock] = true Excon.defaults[:mock] = true
Excon.stub({:method => :get, :path => "/latest/meta-data/iam/security-credentials/"}, {:status => 200, :body => 'arole'}) Excon.stub({ method: :get, path: '/latest/meta-data/iam/security-credentials/' }, { status: 200, body: 'arole' })
Excon.stub({:method => :get, :path => "/latest/meta-data/placement/availability-zone/"}, {:status => 200, :body => 'us-west-1a'}) Excon.stub({ method: :get, path: '/latest/meta-data/placement/availability-zone/' }, { status: 200, body: 'us-west-1a' })
expires_at = Time.at(Time.now.to_i + 500) expires_at = Time.at(Time.now.to_i + 500)
credentials = { credentials = {
@ -16,69 +18,68 @@ Shindo.tests('AWS | credentials', ['aws']) do
'Expiration' => expires_at.xmlschema 'Expiration' => expires_at.xmlschema
} }
Excon.stub({:method => :get, :path => "/latest/meta-data/iam/security-credentials/arole"}, {:status => 200, :body => Fog::JSON.encode(credentials)}) Excon.stub({ method: :get, path: '/latest/meta-data/iam/security-credentials/arole' }, { status: 200, body: Fog::JSON.encode(credentials) })
tests("#fetch_credentials") do tests('#fetch_credentials') do
returns({:aws_access_key_id => 'dummykey', returns(aws_access_key_id: 'dummykey',
:aws_secret_access_key => 'dummysecret', aws_secret_access_key: 'dummysecret',
:aws_session_token => 'dummytoken', aws_session_token: 'dummytoken',
:region => "us-west-1", region: 'us-west-1',
:aws_credentials_expire_at => expires_at}) { Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true) } aws_credentials_expire_at: expires_at) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
end end
ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] = '/v1/credentials?id=task_id' ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] = '/v1/credentials?id=task_id'
Excon.stub({:method => :get, :path => '/v1/credentials?id=task_id'}, {:status => 200, :body => Fog::JSON.encode(credentials)}) Excon.stub({ method: :get, path: '/v1/credentials?id=task_id' }, { status: 200, body: Fog::JSON.encode(credentials) })
tests("#fetch_credentials") do tests('#fetch_credentials') do
returns({:aws_access_key_id => 'dummykey', returns(aws_access_key_id: 'dummykey',
:aws_secret_access_key => 'dummysecret', aws_secret_access_key: 'dummysecret',
:aws_session_token => 'dummytoken', aws_session_token: 'dummytoken',
:region => "us-west-1", region: 'us-west-1',
:aws_credentials_expire_at => expires_at}) { Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true) } aws_credentials_expire_at: expires_at) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
end end
ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] = nil ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] = nil
compute = Fog::AWS::Compute.new(:use_iam_profile => true) compute = Fog::AWS::Compute.new(use_iam_profile: true)
tests("#refresh_credentials_if_expired") do tests('#refresh_credentials_if_expired') do
returns(nil){compute.refresh_credentials_if_expired} returns(nil) { compute.refresh_credentials_if_expired }
end end
credentials['AccessKeyId'] = 'newkey' credentials['AccessKeyId'] = 'newkey'
credentials['SecretAccessKey'] = 'newsecret' credentials['SecretAccessKey'] = 'newsecret'
credentials['Expiration'] = (expires_at + 10).xmlschema credentials['Expiration'] = (expires_at + 10).xmlschema
Excon.stub({:method => :get, :path => "/latest/meta-data/iam/security-credentials/arole"}, {:status => 200, :body => Fog::JSON.encode(credentials)}) Excon.stub({ method: :get, path: '/latest/meta-data/iam/security-credentials/arole' }, { status: 200, body: Fog::JSON.encode(credentials) })
Fog::Time.now = expires_at + 1 Fog::Time.now = expires_at + 1
tests("#refresh_credentials_if_expired") do tests('#refresh_credentials_if_expired') do
returns(true){compute.refresh_credentials_if_expired} returns(true) { compute.refresh_credentials_if_expired }
returns("newkey"){ compute.instance_variable_get(:@aws_access_key_id)} returns('newkey') { compute.instance_variable_get(:@aws_access_key_id) }
end end
Fog::Time.now = Time.now Fog::Time.now = Time.now
default_credentials = Fog::AWS::Compute.fetch_credentials({}) default_credentials = Fog::AWS::Compute.fetch_credentials({})
tests("#fetch_credentials when the url 404s") do tests('#fetch_credentials when the url 404s') do
Excon.stub({:method => :get, :path => "/latest/meta-data/iam/security-credentials/"}, {:status => 404, :body => 'not bound'}) Excon.stub({ method: :get, path: '/latest/meta-data/iam/security-credentials/' }, { status: 404, body: 'not bound' })
Excon.stub({:method => :get, :path => "/latest/meta-data/placement/availability-zone/"}, {:status => 400, :body => 'not found'}) Excon.stub({ method: :get, path: '/latest/meta-data/placement/availability-zone/' }, { status: 400, body: 'not found' })
returns(default_credentials) {Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true)} returns(default_credentials) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
end end
mocked_credentials = { mocked_credentials = {
:aws_access_key_id => "access-key-id", aws_access_key_id: 'access-key-id',
:aws_secret_access_key => "secret-access-key", aws_secret_access_key: 'secret-access-key',
:aws_session_token => "session-token", aws_session_token: 'session-token',
:aws_credentials_expire_at => Time.at(Time.now.to_i + 500).xmlschema aws_credentials_expire_at: Time.at(Time.now.to_i + 500).xmlschema
} }
tests("#fetch_credentials when mocking") do tests('#fetch_credentials when mocking') do
Fog.mock! Fog.mock!
Fog::AWS::Compute::Mock.data[:iam_role_based_creds] = mocked_credentials Fog::AWS::Compute::Mock.data[:iam_role_based_creds] = mocked_credentials
returns(mocked_credentials) {Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true)} returns(mocked_credentials) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
end end
ensure ensure
ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] = nil ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] = nil
Excon.stubs.clear Excon.stubs.clear
Excon.defaults[:mock] = old_mock_value Excon.defaults[:mock] = old_mock_value
Fog.mock! if fog_was_mocked Fog.mock! if fog_was_mocked

View file

@ -1,7 +1,7 @@
begin begin
require 'simplecov' require 'simplecov'
SimpleCov.start SimpleCov.start
SimpleCov.command_name "Shindo" SimpleCov.command_name 'Shindo'
rescue LoadError => e rescue LoadError => e
$stderr.puts "not recording test coverage: #{e.inspect}" $stderr.puts "not recording test coverage: #{e.inspect}"
end end
@ -10,7 +10,7 @@ require File.expand_path('../../lib/fog/aws', __FILE__)
Bundler.require(:test) Bundler.require(:test)
Excon.defaults.merge!(:debug_request => true, :debug_response => true) Excon.defaults.merge!(debug_request: true, debug_response: true)
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper'))

View file

@ -1,6 +1,5 @@
def collection_tests(collection, params = {}, mocks_implemented = true) def collection_tests(collection, params = {}, mocks_implemented = true)
tests('success') do tests('success') do
tests("#new(#{params.inspect})").succeeds do tests("#new(#{params.inspect})").succeeds do
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
collection.new(params) collection.new(params)
@ -34,7 +33,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true)
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
methods = [ methods = [
'all?', 'any?', 'find', 'detect', 'collect', 'map', 'all?', 'any?', 'find', 'detect', 'collect', 'map',
'find_index', 'flat_map', 'collect_concat', 'group_by', 'find_index', 'flat_map', 'collect_concat', 'group_by',
'none?', 'one?' 'none?', 'one?'
] ]
@ -43,7 +42,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true)
if collection.respond_to?(enum_method) if collection.respond_to?(enum_method)
tests("##{enum_method}").succeeds do tests("##{enum_method}").succeeds do
block_called = false block_called = false
collection.send(enum_method) {|x| block_called = true } collection.send(enum_method) { block_called = true }
block_called block_called
end end
end end
@ -55,7 +54,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true)
if collection.respond_to?(enum_method) if collection.respond_to?(enum_method)
tests("##{enum_method}").succeeds do tests("##{enum_method}").succeeds do
block_called = false block_called = false
collection.send(enum_method) {|x| block_called = true; 0 } collection.send(enum_method) { block_called = true; 0 }
block_called block_called
end end
end end

View file

@ -1,7 +1,6 @@
def flavors_tests(connection, params = {}, mocks_implemented = true) def flavors_tests(connection, params = {}, mocks_implemented = true)
tests('success') do tests('success') do
tests('#all').succeeds do
tests("#all").succeeds do
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
connection.flavors.all connection.flavors.all
end end
@ -14,11 +13,9 @@ def flavors_tests(connection, params = {}, mocks_implemented = true)
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
connection.flavors.get(@identity) connection.flavors.get(@identity)
end end
end end
tests('failure') do tests('failure') do
if !Fog.mocking? || mocks_implemented if !Fog.mocking? || mocks_implemented
invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0') invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0')
end end
@ -27,6 +24,5 @@ def flavors_tests(connection, params = {}, mocks_implemented = true)
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
connection.flavors.get(invalid_flavor_identity) connection.flavors.get(invalid_flavor_identity)
end end
end end
end end

View file

@ -1,6 +1,5 @@
def server_tests(connection, params = {}, mocks_implemented = true) def server_tests(connection, params = {}, mocks_implemented = true)
model_tests(connection.servers, params, mocks_implemented) do model_tests(connection.servers, params, mocks_implemented) do
tests('#reload').returns(true) do tests('#reload').returns(true) do
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
@instance.wait_for { ready? } @instance.wait_for { ready? }
@ -8,7 +7,7 @@ def server_tests(connection, params = {}, mocks_implemented = true)
!identity.nil? && identity == @instance.reload.identity !identity.nil? && identity == @instance.reload.identity
end end
responds_to([:ready?, :state]) responds_to(%i[ready state])
yield if block_given? yield if block_given?
tests('#reboot').succeeds do tests('#reboot').succeeds do
@ -20,6 +19,5 @@ def server_tests(connection, params = {}, mocks_implemented = true)
if !Fog.mocking? || mocks_implemented if !Fog.mocking? || mocks_implemented
@instance.wait_for { ready? } @instance.wait_for { ready? }
end end
end end
end end

View file

@ -1,10 +1,8 @@
def servers_tests(connection, params = {}, mocks_implemented = true) def servers_tests(connection, params = {}, mocks_implemented = true)
collection_tests(connection.servers, params, mocks_implemented) do collection_tests(connection.servers, params, mocks_implemented) do
if !Fog.mocking? || mocks_implemented if !Fog.mocking? || mocks_implemented
@instance.wait_for { ready? } @instance.wait_for { ready? }
yield if block_given? yield if block_given?
end end
end end
end end

View file

@ -1,54 +1,55 @@
def dns_providers def dns_providers
{ {
:aws => { aws: {
:mocked => false mocked: false
}, },
:bluebox => { bluebox: {
:mocked => false, mocked: false,
:zone_attributes => { zone_attributes: {
:ttl => 60 ttl: 60
} }
}, },
:dnsimple => { dnsimple: {
:mocked => false mocked: false
}, },
:dnsmadeeasy => { dnsmadeeasy: {
:mocked => false mocked: false
}, },
:dynect => { dynect: {
:mocked => false, mocked: false,
:zone_attributes => { zone_attributes: {
:email => 'fog@example.com' email: 'fog@example.com'
} }
}, },
:linode => { linode: {
:mocked => false, mocked: false,
:zone_attributes => { zone_attributes: {
:email => 'fog@example.com' email: 'fog@example.com'
} }
}, },
:zerigo => { zerigo: {
:mocked => false mocked: false
}, },
:rackspace => { rackspace: {
:mocked => false, mocked: false,
:zone_attributes => { zone_attributes: {
:email => 'fog@example.com' email: 'fog@example.com'
} }
}, },
:rage4 => { rage4: {
:mocked => false mocked: false
} }
} }
end end
def generate_unique_domain( with_trailing_dot = false) def generate_unique_domain(with_trailing_dot = false)
#get time (with 1/100th of sec accuracy) # get time (with 1/100th of sec accuracy)
#want unique domain name and if provider is fast, this can be called more than once per second # want unique domain name and if provider is fast,
time= (Time.now.to_f * 100).to_i # this can be called more than once per second
time = (Time.now.to_f * 100).to_i
domain = 'test-' + time.to_s + '.com' domain = 'test-' + time.to_s + '.com'
if with_trailing_dot if with_trailing_dot
domain+= '.' domain += '.'
end end
domain domain

View file

@ -1,4 +1,6 @@
require "fog/schema/data_validator" # frozen_string_literal: true
require 'fog/schema/data_validator'
# format related hackery # format related hackery
# allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean)
@ -15,62 +17,62 @@ module Fog
module Array; end module Array; end
end end
end end
[FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)} [FalseClass, TrueClass].each { |klass| klass.send(:include, Fog::Boolean) }
[FalseClass, TrueClass, NilClass, Fog::Boolean].each {|klass| klass.send(:include, Fog::Nullable::Boolean)} [FalseClass, TrueClass, NilClass, Fog::Boolean].each { |klass| klass.send(:include, Fog::Nullable::Boolean) }
[NilClass, String].each {|klass| klass.send(:include, Fog::Nullable::String)} [NilClass, String].each { |klass| klass.send(:include, Fog::Nullable::String) }
[NilClass, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)} [NilClass, Time].each { |klass| klass.send(:include, Fog::Nullable::Time) }
[Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)} [Integer, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Integer) }
[Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)} [Float, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Float) }
[Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)} [Hash, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Hash) }
[Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)} [Array, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Array) }
module Shindo module Shindo
# Generates a Shindo test that compares a hash schema to the result
# of the passed in block returning true if they match.
#
# The schema that is passed in is a Hash or Array of hashes that
# have Classes in place of values. When checking the schema the
# value should match the Class.
#
# Strict mode will fail if the data has additional keys. Setting
# +strict+ to +false+ will allow additional keys to appear.
#
# @param [Hash] schema A Hash schema
# @param [Hash] options Options to change validation rules
# @option options [Boolean] :allow_extra_keys
# If +true+ does not fail when keys are in the data that are
# not specified in the schema. This allows new values to
# appear in API output without breaking the check.
# @option options [Boolean] :allow_optional_rules
# If +true+ does not fail if extra keys are in the schema
# that do not match the data. Not recommended!
# @yield Data to check with schema
#
# @example Using in a test
# Shindo.tests("comparing welcome data against schema") do
# data = {:welcome => "Hello" }
# data_matches_schema(:welcome => String) { data }
# end
#
# comparing welcome data against schema
# + data matches schema
#
# @example Example schema
# {
# "id" => String,
# "ram" => Integer,
# "disks" => [
# {
# "size" => Float
# }
# ],
# "dns_name" => Fog::Nullable::String,
# "active" => Fog::Boolean,
# "created" => DateTime
# }
#
# @return [Boolean]
class Tests class Tests
# Generates a Shindo test that compares a hash schema to the result
# of the passed in block returning true if they match.
#
# The schema that is passed in is a Hash or Array of hashes that
# have Classes in place of values. When checking the schema the
# value should match the Class.
#
# Strict mode will fail if the data has additional keys. Setting
# +strict+ to +false+ will allow additional keys to appear.
#
# @param [Hash] schema A Hash schema
# @param [Hash] options Options to change validation rules
# @option options [Boolean] :allow_extra_keys
# If +true+ does not fail when keys are in the data that are
# not specified in the schema. This allows new values to
# appear in API output without breaking the check.
# @option options [Boolean] :allow_optional_rules
# If +true+ does not fail if extra keys are in the schema
# that do not match the data. Not recommended!
# @yield Data to check with schema
#
# @example Using in a test
# Shindo.tests("comparing welcome data against schema") do
# data = {:welcome => "Hello" }
# data_matches_schema(:welcome => String) { data }
# end
#
# comparing welcome data against schema
# + data matches schema
#
# @example Example schema
# {
# "id" => String,
# "ram" => Integer,
# "disks" => [
# {
# "size" => Float
# }
# ],
# "dns_name" => Fog::Nullable::String,
# "active" => Fog::Boolean,
# "created" => DateTime
# }
#
# @return [Boolean]
def data_matches_schema(schema, options = {}) def data_matches_schema(schema, options = {})
test('data matches schema') do test('data matches schema') do
validator = Fog::Schema::DataValidator.new validator = Fog::Schema::DataValidator.new
@ -84,9 +86,9 @@ module Shindo
def formats(format, strict = true) def formats(format, strict = true)
test('has proper format') do test('has proper format') do
if strict if strict
options = {:allow_extra_keys => false, :allow_optional_rules => true} options = { allow_extra_keys: false, allow_optional_rules: true }
else else
options = {:allow_extra_keys => true, :allow_optional_rules => true} options = { allow_extra_keys: true, allow_optional_rules: true }
end end
validator = Fog::Schema::DataValidator.new validator = Fog::Schema::DataValidator.new
valid = validator.validate(yield, format, options) valid = validator.validate(yield, format, options)

View file

@ -1,37 +1,37 @@
Shindo.tests('test_helper', 'meta') do Shindo.tests('test_helper', 'meta') do
tests('comparing welcome data against schema') do tests('comparing welcome data against schema') do
data = {:welcome => "Hello" } data = { welcome: 'Hello' }
data_matches_schema(:welcome => String) { data } data_matches_schema(welcome: String) { data }
end end
tests('#data_matches_schema') do tests('#data_matches_schema') do
tests('when value matches schema expectation') do tests('when value matches schema expectation') do
data_matches_schema({"key" => String}) { {"key" => "Value"} } data_matches_schema('key' => String) { { 'key' => 'Value' } }
end end
tests('when values within an array all match schema expectation') do tests('when values within an array all match schema expectation') do
data_matches_schema({"key" => [Integer]}) { {"key" => [1, 2]} } data_matches_schema('key' => [Integer]) { { 'key' => [1, 2] } }
end end
tests('when nested values match schema expectation') do tests('when nested values match schema expectation') do
data_matches_schema({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } data_matches_schema('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
end end
tests('when collection of values all match schema expectation') do tests('when collection of values all match schema expectation') do
data_matches_schema([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } data_matches_schema([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
end end
tests('when collection is empty although schema covers optional members') do tests('when collection is empty although schema covers optional members') do
data_matches_schema([{"key" => String}], {:allow_optional_rules => true}) { [] } data_matches_schema([{ 'key' => String }], allow_optional_rules: true) { [] }
end end
tests('when additional keys are passed and not strict') do tests('when additional keys are passed and not strict') do
data_matches_schema({"key" => String}, {:allow_extra_keys => true}) { {"key" => "Value", :extra => "Bonus"} } data_matches_schema({ 'key' => String }, allow_extra_keys: true) { { 'key' => 'Value', extra: 'Bonus' } }
end end
tests('when value is nil and schema expects NilClass') do tests('when value is nil and schema expects NilClass') do
data_matches_schema({"key" => NilClass}) { {"key" => nil} } data_matches_schema('key' => NilClass) { { 'key' => nil } }
end end
tests('when value and schema match as hashes') do tests('when value and schema match as hashes') do
@ -43,46 +43,45 @@ Shindo.tests('test_helper', 'meta') do
end end
tests('when value is a Time') do tests('when value is a Time') do
data_matches_schema({"time" => Time}) { {"time" => Time.now} } data_matches_schema('time' => Time) { { 'time' => Time.now } }
end end
tests('when key is missing but value should be NilClass (#1477)') do tests('when key is missing but value should be NilClass (#1477)') do
data_matches_schema({"key" => NilClass}, {:allow_optional_rules => true}) { {} } data_matches_schema({ 'key' => NilClass }, allow_optional_rules: true) { {} }
end end
tests('when key is missing but value is nullable (#1477)') do tests('when key is missing but value is nullable (#1477)') do
data_matches_schema({"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) { {} } data_matches_schema({ 'key' => Fog::Nullable::String }, allow_optional_rules: true) { {} }
end end
end end
tests('#formats backwards compatible changes') do tests('#formats backwards compatible changes') do
tests('when value matches schema expectation') do tests('when value matches schema expectation') do
formats({"key" => String}) { {"key" => "Value"} } formats('key' => String) { { 'key' => 'Value' } }
end end
tests('when values within an array all match schema expectation') do tests('when values within an array all match schema expectation') do
formats({"key" => [Integer]}) { {"key" => [1, 2]} } formats('key' => [Integer]) { { 'key' => [1, 2] } }
end end
tests('when nested values match schema expectation') do tests('when nested values match schema expectation') do
formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } formats('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
end end
tests('when collection of values all match schema expectation') do tests('when collection of values all match schema expectation') do
formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } formats([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
end end
tests('when collection is empty although schema covers optional members') do tests('when collection is empty although schema covers optional members') do
formats([{"key" => String}]) { [] } formats([{ 'key' => String }]) { [] }
end end
tests('when additional keys are passed and not strict') do tests('when additional keys are passed and not strict') do
formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} } formats({ 'key' => String }, false) { { 'key' => 'Value', :extra => 'Bonus' } }
end end
tests('when value is nil and schema expects NilClass') do tests('when value is nil and schema expects NilClass') do
formats({"key" => NilClass}) { {"key" => nil} } formats('key' => NilClass) { { 'key' => nil } }
end end
tests('when value and schema match as hashes') do tests('when value and schema match as hashes') do
@ -94,17 +93,15 @@ Shindo.tests('test_helper', 'meta') do
end end
tests('when value is a Time') do tests('when value is a Time') do
formats({"time" => Time}) { {"time" => Time.now} } formats('time' => Time) { { 'time' => Time.now } }
end end
tests('when key is missing but value should be NilClass (#1477)') do tests('when key is missing but value should be NilClass (#1477)') do
formats({"key" => NilClass}) { {} } formats('key' => NilClass) { {} }
end end
tests('when key is missing but value is nullable (#1477)') do tests('when key is missing but value is nullable (#1477)') do
formats({"key" => Fog::Nullable::String}) { {} } formats('key' => Fog::Nullable::String) { {} }
end end
end end
end end

View file

@ -9,101 +9,101 @@ end
# if in mocked mode, fill in some fake credentials for us # if in mocked mode, fill in some fake credentials for us
if Fog.mock? if Fog.mock?
Fog.credentials = { Fog.credentials = {
:aws_access_key_id => 'aws_access_key_id', aws_access_key_id: 'aws_access_key_id',
:aws_secret_access_key => 'aws_secret_access_key', aws_secret_access_key: 'aws_secret_access_key',
:ia_access_key_id => 'aws_access_key_id', ia_access_key_id: 'aws_access_key_id',
:ia_secret_access_key => 'aws_secret_access_key', ia_secret_access_key: 'aws_secret_access_key',
:bluebox_api_key => 'bluebox_api_key', bluebox_api_key: 'bluebox_api_key',
:bluebox_customer_id => 'bluebox_customer_id', bluebox_customer_id: 'bluebox_customer_id',
:brightbox_client_id => 'brightbox_client_id', brightbox_client_id: 'brightbox_client_id',
:brightbox_secret => 'brightbox_secret', brightbox_secret: 'brightbox_secret',
:cloudstack_disk_offering_id => '', cloudstack_disk_offering_id: '',
:cloudstack_host => 'http://cloudstack.example.org', cloudstack_host: 'http://cloudstack.example.org',
:cloudstack_network_ids => '', cloudstack_network_ids: '',
:cloudstack_service_offering_id => '4437ac6c-9fe3-477a-57ec-60a5a45896a4', cloudstack_service_offering_id: '4437ac6c-9fe3-477a-57ec-60a5a45896a4',
:cloudstack_template_id => '8a31cf9c-f248-0588-256e-9dbf58785216', cloudstack_template_id: '8a31cf9c-f248-0588-256e-9dbf58785216',
:cloudstack_zone_id => 'c554c592-e09c-9df5-7688-4a32754a4305', cloudstack_zone_id: 'c554c592-e09c-9df5-7688-4a32754a4305',
:cloudstack_project_id => 'f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1f1', cloudstack_project_id: 'f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1f1',
:clodo_api_key => 'clodo_api_key', clodo_api_key: 'clodo_api_key',
:clodo_username => 'clodo_username', clodo_username: 'clodo_username',
:digitalocean_api_key => 'digitalocean_api_key', digitalocean_api_key: 'digitalocean_api_key',
:digitalocean_client_id => 'digitalocean_client_id', digitalocean_client_id: 'digitalocean_client_id',
:dnsimple_email => 'dnsimple_email', dnsimple_email: 'dnsimple_email',
:dnsimple_password => 'dnsimple_password', dnsimple_password: 'dnsimple_password',
:dnsmadeeasy_api_key => 'dnsmadeeasy_api_key', dnsmadeeasy_api_key: 'dnsmadeeasy_api_key',
:dnsmadeeasy_secret_key => 'dnsmadeeasy_secret_key', dnsmadeeasy_secret_key: 'dnsmadeeasy_secret_key',
:glesys_username => 'glesys_username', glesys_username: 'glesys_username',
:glesys_api_key => 'glesys_api_key', glesys_api_key: 'glesys_api_key',
:go_grid_api_key => 'go_grid_api_key', go_grid_api_key: 'go_grid_api_key',
:go_grid_shared_secret => 'go_grid_shared_secret', go_grid_shared_secret: 'go_grid_shared_secret',
:google_storage_access_key_id => 'google_storage_access_key_id', google_storage_access_key_id: 'google_storage_access_key_id',
:google_storage_secret_access_key => 'google_storage_secret_access_key', google_storage_secret_access_key: 'google_storage_secret_access_key',
:google_project => 'google_project_name', google_project: 'google_project_name',
:google_client_email => 'fake@developer.gserviceaccount.com', google_client_email: 'fake@developer.gserviceaccount.com',
:google_key_location => '~/fake.p12', google_key_location: '~/fake.p12',
:hp_access_key => 'hp_access_key', hp_access_key: 'hp_access_key',
:hp_secret_key => 'hp_secret_key', hp_secret_key: 'hp_secret_key',
:hp_tenant_id => 'hp_tenant_id', hp_tenant_id: 'hp_tenant_id',
:hp_avl_zone => 'hp_avl_zone', hp_avl_zone: 'hp_avl_zone',
:os_account_meta_temp_url_key => 'os_account_meta_temp_url_key', os_account_meta_temp_url_key: 'os_account_meta_temp_url_key',
:ibm_username => 'ibm_username', ibm_username: 'ibm_username',
:ibm_password => 'ibm_password', ibm_password: 'ibm_password',
:joyent_username => "joyentuser", joyent_username: 'joyentuser',
:joyent_password => "joyentpass", joyent_password: 'joyentpass',
:linode_api_key => 'linode_api_key', linode_api_key: 'linode_api_key',
:local_root => '~/.fog', local_root: '~/.fog',
:bare_metal_cloud_password => 'bare_metal_cloud_password', bare_metal_cloud_password: 'bare_metal_cloud_password',
:bare_metal_cloud_username => 'bare_metal_cloud_username', bare_metal_cloud_username: 'bare_metal_cloud_username',
:ninefold_compute_key => 'ninefold_compute_key', ninefold_compute_key: 'ninefold_compute_key',
:ninefold_compute_secret => 'ninefold_compute_secret', ninefold_compute_secret: 'ninefold_compute_secret',
:ninefold_storage_secret => 'ninefold_storage_secret', ninefold_storage_secret: 'ninefold_storage_secret',
:ninefold_storage_token => 'ninefold_storage_token', ninefold_storage_token: 'ninefold_storage_token',
# :public_key_path => '~/.ssh/id_rsa.pub', # public_key_path: '~/.ssh/id_rsa.pub',
# :private_key_path => '~/.ssh/id_rsa', # private_key_path: '~/.ssh/id_rsa',
:opennebula_endpoint => 'http://opennebula:2633/RPC2', opennebula_endpoint: 'http://opennebula:2633/RPC2',
:opennebula_username => 'oneadmin', opennebula_username: 'oneadmin',
:opennebula_password => 'oneadmin', opennebula_password: 'oneadmin',
:openstack_api_key => 'openstack_api_key', openstack_api_key: 'openstack_api_key',
:openstack_username => 'openstack_username', openstack_username: 'openstack_username',
:openstack_tenant => 'openstack_tenant', openstack_tenant: 'openstack_tenant',
:openstack_auth_url => 'http://openstack:35357/v2.0/tokens', openstack_auth_url: 'http://openstack:35357/v2.0/tokens',
:ovirt_url => 'http://ovirt:8080/api', ovirt_url: 'http://ovirt:8080/api',
:ovirt_username => 'admin@internal', ovirt_username: 'admin@internal',
:ovirt_password => '123123', ovirt_password: '123123',
:profitbricks_username => 'profitbricks_username', profitbricks_username: 'profitbricks_username',
:profitbricks_password => 'profitbricks_password', profitbricks_password: 'profitbricks_password',
:libvirt_uri => 'qemu://libvirt/system', libvirt_uri: 'qemu://libvirt/system',
:rackspace_api_key => 'rackspace_api_key', rackspace_api_key: 'rackspace_api_key',
:rackspace_region => 'dfw', rackspace_region: 'dfw',
:rackspace_username => 'rackspace_username', rackspace_username: 'rackspace_username',
:riakcs_access_key_id => 'riakcs_access_key_id', riakcs_access_key_id: 'riakcs_access_key_id',
:riakcs_secret_access_key => 'riakcs_secret_access_key', riakcs_secret_access_key: 'riakcs_secret_access_key',
:sakuracloud_api_token => 'sakuracloud_api_token', sakuracloud_api_token: 'sakuracloud_api_token',
:sakuracloud_api_token_secret => 'sakuracloud_api_token_secret', sakuracloud_api_token_secret: 'sakuracloud_api_token_secret',
:storm_on_demand_username => 'storm_on_demand_username', storm_on_demand_username: 'storm_on_demand_username',
:storm_on_demand_password => 'storm_on_demand_password', storm_on_demand_password: 'storm_on_demand_password',
:vcloud_host => 'vcloud_host', vcloud_host: 'vcloud_host',
:vcloud_password => 'vcloud_password', vcloud_password: 'vcloud_password',
:vcloud_username => 'vcloud_username', vcloud_username: 'vcloud_username',
:vcloud_director_host => 'vcloud-director-host', vcloud_director_host: 'vcloud-director-host',
:vcloud_director_password => 'vcloud_director_password', vcloud_director_password: 'vcloud_director_password',
:vcloud_director_username => 'vcd_user@vcd_org_name', vcloud_director_username: 'vcd_user@vcd_org_name',
:zerigo_email => 'zerigo_email', zerigo_email: 'zerigo_email',
:zerigo_token => 'zerigo_token', zerigo_token: 'zerigo_token',
:dynect_customer => 'dynect_customer', dynect_customer: 'dynect_customer',
:dynect_username => 'dynect_username', dynect_username: 'dynect_username',
:dynect_password => 'dynect_password', dynect_password: 'dynect_password',
:vsphere_server => 'virtualcenter.lan', vsphere_server: 'virtualcenter.lan',
:vsphere_username => 'apiuser', vsphere_username: 'apiuser',
:vsphere_password => 'apipassword', vsphere_password: 'apipassword',
:vsphere_expected_pubkey_hash => 'abcdef1234567890', vsphere_expected_pubkey_hash: 'abcdef1234567890',
:libvirt_username => 'root', libvirt_username: 'root',
:libvirt_password => 'password', libvirt_password: 'password',
:cloudsigma_username => 'csuname', cloudsigma_username: 'csuname',
:cloudsigma_password => 'cspass', cloudsigma_password: 'cspass',
:docker_username => 'docker-fan', docker_username: 'docker-fan',
:docker_password => 'i<3docker', docker_password: 'i<3docker',
:docker_email => 'dockerfan@gmail.com', docker_email: 'dockerfan@gmail.com',
:docker_url => 'unix://var/run/docker.sock' docker_url: 'unix://var/run/docker.sock'
}.merge(Fog.credentials) }.merge(Fog.credentials)
end end

View file

@ -1,9 +1,8 @@
def model_tests(collection, params = {}, mocks_implemented = true) def model_tests(collection, params = {}, mocks_implemented = true)
tests('success') do tests('success') do
@instance = collection.new(params) @instance = collection.new(params)
tests("#save").succeeds do tests('#save').succeeds do
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
@instance.save @instance.save
end end
@ -12,7 +11,7 @@ def model_tests(collection, params = {}, mocks_implemented = true)
yield(@instance) yield(@instance)
end end
tests("#destroy").succeeds do tests('#destroy').succeeds do
pending if Fog.mocking? && !mocks_implemented pending if Fog.mocking? && !mocks_implemented
@instance.destroy @instance.destroy
end end
@ -26,6 +25,6 @@ end
# E.g. 'fog-test-1234' # E.g. 'fog-test-1234'
def uniq_id(base_name = 'fog-test') def uniq_id(base_name = 'fog-test')
# random_differentiator # random_differentiator
suffix = rand(65536).to_s(16).rjust(4, '0') suffix = rand(65_536).to_s(16).rjust(4, '0')
[base_name, suffix] * '-' [base_name, suffix].join('-')
end end

View file

@ -1,7 +1,7 @@
module Shindo module Shindo
class Tests class Tests
def responds_to(method_names) def responds_to(method_names)
for method_name in [*method_names] [*method_names].each do |method_name|
tests("#respond_to?(:#{method_name})").returns(true) do tests("#respond_to?(:#{method_name})").returns(true) do
@instance.respond_to?(method_name) @instance.respond_to?(method_name)
end end

View file

@ -1,37 +1,37 @@
# frozen_string_literal: true
Shindo.tests('Fog::Schema::DataValidator', 'meta') do Shindo.tests('Fog::Schema::DataValidator', 'meta') do
validator = Fog::Schema::DataValidator.new validator = Fog::Schema::DataValidator.new
tests('#validate') do tests('#validate') do
tests('returns true') do tests('returns true') do
returns(true, 'when value matches schema expectation') do returns(true, 'when value matches schema expectation') do
validator.validate({"key" => "Value"}, {"key" => String}) validator.validate({ 'key' => 'Value' }, 'key' => String)
end end
returns(true, 'when values within an array all match schema expectation') do returns(true, 'when values within an array all match schema expectation') do
validator.validate({"key" => [1, 2]}, {"key" => [Integer]}) validator.validate({ 'key' => [1, 2] }, 'key' => [Integer])
end end
returns(true, 'when nested values match schema expectation') do returns(true, 'when nested values match schema expectation') do
validator.validate({"key" => {:nested_key => "Value"}}, {"key" => {:nested_key => String}}) validator.validate({ 'key' => { nested_key: 'Value' } }, 'key' => { nested_key: String })
end end
returns(true, 'when collection of values all match schema expectation') do returns(true, 'when collection of values all match schema expectation') do
validator.validate([{"key" => "Value"}, {"key" => "Value"}], [{"key" => String}]) validator.validate([{ 'key' => 'Value' }, 'key' => 'Value'], [{ 'key' => String }])
end end
returns(true, 'when collection is empty although schema covers optional members') do returns(true, 'when collection is empty although schema covers optional members') do
validator.validate([], [{"key" => String}]) validator.validate([], [{ 'key' => String }])
end end
returns(true, 'when additional keys are passed and not strict') do returns(true, 'when additional keys are passed and not strict') do
validator.validate({"key" => "Value", :extra => "Bonus"}, {"key" => String}, {:allow_extra_keys => true}) validator.validate({ 'key' => 'Value', extra: 'Bonus' }, { 'key' => String }, allow_extra_keys: true)
end end
returns(true, 'when value is nil and schema expects NilClass') do returns(true, 'when value is nil and schema expects NilClass') do
validator.validate({"key" => nil}, {"key" => NilClass}) validator.validate({ 'key' => nil }, 'key' => NilClass)
end end
returns(true, 'when value and schema match as hashes') do returns(true, 'when value and schema match as hashes') do
@ -43,43 +43,41 @@ Shindo.tests('Fog::Schema::DataValidator', 'meta') do
end end
returns(true, 'when value is a Time') do returns(true, 'when value is a Time') do
validator.validate({"time" => Time.now}, {"time" => Time}) validator.validate({ 'time' => Time.now }, 'time' => Time)
end end
returns(true, 'when key is missing but value should be NilClass (#1477)') do returns(true, 'when key is missing but value should be NilClass (#1477)') do
validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => true}) validator.validate({}, { 'key' => NilClass }, allow_optional_rules: true)
end end
returns(true, 'when key is missing but value is nullable (#1477)') do returns(true, 'when key is missing but value is nullable (#1477)') do
validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) validator.validate({}, { 'key' => Fog::Nullable::String }, allow_optional_rules: true)
end end
end end
tests('returns false') do tests('returns false') do
returns(false, 'when value does not match schema expectation') do returns(false, 'when value does not match schema expectation') do
validator.validate({"key" => nil}, {"key" => String}) validator.validate({ 'key' => nil }, 'key' => String)
end end
returns(false, 'when key formats do not match') do returns(false, 'when key formats do not match') do
validator.validate({"key" => "Value"}, {:key => String}) validator.validate({ 'key' => 'Value' }, key: String)
end end
returns(false, 'when additional keys are passed and strict') do returns(false, 'when additional keys are passed and strict') do
validator.validate({"key" => "Missing"}, {}) validator.validate({ 'key' => 'Missing' }, {})
end end
returns(false, 'when some keys do not appear') do returns(false, 'when some keys do not appear') do
validator.validate({}, {"key" => String}) validator.validate({}, 'key' => String)
end end
returns(false, 'when collection contains a member that does not match schema') do returns(false, 'when collection contains a member that does not match schema') do
validator.validate([{"key" => "Value"}, {"key" => 5}], [{"key" => String}]) validator.validate([{ 'key' => 'Value' }, 'key' => 5], ['key' => String])
end end
returns(false, 'when collection has multiple schema patterns') do returns(false, 'when collection has multiple schema patterns') do
validator.validate([{"key" => "Value"}], [{"key" => Integer}, {"key" => String}]) validator.validate([{ 'key' => 'Value' }], [{ 'key' => Integer }, { 'key' => String }])
end end
returns(false, 'when hash and array are compared') do returns(false, 'when hash and array are compared') do
@ -91,17 +89,16 @@ Shindo.tests('Fog::Schema::DataValidator', 'meta') do
end end
returns(false, 'when a hash is expected but another data type is found') do returns(false, 'when a hash is expected but another data type is found') do
validator.validate({"key" => {:nested_key => []}}, {"key" => {:nested_key => {}}}) validator.validate({ 'key' => { nested_key: [] } }, 'key' => { nested_key: {} })
end end
returns(false, 'when key is missing but value should be NilClass (#1477)') do returns(false, 'when key is missing but value should be NilClass (#1477)') do
validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => false}) validator.validate({}, { 'key' => NilClass }, allow_optional_rules: false)
end end
returns(false, 'when key is missing but value is nullable (#1477)') do returns(false, 'when key is missing but value is nullable (#1477)') do
validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => false}) validator.validate({}, { 'key' => Fog::Nullable::String }, allow_optional_rules: false)
end end
end end
end end
end end

View file

@ -2,7 +2,7 @@ module Shindo
class Tests class Tests
def succeeds def succeeds
test('succeeds') do test('succeeds') do
!!instance_eval(&Proc.new) !instance_eval(&Proc.new).nil?
end end
end end
end end

View file

@ -24,7 +24,7 @@ DESCRIBE_IMAGES_RESULT = <<-EOF
</DescribeImagesResponse> </DescribeImagesResponse>
EOF EOF
Shindo.tests('AWS::Compute | parsers | describe_images', ['compute', 'aws', 'parser']) do Shindo.tests('AWS::Compute | parsers | describe_images', %w[compute aws parser]) do
tests('parses the xml').formats(AWS::Compute::Formats::DESCRIBE_IMAGES) do tests('parses the xml').formats(AWS::Compute::Formats::DESCRIBE_IMAGES) do
parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::Compute::DescribeImages.new) parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::Compute::DescribeImages.new)
parser.parse(DESCRIBE_IMAGES_RESULT) parser.parse(DESCRIBE_IMAGES_RESULT)

View file

@ -56,7 +56,7 @@ xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
</DescribeLoadBalancersResponse> </DescribeLoadBalancersResponse>
EOF EOF
Shindo.tests('AWS::ELB | parsers | describe_load_balancers', ['aws', 'elb', 'parser']) do Shindo.tests('AWS::ELB | parsers | describe_load_balancers', %w[aws elb parser]) do
tests('parses the xml').formats(AWS::ELB::Formats::DESCRIBE_LOAD_BALANCERS) do tests('parses the xml').formats(AWS::ELB::Formats::DESCRIBE_LOAD_BALANCERS) do
parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new) parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new)
parser.parse(DESCRIBE_LOAD_BALANCERS_RESULT) parser.parse(DESCRIBE_LOAD_BALANCERS_RESULT)

View file

@ -1,81 +1,80 @@
# encoding: utf-8 # encoding: utf-8
Shindo.tests('AWS | signaturev4', ['aws']) do Shindo.tests('AWS | signaturev4', ['aws']) do
@now = Fog::Time.utc(2011, 9, 9, 23, 36, 0)
@now = Fog::Time.utc(2011,9,9,23,36,0)
# These testcases are from http://docs.amazonwebservices.com/general/latest/gr/signature-v4-test-suite.html # These testcases are from http://docs.amazonwebservices.com/general/latest/gr/signature-v4-test-suite.html
@signer = Fog::AWS::SignatureV4.new('AKIDEXAMPLE', 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', 'us-east-1','host') @signer = Fog::AWS::SignatureV4.new('AKIDEXAMPLE', 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', 'us-east-1', 'host')
tests('get-vanilla') do tests('get-vanilla') do
returns(@signer.sign({:headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do returns(@signer.sign({ headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470'
end end
end end
tests('get-headers-mixed-case-headers') do tests('get-headers-mixed-case-headers') do
returns(@signer.sign({:headers => {'HOST' => 'host.foo.com', 'date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do returns(@signer.sign({ headers: { 'HOST' => 'host.foo.com', 'date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470'
end end
end end
tests('get-vanilla-query-order-key with symbol keys') do tests('get-vanilla-query-order-key with symbol keys') do
returns(@signer.sign({:query => {:'a' => 'foo', :'b' => 'foo'}, :headers => {:'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do returns(@signer.sign({ query: { a: 'foo', b: 'foo' }, headers: { Host: 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, method: :get, path: '/' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=0dc122f3b28b831ab48ba65cb47300de53fbe91b577fe113edac383730254a3b' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=0dc122f3b28b831ab48ba65cb47300de53fbe91b577fe113edac383730254a3b'
end end
end end
tests('get-vanilla-query-order-key') do tests('get-vanilla-query-order-key') do
returns(@signer.sign({:query => {'a' => 'foo', 'b' => 'foo'}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do returns(@signer.sign({ query: { a: 'foo', b: 'foo' }, headers: { Host: 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=0dc122f3b28b831ab48ba65cb47300de53fbe91b577fe113edac383730254a3b' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=0dc122f3b28b831ab48ba65cb47300de53fbe91b577fe113edac383730254a3b'
end end
end end
tests('get-unreserved') do tests('get-unreserved') do
returns(@signer.sign({:headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'}, @now)) do returns(@signer.sign({ headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=830cc36d03f0f84e6ee4953fbe701c1c8b71a0372c63af9255aa364dd183281e' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=830cc36d03f0f84e6ee4953fbe701c1c8b71a0372c63af9255aa364dd183281e'
end end
end end
tests('post-x-www-form-urlencoded-parameter') do tests('post-x-www-form-urlencoded-parameter') do
returns(@signer.sign({:headers => {'Content-type' => 'application/x-www-form-urlencoded; charset=utf8', 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :post, :path => '/', returns(@signer.sign({ headers: { 'Content-type' => 'application/x-www-form-urlencoded; charset=utf8', 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :post, path: '/',
:body => 'foo=bar'}, @now)) do body: 'foo=bar' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=content-type;date;host, Signature=b105eb10c6d318d2294de9d49dd8b031b55e3c3fe139f2e637da70511e9e7b71' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=content-type;date;host, Signature=b105eb10c6d318d2294de9d49dd8b031b55e3c3fe139f2e637da70511e9e7b71'
end end
end end
tests('get with relative path') do tests('get with relative path') do
returns(@signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/foo/bar/../..'}, @now)) do returns(@signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/foo/bar/../..' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470'
end end
end end
tests('get with pointless .') do tests('get with pointless .') do
returns(@signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/./foo'}, @now)) do returns(@signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/./foo' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=910e4d6c9abafaf87898e1eb4c929135782ea25bb0279703146455745391e63a' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=910e4d6c9abafaf87898e1eb4c929135782ea25bb0279703146455745391e63a'
end end
end end
tests('get with repeated / ') do tests('get with repeated / ') do
returns(@signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '//'}, @now)) do returns(@signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '//' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470'
end end
end end
tests('get with repeated // inside path') do tests('get with repeated // inside path') do
returns(@signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/foo//bar//baz'}, @now)) do returns(@signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/foo//bar//baz' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b250c85c72c5d7c33f67759c7a1ad79ea381cf62105290cecd530af2771575d4' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b250c85c72c5d7c33f67759c7a1ad79ea381cf62105290cecd530af2771575d4'
end end
end end
tests('get with repeated trailing / ') do tests('get with repeated trailing / ') do
returns(@signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '//foo//'}, @now)) do returns(@signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '//foo//' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b00392262853cfe3201e47ccf945601079e9b8a7f51ee4c3d9ee4f187aa9bf19' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b00392262853cfe3201e47ccf945601079e9b8a7f51ee4c3d9ee4f187aa9bf19'
end end
end end
tests('get signature as components') do tests('get signature as components') do
returns(@signer.signature_parameters({:query => {'a' => 'foo', 'b' => 'foo'}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do returns(@signer.signature_parameters({ query: { 'a' => 'foo', 'b' => 'foo' }, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/'}, @now)) do
{ {
'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256', 'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256',
'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request', 'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request',
@ -85,8 +84,8 @@ Shindo.tests('AWS | signaturev4', ['aws']) do
end end
end end
tests("inject body sha") do tests('inject body sha') do
returns(@signer.signature_parameters({:query => {'a' => 'foo', 'b' => 'foo'}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now, 'STREAMING-AWS4-HMAC-SHA256-PAYLOAD')) do returns(@signer.signature_parameters({ query: { 'a' => 'foo', 'b' => 'foo' }, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '/' }, @now, 'STREAMING-AWS4-HMAC-SHA256-PAYLOAD')) do
{ {
'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256', 'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256',
'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request', 'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request',
@ -96,9 +95,9 @@ Shindo.tests('AWS | signaturev4', ['aws']) do
end end
end end
tests("s3 signer does not normalize path") do tests('s3 signer does not normalize path') do
signer=Fog::AWS::SignatureV4.new('AKIDEXAMPLE', 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', 'us-east-1','s3') signer = Fog::AWS::SignatureV4.new('AKIDEXAMPLE', 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', 'us-east-1', 's3')
returns(signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '//foo/../bar/./'}, @now)) do returns(signer.sign({ query: {}, headers: { 'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT' }, method: :get, path: '//foo/../bar/./' }, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/s3/aws4_request, SignedHeaders=date;host, Signature=72407ad06b8e5750360f42e8aad9f33a0be363bcfeecdcae0aea58c99709fb4a' 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/s3/aws4_request, SignedHeaders=date;host, Signature=72407ad06b8e5750360f42e8aad9f33a0be363bcfeecdcae0aea58c99709fb4a'
end end
end end

View file

@ -1,17 +1,17 @@
# encoding: utf-8 # encoding: utf-8
Shindo.tests('AWS | signed_params', ['aws']) do Shindo.tests('AWS | signed_params', ['aws']) do
returns( Fog::AWS.escape( "'Stöp!' said Fred_-~./" ) ) { "%27St%C3%B6p%21%27%20said%20Fred_-~.%2F" } returns(Fog::AWS.escape("'Stöp!' said Fred_-~./")) { '%27St%C3%B6p%21%27%20said%20Fred_-~.%2F' }
tests('Unicode characters should be escaped') do tests('Unicode characters should be escaped') do
unicode = ["00E9".to_i(16)].pack("U*") unicode = ['00E9'.to_i(16)].pack('U*')
escaped = "%C3%A9" escaped = '%C3%A9'
returns( escaped ) { Fog::AWS.escape( unicode ) } returns(escaped) { Fog::AWS.escape(unicode) }
end end
tests('Unicode characters with combining marks should be escaped') do tests('Unicode characters with combining marks should be escaped') do
unicode = ["0065".to_i(16), "0301".to_i(16)].pack("U*") unicode = ['0065'.to_i(16), '0301'.to_i(16)].pack('U*')
escaped = "e%CC%81" escaped = 'e%CC%81'
returns( escaped ) { Fog::AWS.escape( unicode ) } returns(escaped) { Fog::AWS.escape(unicode) }
end end
end end

View file

@ -2,6 +2,6 @@
Shindo.tests('AWS Storage | escape', ['aws']) do Shindo.tests('AWS Storage | escape', ['aws']) do
tests('Keys can contain a hierarchical prefix which should not be escaped') do tests('Keys can contain a hierarchical prefix which should not be escaped') do
returns( Fog::AWS::Storage.new.send(:escape, "key/with/prefix") ) { "key/with/prefix" } returns(Fog::AWS::Storage.new.send(:escape, 'key/with/prefix')) { 'key/with/prefix' }
end end
end end