diff --git a/tests/credentials_tests.rb b/tests/credentials_tests.rb index 1ca9fa161..a7d0511a2 100644 --- a/tests/credentials_tests.rb +++ b/tests/credentials_tests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Shindo.tests('AWS | credentials', ['aws']) do old_mock_value = Excon.defaults[:mock] fog_was_mocked = Fog.mocking? @@ -5,8 +7,8 @@ Shindo.tests('AWS | credentials', ['aws']) do Fog.unmock! begin 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/placement/availability-zone/"}, {:status => 200, :body => 'us-west-1a'}) + 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' }) expires_at = Time.at(Time.now.to_i + 500) credentials = { @@ -16,69 +18,68 @@ Shindo.tests('AWS | credentials', ['aws']) do '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 - returns({:aws_access_key_id => 'dummykey', - :aws_secret_access_key => 'dummysecret', - :aws_session_token => 'dummytoken', - :region => "us-west-1", - :aws_credentials_expire_at => expires_at}) { Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true) } + tests('#fetch_credentials') do + returns(aws_access_key_id: 'dummykey', + aws_secret_access_key: 'dummysecret', + aws_session_token: 'dummytoken', + region: 'us-west-1', + aws_credentials_expire_at: expires_at) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) } end - 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)}) + 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) }) - tests("#fetch_credentials") do - returns({:aws_access_key_id => 'dummykey', - :aws_secret_access_key => 'dummysecret', - :aws_session_token => 'dummytoken', - :region => "us-west-1", - :aws_credentials_expire_at => expires_at}) { Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true) } + tests('#fetch_credentials') do + returns(aws_access_key_id: 'dummykey', + aws_secret_access_key: 'dummysecret', + aws_session_token: 'dummytoken', + region: 'us-west-1', + aws_credentials_expire_at: expires_at) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) } 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 - returns(nil){compute.refresh_credentials_if_expired} + tests('#refresh_credentials_if_expired') do + returns(nil) { compute.refresh_credentials_if_expired } end credentials['AccessKeyId'] = 'newkey' credentials['SecretAccessKey'] = 'newsecret' 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 - tests("#refresh_credentials_if_expired") do - returns(true){compute.refresh_credentials_if_expired} - returns("newkey"){ compute.instance_variable_get(:@aws_access_key_id)} + tests('#refresh_credentials_if_expired') do + returns(true) { compute.refresh_credentials_if_expired } + returns('newkey') { compute.instance_variable_get(:@aws_access_key_id) } end Fog::Time.now = Time.now default_credentials = Fog::AWS::Compute.fetch_credentials({}) - 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/placement/availability-zone/"}, {:status => 400, :body => 'not found'}) - returns(default_credentials) {Fog::AWS::Compute.fetch_credentials(:use_iam_profile => true)} + 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/placement/availability-zone/' }, { status: 400, body: 'not found' }) + returns(default_credentials) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) } end mocked_credentials = { - :aws_access_key_id => "access-key-id", - :aws_secret_access_key => "secret-access-key", - :aws_session_token => "session-token", - :aws_credentials_expire_at => Time.at(Time.now.to_i + 500).xmlschema + aws_access_key_id: 'access-key-id', + aws_secret_access_key: 'secret-access-key', + aws_session_token: 'session-token', + 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::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 - ensure - ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"] = nil + ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] = nil Excon.stubs.clear Excon.defaults[:mock] = old_mock_value Fog.mock! if fog_was_mocked diff --git a/tests/helper.rb b/tests/helper.rb index 1aa467622..d8217b9a2 100644 --- a/tests/helper.rb +++ b/tests/helper.rb @@ -1,7 +1,7 @@ begin require 'simplecov' SimpleCov.start - SimpleCov.command_name "Shindo" + SimpleCov.command_name 'Shindo' rescue LoadError => e $stderr.puts "not recording test coverage: #{e.inspect}" end @@ -10,7 +10,7 @@ require File.expand_path('../../lib/fog/aws', __FILE__) 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')) diff --git a/tests/helpers/collection_helper.rb b/tests/helpers/collection_helper.rb index 78a751e07..2a2988272 100644 --- a/tests/helpers/collection_helper.rb +++ b/tests/helpers/collection_helper.rb @@ -1,6 +1,5 @@ def collection_tests(collection, params = {}, mocks_implemented = true) tests('success') do - tests("#new(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.new(params) @@ -34,7 +33,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true) pending if Fog.mocking? && !mocks_implemented methods = [ - 'all?', 'any?', 'find', 'detect', 'collect', 'map', + 'all?', 'any?', 'find', 'detect', 'collect', 'map', 'find_index', 'flat_map', 'collect_concat', 'group_by', 'none?', 'one?' ] @@ -43,7 +42,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true) if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false - collection.send(enum_method) {|x| block_called = true } + collection.send(enum_method) { block_called = true } block_called end end @@ -55,7 +54,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true) if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false - collection.send(enum_method) {|x| block_called = true; 0 } + collection.send(enum_method) { block_called = true; 0 } block_called end end diff --git a/tests/helpers/compute/flavors_helper.rb b/tests/helpers/compute/flavors_helper.rb index b9170e816..fda6828d2 100644 --- a/tests/helpers/compute/flavors_helper.rb +++ b/tests/helpers/compute/flavors_helper.rb @@ -1,7 +1,6 @@ def flavors_tests(connection, params = {}, mocks_implemented = true) tests('success') do - - tests("#all").succeeds do + tests('#all').succeeds do pending if Fog.mocking? && !mocks_implemented connection.flavors.all end @@ -14,11 +13,9 @@ def flavors_tests(connection, params = {}, mocks_implemented = true) pending if Fog.mocking? && !mocks_implemented connection.flavors.get(@identity) end - end tests('failure') do - if !Fog.mocking? || mocks_implemented invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0') end @@ -27,6 +24,5 @@ def flavors_tests(connection, params = {}, mocks_implemented = true) pending if Fog.mocking? && !mocks_implemented connection.flavors.get(invalid_flavor_identity) end - end end diff --git a/tests/helpers/compute/server_helper.rb b/tests/helpers/compute/server_helper.rb index 90a79fb12..2d27fedd0 100644 --- a/tests/helpers/compute/server_helper.rb +++ b/tests/helpers/compute/server_helper.rb @@ -1,6 +1,5 @@ def server_tests(connection, params = {}, mocks_implemented = true) model_tests(connection.servers, params, mocks_implemented) do - tests('#reload').returns(true) do pending if Fog.mocking? && !mocks_implemented @instance.wait_for { ready? } @@ -8,7 +7,7 @@ def server_tests(connection, params = {}, mocks_implemented = true) !identity.nil? && identity == @instance.reload.identity end - responds_to([:ready?, :state]) + responds_to(%i[ready state]) yield if block_given? tests('#reboot').succeeds do @@ -20,6 +19,5 @@ def server_tests(connection, params = {}, mocks_implemented = true) if !Fog.mocking? || mocks_implemented @instance.wait_for { ready? } end - end end diff --git a/tests/helpers/compute/servers_helper.rb b/tests/helpers/compute/servers_helper.rb index 60a292211..3d56c83f7 100644 --- a/tests/helpers/compute/servers_helper.rb +++ b/tests/helpers/compute/servers_helper.rb @@ -1,10 +1,8 @@ def servers_tests(connection, params = {}, mocks_implemented = true) collection_tests(connection.servers, params, mocks_implemented) do - if !Fog.mocking? || mocks_implemented @instance.wait_for { ready? } yield if block_given? end - end end diff --git a/tests/helpers/dns_helper.rb b/tests/helpers/dns_helper.rb index 1c85cefe8..f990fecc6 100644 --- a/tests/helpers/dns_helper.rb +++ b/tests/helpers/dns_helper.rb @@ -1,54 +1,55 @@ def dns_providers { - :aws => { - :mocked => false + aws: { + mocked: false }, - :bluebox => { - :mocked => false, - :zone_attributes => { - :ttl => 60 + bluebox: { + mocked: false, + zone_attributes: { + ttl: 60 } }, - :dnsimple => { - :mocked => false + dnsimple: { + mocked: false }, - :dnsmadeeasy => { - :mocked => false + dnsmadeeasy: { + mocked: false }, - :dynect => { - :mocked => false, - :zone_attributes => { - :email => 'fog@example.com' + dynect: { + mocked: false, + zone_attributes: { + email: 'fog@example.com' } }, - :linode => { - :mocked => false, - :zone_attributes => { - :email => 'fog@example.com' + linode: { + mocked: false, + zone_attributes: { + email: 'fog@example.com' } }, - :zerigo => { - :mocked => false + zerigo: { + mocked: false }, - :rackspace => { - :mocked => false, - :zone_attributes => { - :email => 'fog@example.com' + rackspace: { + mocked: false, + zone_attributes: { + email: 'fog@example.com' } }, - :rage4 => { - :mocked => false + rage4: { + mocked: false } } end -def generate_unique_domain( with_trailing_dot = false) - #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 - time= (Time.now.to_f * 100).to_i +def generate_unique_domain(with_trailing_dot = false) + # 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 + time = (Time.now.to_f * 100).to_i domain = 'test-' + time.to_s + '.com' if with_trailing_dot - domain+= '.' + domain += '.' end domain diff --git a/tests/helpers/formats_helper.rb b/tests/helpers/formats_helper.rb index 0053bb546..ab4b42ab2 100644 --- a/tests/helpers/formats_helper.rb +++ b/tests/helpers/formats_helper.rb @@ -1,4 +1,6 @@ -require "fog/schema/data_validator" +# frozen_string_literal: true + +require 'fog/schema/data_validator' # format related hackery # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) @@ -15,62 +17,62 @@ module Fog module Array; end end end -[FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::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, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)} -[Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)} -[Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)} -[Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)} -[Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)} +[FalseClass, TrueClass].each { |klass| klass.send(:include, Fog::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, Time].each { |klass| klass.send(:include, Fog::Nullable::Time) } +[Integer, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Integer) } +[Float, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Float) } +[Hash, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Hash) } +[Array, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Array) } 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 - # 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 = {}) test('data matches schema') do validator = Fog::Schema::DataValidator.new @@ -84,9 +86,9 @@ module Shindo def formats(format, strict = true) test('has proper format') do if strict - options = {:allow_extra_keys => false, :allow_optional_rules => true} + options = { allow_extra_keys: false, allow_optional_rules: true } else - options = {:allow_extra_keys => true, :allow_optional_rules => true} + options = { allow_extra_keys: true, allow_optional_rules: true } end validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, format, options) diff --git a/tests/helpers/formats_helper_tests.rb b/tests/helpers/formats_helper_tests.rb index dba2386f0..5f691bc1d 100644 --- a/tests/helpers/formats_helper_tests.rb +++ b/tests/helpers/formats_helper_tests.rb @@ -1,37 +1,37 @@ Shindo.tests('test_helper', 'meta') do tests('comparing welcome data against schema') do - data = {:welcome => "Hello" } - data_matches_schema(:welcome => String) { data } + data = { welcome: 'Hello' } + data_matches_schema(welcome: String) { data } end tests('#data_matches_schema') do tests('when value matches schema expectation') do - data_matches_schema({"key" => String}) { {"key" => "Value"} } + data_matches_schema('key' => String) { { 'key' => 'Value' } } end 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 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 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 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 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 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 tests('when value and schema match as hashes') do @@ -43,46 +43,45 @@ Shindo.tests('test_helper', 'meta') do end tests('when value is a Time') do - data_matches_schema({"time" => Time}) { {"time" => Time.now} } + data_matches_schema('time' => Time) { { 'time' => Time.now } } end 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 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 tests('#formats backwards compatible changes') do - tests('when value matches schema expectation') do - formats({"key" => String}) { {"key" => "Value"} } + formats('key' => String) { { 'key' => 'Value' } } end tests('when values within an array all match schema expectation') do - formats({"key" => [Integer]}) { {"key" => [1, 2]} } + formats('key' => [Integer]) { { 'key' => [1, 2] } } end 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 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 tests('when collection is empty although schema covers optional members') do - formats([{"key" => String}]) { [] } + formats([{ 'key' => String }]) { [] } end 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 tests('when value is nil and schema expects NilClass') do - formats({"key" => NilClass}) { {"key" => nil} } + formats('key' => NilClass) { { 'key' => nil } } end tests('when value and schema match as hashes') do @@ -94,17 +93,15 @@ Shindo.tests('test_helper', 'meta') do end tests('when value is a Time') do - formats({"time" => Time}) { {"time" => Time.now} } + formats('time' => Time) { { 'time' => Time.now } } end tests('when key is missing but value should be NilClass (#1477)') do - formats({"key" => NilClass}) { {} } + formats('key' => NilClass) { {} } end tests('when key is missing but value is nullable (#1477)') do - formats({"key" => Fog::Nullable::String}) { {} } + formats('key' => Fog::Nullable::String) { {} } end - end - end diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index 7c024c799..18e0e8b6b 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -9,101 +9,101 @@ end # if in mocked mode, fill in some fake credentials for us if Fog.mock? Fog.credentials = { - :aws_access_key_id => 'aws_access_key_id', - :aws_secret_access_key => 'aws_secret_access_key', - :ia_access_key_id => 'aws_access_key_id', - :ia_secret_access_key => 'aws_secret_access_key', - :bluebox_api_key => 'bluebox_api_key', - :bluebox_customer_id => 'bluebox_customer_id', - :brightbox_client_id => 'brightbox_client_id', - :brightbox_secret => 'brightbox_secret', - :cloudstack_disk_offering_id => '', - :cloudstack_host => 'http://cloudstack.example.org', - :cloudstack_network_ids => '', - :cloudstack_service_offering_id => '4437ac6c-9fe3-477a-57ec-60a5a45896a4', - :cloudstack_template_id => '8a31cf9c-f248-0588-256e-9dbf58785216', - :cloudstack_zone_id => 'c554c592-e09c-9df5-7688-4a32754a4305', - :cloudstack_project_id => 'f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1f1', - :clodo_api_key => 'clodo_api_key', - :clodo_username => 'clodo_username', - :digitalocean_api_key => 'digitalocean_api_key', - :digitalocean_client_id => 'digitalocean_client_id', - :dnsimple_email => 'dnsimple_email', - :dnsimple_password => 'dnsimple_password', - :dnsmadeeasy_api_key => 'dnsmadeeasy_api_key', - :dnsmadeeasy_secret_key => 'dnsmadeeasy_secret_key', - :glesys_username => 'glesys_username', - :glesys_api_key => 'glesys_api_key', - :go_grid_api_key => 'go_grid_api_key', - :go_grid_shared_secret => 'go_grid_shared_secret', - :google_storage_access_key_id => 'google_storage_access_key_id', - :google_storage_secret_access_key => 'google_storage_secret_access_key', - :google_project => 'google_project_name', - :google_client_email => 'fake@developer.gserviceaccount.com', - :google_key_location => '~/fake.p12', - :hp_access_key => 'hp_access_key', - :hp_secret_key => 'hp_secret_key', - :hp_tenant_id => 'hp_tenant_id', - :hp_avl_zone => 'hp_avl_zone', - :os_account_meta_temp_url_key => 'os_account_meta_temp_url_key', - :ibm_username => 'ibm_username', - :ibm_password => 'ibm_password', - :joyent_username => "joyentuser", - :joyent_password => "joyentpass", - :linode_api_key => 'linode_api_key', - :local_root => '~/.fog', - :bare_metal_cloud_password => 'bare_metal_cloud_password', - :bare_metal_cloud_username => 'bare_metal_cloud_username', - :ninefold_compute_key => 'ninefold_compute_key', - :ninefold_compute_secret => 'ninefold_compute_secret', - :ninefold_storage_secret => 'ninefold_storage_secret', - :ninefold_storage_token => 'ninefold_storage_token', -# :public_key_path => '~/.ssh/id_rsa.pub', -# :private_key_path => '~/.ssh/id_rsa', - :opennebula_endpoint => 'http://opennebula:2633/RPC2', - :opennebula_username => 'oneadmin', - :opennebula_password => 'oneadmin', - :openstack_api_key => 'openstack_api_key', - :openstack_username => 'openstack_username', - :openstack_tenant => 'openstack_tenant', - :openstack_auth_url => 'http://openstack:35357/v2.0/tokens', - :ovirt_url => 'http://ovirt:8080/api', - :ovirt_username => 'admin@internal', - :ovirt_password => '123123', - :profitbricks_username => 'profitbricks_username', - :profitbricks_password => 'profitbricks_password', - :libvirt_uri => 'qemu://libvirt/system', - :rackspace_api_key => 'rackspace_api_key', - :rackspace_region => 'dfw', - :rackspace_username => 'rackspace_username', - :riakcs_access_key_id => 'riakcs_access_key_id', - :riakcs_secret_access_key => 'riakcs_secret_access_key', - :sakuracloud_api_token => 'sakuracloud_api_token', - :sakuracloud_api_token_secret => 'sakuracloud_api_token_secret', - :storm_on_demand_username => 'storm_on_demand_username', - :storm_on_demand_password => 'storm_on_demand_password', - :vcloud_host => 'vcloud_host', - :vcloud_password => 'vcloud_password', - :vcloud_username => 'vcloud_username', - :vcloud_director_host => 'vcloud-director-host', - :vcloud_director_password => 'vcloud_director_password', - :vcloud_director_username => 'vcd_user@vcd_org_name', - :zerigo_email => 'zerigo_email', - :zerigo_token => 'zerigo_token', - :dynect_customer => 'dynect_customer', - :dynect_username => 'dynect_username', - :dynect_password => 'dynect_password', - :vsphere_server => 'virtualcenter.lan', - :vsphere_username => 'apiuser', - :vsphere_password => 'apipassword', - :vsphere_expected_pubkey_hash => 'abcdef1234567890', - :libvirt_username => 'root', - :libvirt_password => 'password', - :cloudsigma_username => 'csuname', - :cloudsigma_password => 'cspass', - :docker_username => 'docker-fan', - :docker_password => 'i<3docker', - :docker_email => 'dockerfan@gmail.com', - :docker_url => 'unix://var/run/docker.sock' + aws_access_key_id: 'aws_access_key_id', + aws_secret_access_key: 'aws_secret_access_key', + ia_access_key_id: 'aws_access_key_id', + ia_secret_access_key: 'aws_secret_access_key', + bluebox_api_key: 'bluebox_api_key', + bluebox_customer_id: 'bluebox_customer_id', + brightbox_client_id: 'brightbox_client_id', + brightbox_secret: 'brightbox_secret', + cloudstack_disk_offering_id: '', + cloudstack_host: 'http://cloudstack.example.org', + cloudstack_network_ids: '', + cloudstack_service_offering_id: '4437ac6c-9fe3-477a-57ec-60a5a45896a4', + cloudstack_template_id: '8a31cf9c-f248-0588-256e-9dbf58785216', + cloudstack_zone_id: 'c554c592-e09c-9df5-7688-4a32754a4305', + cloudstack_project_id: 'f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1f1', + clodo_api_key: 'clodo_api_key', + clodo_username: 'clodo_username', + digitalocean_api_key: 'digitalocean_api_key', + digitalocean_client_id: 'digitalocean_client_id', + dnsimple_email: 'dnsimple_email', + dnsimple_password: 'dnsimple_password', + dnsmadeeasy_api_key: 'dnsmadeeasy_api_key', + dnsmadeeasy_secret_key: 'dnsmadeeasy_secret_key', + glesys_username: 'glesys_username', + glesys_api_key: 'glesys_api_key', + go_grid_api_key: 'go_grid_api_key', + go_grid_shared_secret: 'go_grid_shared_secret', + google_storage_access_key_id: 'google_storage_access_key_id', + google_storage_secret_access_key: 'google_storage_secret_access_key', + google_project: 'google_project_name', + google_client_email: 'fake@developer.gserviceaccount.com', + google_key_location: '~/fake.p12', + hp_access_key: 'hp_access_key', + hp_secret_key: 'hp_secret_key', + hp_tenant_id: 'hp_tenant_id', + hp_avl_zone: 'hp_avl_zone', + os_account_meta_temp_url_key: 'os_account_meta_temp_url_key', + ibm_username: 'ibm_username', + ibm_password: 'ibm_password', + joyent_username: 'joyentuser', + joyent_password: 'joyentpass', + linode_api_key: 'linode_api_key', + local_root: '~/.fog', + bare_metal_cloud_password: 'bare_metal_cloud_password', + bare_metal_cloud_username: 'bare_metal_cloud_username', + ninefold_compute_key: 'ninefold_compute_key', + ninefold_compute_secret: 'ninefold_compute_secret', + ninefold_storage_secret: 'ninefold_storage_secret', + ninefold_storage_token: 'ninefold_storage_token', +# public_key_path: '~/.ssh/id_rsa.pub', +# private_key_path: '~/.ssh/id_rsa', + opennebula_endpoint: 'http://opennebula:2633/RPC2', + opennebula_username: 'oneadmin', + opennebula_password: 'oneadmin', + openstack_api_key: 'openstack_api_key', + openstack_username: 'openstack_username', + openstack_tenant: 'openstack_tenant', + openstack_auth_url: 'http://openstack:35357/v2.0/tokens', + ovirt_url: 'http://ovirt:8080/api', + ovirt_username: 'admin@internal', + ovirt_password: '123123', + profitbricks_username: 'profitbricks_username', + profitbricks_password: 'profitbricks_password', + libvirt_uri: 'qemu://libvirt/system', + rackspace_api_key: 'rackspace_api_key', + rackspace_region: 'dfw', + rackspace_username: 'rackspace_username', + riakcs_access_key_id: 'riakcs_access_key_id', + riakcs_secret_access_key: 'riakcs_secret_access_key', + sakuracloud_api_token: 'sakuracloud_api_token', + sakuracloud_api_token_secret: 'sakuracloud_api_token_secret', + storm_on_demand_username: 'storm_on_demand_username', + storm_on_demand_password: 'storm_on_demand_password', + vcloud_host: 'vcloud_host', + vcloud_password: 'vcloud_password', + vcloud_username: 'vcloud_username', + vcloud_director_host: 'vcloud-director-host', + vcloud_director_password: 'vcloud_director_password', + vcloud_director_username: 'vcd_user@vcd_org_name', + zerigo_email: 'zerigo_email', + zerigo_token: 'zerigo_token', + dynect_customer: 'dynect_customer', + dynect_username: 'dynect_username', + dynect_password: 'dynect_password', + vsphere_server: 'virtualcenter.lan', + vsphere_username: 'apiuser', + vsphere_password: 'apipassword', + vsphere_expected_pubkey_hash: 'abcdef1234567890', + libvirt_username: 'root', + libvirt_password: 'password', + cloudsigma_username: 'csuname', + cloudsigma_password: 'cspass', + docker_username: 'docker-fan', + docker_password: 'i<3docker', + docker_email: 'dockerfan@gmail.com', + docker_url: 'unix://var/run/docker.sock' }.merge(Fog.credentials) end diff --git a/tests/helpers/model_helper.rb b/tests/helpers/model_helper.rb index e026a7b32..5e1d74eef 100644 --- a/tests/helpers/model_helper.rb +++ b/tests/helpers/model_helper.rb @@ -1,9 +1,8 @@ def model_tests(collection, params = {}, mocks_implemented = true) tests('success') do - @instance = collection.new(params) - tests("#save").succeeds do + tests('#save').succeeds do pending if Fog.mocking? && !mocks_implemented @instance.save end @@ -12,7 +11,7 @@ def model_tests(collection, params = {}, mocks_implemented = true) yield(@instance) end - tests("#destroy").succeeds do + tests('#destroy').succeeds do pending if Fog.mocking? && !mocks_implemented @instance.destroy end @@ -26,6 +25,6 @@ end # E.g. 'fog-test-1234' def uniq_id(base_name = 'fog-test') # random_differentiator - suffix = rand(65536).to_s(16).rjust(4, '0') - [base_name, suffix] * '-' + suffix = rand(65_536).to_s(16).rjust(4, '0') + [base_name, suffix].join('-') end diff --git a/tests/helpers/responds_to_helper.rb b/tests/helpers/responds_to_helper.rb index 598270095..08529f6b1 100644 --- a/tests/helpers/responds_to_helper.rb +++ b/tests/helpers/responds_to_helper.rb @@ -1,7 +1,7 @@ module Shindo class Tests 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 @instance.respond_to?(method_name) end diff --git a/tests/helpers/schema_validator_tests.rb b/tests/helpers/schema_validator_tests.rb index 8715af391..38ae5e5bb 100644 --- a/tests/helpers/schema_validator_tests.rb +++ b/tests/helpers/schema_validator_tests.rb @@ -1,37 +1,37 @@ +# frozen_string_literal: true + Shindo.tests('Fog::Schema::DataValidator', 'meta') do validator = Fog::Schema::DataValidator.new tests('#validate') do - tests('returns true') do - returns(true, 'when value matches schema expectation') do - validator.validate({"key" => "Value"}, {"key" => String}) + validator.validate({ 'key' => 'Value' }, 'key' => String) end 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 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 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 returns(true, 'when collection is empty although schema covers optional members') do - validator.validate([], [{"key" => String}]) + validator.validate([], [{ 'key' => String }]) end 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 returns(true, 'when value is nil and schema expects NilClass') do - validator.validate({"key" => nil}, {"key" => NilClass}) + validator.validate({ 'key' => nil }, 'key' => NilClass) end returns(true, 'when value and schema match as hashes') do @@ -43,43 +43,41 @@ Shindo.tests('Fog::Schema::DataValidator', 'meta') do end returns(true, 'when value is a Time') do - validator.validate({"time" => Time.now}, {"time" => Time}) + validator.validate({ 'time' => Time.now }, 'time' => Time) end 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 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 tests('returns false') do - returns(false, 'when value does not match schema expectation') do - validator.validate({"key" => nil}, {"key" => String}) + validator.validate({ 'key' => nil }, 'key' => String) end returns(false, 'when key formats do not match') do - validator.validate({"key" => "Value"}, {:key => String}) + validator.validate({ 'key' => 'Value' }, key: String) end returns(false, 'when additional keys are passed and strict') do - validator.validate({"key" => "Missing"}, {}) + validator.validate({ 'key' => 'Missing' }, {}) end returns(false, 'when some keys do not appear') do - validator.validate({}, {"key" => String}) + validator.validate({}, 'key' => String) end 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 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 returns(false, 'when hash and array are compared') do @@ -91,17 +89,16 @@ Shindo.tests('Fog::Schema::DataValidator', 'meta') do end 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 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 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 diff --git a/tests/helpers/succeeds_helper.rb b/tests/helpers/succeeds_helper.rb index b54589e3a..9e506ffdc 100644 --- a/tests/helpers/succeeds_helper.rb +++ b/tests/helpers/succeeds_helper.rb @@ -2,7 +2,7 @@ module Shindo class Tests def succeeds test('succeeds') do - !!instance_eval(&Proc.new) + !instance_eval(&Proc.new).nil? end end end diff --git a/tests/parsers/compute/describe_images_tests.rb b/tests/parsers/compute/describe_images_tests.rb index 12843955c..cc43aa172 100644 --- a/tests/parsers/compute/describe_images_tests.rb +++ b/tests/parsers/compute/describe_images_tests.rb @@ -24,7 +24,7 @@ DESCRIBE_IMAGES_RESULT = <<-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 parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::Compute::DescribeImages.new) parser.parse(DESCRIBE_IMAGES_RESULT) diff --git a/tests/parsers/elb/describe_load_balancers.rb b/tests/parsers/elb/describe_load_balancers.rb index 115dbeffa..c69d7ab9c 100644 --- a/tests/parsers/elb/describe_load_balancers.rb +++ b/tests/parsers/elb/describe_load_balancers.rb @@ -56,7 +56,7 @@ xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/"> 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 parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new) parser.parse(DESCRIBE_LOAD_BALANCERS_RESULT) diff --git a/tests/signaturev4_tests.rb b/tests/signaturev4_tests.rb index af155cfbd..8887d4dcb 100644 --- a/tests/signaturev4_tests.rb +++ b/tests/signaturev4_tests.rb @@ -1,81 +1,80 @@ # encoding: utf-8 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 - @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 - 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' end end 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' end end 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' end end 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' end end 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' end end 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 => '/', - :body => 'foo=bar'}, @now)) 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: '/', + body: 'foo=bar' }, @now)) do 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=content-type;date;host, Signature=b105eb10c6d318d2294de9d49dd8b031b55e3c3fe139f2e637da70511e9e7b71' end end 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' end end 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' end end 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' end end 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' end end 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' end end - 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 + 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 { 'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256', 'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request', @@ -85,8 +84,8 @@ Shindo.tests('AWS | signaturev4', ['aws']) do end end - 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 + 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 { 'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256', 'X-Amz-Credential' => 'AKIDEXAMPLE/20110909/us-east-1/host/aws4_request', @@ -96,9 +95,9 @@ Shindo.tests('AWS | signaturev4', ['aws']) do end end - tests("s3 signer does not normalize path") do - 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 + tests('s3 signer does not normalize path') do + 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 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/s3/aws4_request, SignedHeaders=date;host, Signature=72407ad06b8e5750360f42e8aad9f33a0be363bcfeecdcae0aea58c99709fb4a' end end diff --git a/tests/signed_params_tests.rb b/tests/signed_params_tests.rb index 64b9a9f90..6541294b0 100644 --- a/tests/signed_params_tests.rb +++ b/tests/signed_params_tests.rb @@ -1,17 +1,17 @@ # encoding: utf-8 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 - unicode = ["00E9".to_i(16)].pack("U*") - escaped = "%C3%A9" - returns( escaped ) { Fog::AWS.escape( unicode ) } + unicode = ['00E9'.to_i(16)].pack('U*') + escaped = '%C3%A9' + returns(escaped) { Fog::AWS.escape(unicode) } end tests('Unicode characters with combining marks should be escaped') do - unicode = ["0065".to_i(16), "0301".to_i(16)].pack("U*") - escaped = "e%CC%81" - returns( escaped ) { Fog::AWS.escape( unicode ) } + unicode = ['0065'.to_i(16), '0301'.to_i(16)].pack('U*') + escaped = 'e%CC%81' + returns(escaped) { Fog::AWS.escape(unicode) } end end diff --git a/tests/storage_tests.rb b/tests/storage_tests.rb index a8a307a1d..7567d2ace 100644 --- a/tests/storage_tests.rb +++ b/tests/storage_tests.rb @@ -2,6 +2,6 @@ Shindo.tests('AWS Storage | escape', ['aws']) 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