diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3d4091..3c9e844 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,10 +19,10 @@ jobs: - gemfiles/faraday_0.15.gemfile - gemfiles/faraday_0.16.gemfile - gemfiles/faraday_0.17.gemfile - + - gemfiles/faraday_1.0.gemfile steps: - uses: actions/checkout@v2 - - uses: actions/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - uses: actions/cache@v2 @@ -31,20 +31,28 @@ jobs: key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles('faraday_middleware-aws-sigv4.gemspec', '**/Gemfile', '${{ matrix.gemfile }}') }} restore-keys: | ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}- - - name: Setup dependencies run: | bundle config path vendor/bundle bundle install env: BUNDLE_GEMFILE: ${{ matrix.gemfile }} - - name: Run tests run: ${{ matrix.env }} bundle exec rake env: BUNDLE_GEMFILE: ${{ matrix.gemfile }} - - - name: Coveralls GitHub Action + - name: Coveralls Parallel + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: run-${{ matrix.ruby }}-${{ matrix.env }}-${{ matrix.gemfile }} + parallel: true + finish: + needs: build + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..652b1c3 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,16 @@ +AllCops: + Exclude: + - 'gemfiles/**/*' + TargetRubyVersion: 2.4 + NewCops: enable +Bundler/OrderedGems: + Include: + - 'Appraisals' +Metrics/BlockLength: + Enabled: false +Layout/LineLength: + Enabled: false +Metrics/MethodLength: + Enabled: false +Style/Documentation: + Enabled: false diff --git a/.simplecov b/.simplecov index 2c60eb6..c350579 100644 --- a/.simplecov +++ b/.simplecov @@ -1,4 +1,6 @@ +# frozen_string_literal: true + SimpleCov.start do # exclude directories and files - add_filter "/spec/" + add_filter '/spec/' end diff --git a/Appraisals b/Appraisals index 7d2f06d..0d768bf 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise 'faraday-0.15' do gem 'faraday', '~> 0.15.0' end diff --git a/Gemfile b/Gemfile index ec1ce2c..8ae2f52 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in faraday_middleware-aws-sigv4.gemspec diff --git a/Rakefile b/Rakefile index 93cb943..a2c92fd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,13 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' +require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :spec +RuboCop::RakeTask.new do |task| + task.options = %w[-c .rubocop.yml] +end + +task default: %i[rubocop spec] diff --git a/bin/console b/bin/console deleted file mode 100755 index 7264b67..0000000 --- a/bin/console +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env ruby - -require "bundler/setup" -require "faraday_middleware/aws/sigv4" - -# You can add fixtures and/or initialization code here to make experimenting -# with your gem easier. You can also use a different console, if you like. - -# (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" -# Pry.start - -require "irb" -IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup deleted file mode 100755 index dce67d8..0000000 --- a/bin/setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -IFS=$'\n\t' -set -vx - -bundle install - -# Do any other automated setup that you need to do here diff --git a/faraday_middleware-aws-sigv4.gemspec b/faraday_middleware-aws-sigv4.gemspec index 86b4bb0..5beb3be 100644 --- a/faraday_middleware-aws-sigv4.gemspec +++ b/faraday_middleware-aws-sigv4.gemspec @@ -1,5 +1,6 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| @@ -8,8 +9,8 @@ Gem::Specification.new do |spec| spec.authors = ['Genki Sugawara'] spec.email = ['sugawara@cookpad.com'] - spec.summary = %q{Faraday middleware for AWS Signature Version 4 using aws-sigv4.} - spec.description = %q{Faraday middleware for AWS Signature Version 4 using aws-sigv4.} + spec.summary = 'Faraday middleware for AWS Signature Version 4 using aws-sigv4.' + spec.description = 'Faraday middleware for AWS Signature Version 4 using aws-sigv4.' spec.homepage = 'https://github.com/winebarrel/faraday_middleware-aws-sigv4' spec.license = 'MIT' @@ -20,18 +21,21 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.3' + spec.required_ruby_version = '>= 2.4' - spec.add_dependency 'faraday', '>= 0.15' spec.add_dependency 'aws-sigv4', '~> 1.0' + spec.add_dependency 'faraday', '>= 0.15' - spec.add_development_dependency 'faraday_middleware' + spec.add_development_dependency 'appraisal', '>= 2.2' + spec.add_development_dependency 'aws-sdk-core', '~> 3.14.0' spec.add_development_dependency 'bundler' + spec.add_development_dependency 'faraday_middleware' spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'timecop' - spec.add_development_dependency 'aws-sdk-core', '~> 3.14.0' - spec.add_development_dependency 'appraisal', '>= 2.2' + spec.add_development_dependency 'rubocop', '>= 1.8.0' + spec.add_development_dependency 'rubocop-rake' + spec.add_development_dependency 'rubocop-rspec' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'simplecov-lcov' + spec.add_development_dependency 'timecop' end diff --git a/lib/faraday_middleware/aws_sigv4.rb b/lib/faraday_middleware/aws_sigv4.rb index 6994851..8e1beae 100644 --- a/lib/faraday_middleware/aws_sigv4.rb +++ b/lib/faraday_middleware/aws_sigv4.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware autoload :AwsSigV4, 'faraday_middleware/request/aws_sigv4' - Faraday::Request.register_middleware aws_sigv4: lambda { AwsSigV4 } + Faraday::Request.register_middleware aws_sigv4: -> { AwsSigV4 } end diff --git a/lib/faraday_middleware/request/aws_sigv4.rb b/lib/faraday_middleware/request/aws_sigv4.rb index be093ee..3c3779a 100644 --- a/lib/faraday_middleware/request/aws_sigv4.rb +++ b/lib/faraday_middleware/request/aws_sigv4.rb @@ -1,37 +1,41 @@ +# frozen_string_literal: true + require 'aws-sigv4' require 'faraday_middleware/request/aws_sigv4_util' -class FaradayMiddleware::AwsSigV4 < Faraday::Middleware - include FaradayMiddleware::AwsSigV4Util +module FaradayMiddleware + class AwsSigV4 < Faraday::Middleware + include FaradayMiddleware::AwsSigV4Util - def initialize(app, options = nil) - super(app) - @signer = Aws::Sigv4::Signer.new(options) - @options = options - end + def initialize(app, options = nil) + super(app) + @signer = Aws::Sigv4::Signer.new(options) + @options = options + end - def call(env) - sign!(env) - @app.call(env) - end + def call(env) + sign!(env) + @app.call(env) + end - private + private - def sign!(env) - request = build_aws_sigv4_request(env) - signature = @signer.sign_request(request) + def sign!(env) + request = build_aws_sigv4_request(env) + signature = @signer.sign_request(request) - signature.headers.each do |name, value| - env.request_headers[name] = value + signature.headers.each do |name, value| + env.request_headers[name] = value + end end - end - def build_aws_sigv4_request(env) - { - http_method: env.method.to_s, - url: seahorse_encode_query(env.url), - headers: env.request_headers, - body: env.body, - } + def build_aws_sigv4_request(env) + { + http_method: env.method.to_s, + url: seahorse_encode_query(env.url), + headers: env.request_headers, + body: env.body + } + end end end diff --git a/lib/faraday_middleware/request/aws_sigv4_util.rb b/lib/faraday_middleware/request/aws_sigv4_util.rb index 5a7237d..4ddfdba 100644 --- a/lib/faraday_middleware/request/aws_sigv4_util.rb +++ b/lib/faraday_middleware/request/aws_sigv4_util.rb @@ -1,32 +1,36 @@ -module FaradayMiddleware::AwsSigV4Util - def seahorse_encode_query(url) - return url unless url.query +# frozen_string_literal: true - params = URI.decode_www_form(url.query) +module FaradayMiddleware + module AwsSigV4Util + def seahorse_encode_query(url) + return url unless url.query - if params.any? {|_, v| v[?\s] } - url = url.dup - url.query = seahorse_encode_www_form(params) - end + params = URI.decode_www_form(url.query) - url - end + if params.any? { |_, v| v["\s"] } + url = url.dup + url.query = seahorse_encode_www_form(params) + end - def seahorse_encode_www_form(params) - params.flat_map {|key, value| - encoded_key = URI.encode_www_form_component(key) + url + end - if value.nil? - encoded_key - else - Array(value).map do |v| - if v.nil? - # nothing to do - else - encoded_key + '=' + Aws::Sigv4::Signer.uri_escape(v) + def seahorse_encode_www_form(params) + params.flat_map do |key, value| + encoded_key = URI.encode_www_form_component(key) + + if value.nil? + encoded_key + else + Array(value).map do |v| + if v.nil? + # nothing to do + else + "#{encoded_key}=#{Aws::Sigv4::Signer.uri_escape(v)}" + end end end - end - }.join(?&) + end.join('&') + end end end diff --git a/spec/faraday_middleware/aws_sigv4_instance_profile_credentials_spec.rb b/spec/faraday_middleware/aws_sigv4_instance_profile_credentials_spec.rb index 4b11ae6..acdd5d9 100644 --- a/spec/faraday_middleware/aws_sigv4_instance_profile_credentials_spec.rb +++ b/spec/faraday_middleware/aws_sigv4_instance_profile_credentials_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe FaradayMiddleware::AwsSigV4 do - def faraday(options = {}) + def faraday(options = {}, &block) options = { url: 'https://apigateway.us-east-1.amazonaws.com' }.merge(options) @@ -8,47 +10,45 @@ def faraday(options = {}) aws_sigv4_options = { service: 'apigateway', region: 'us-east-1', - credentials_provider: Aws::InstanceProfileCredentials.new, + credentials_provider: Aws::InstanceProfileCredentials.new } faraday.request :aws_sigv4, aws_sigv4_options - faraday.response :json, :content_type => /\bjson\b/ + faraday.response :json, content_type: /\bjson\b/ - faraday.adapter(:test, Faraday::Adapter::Test::Stubs.new) do |stub| - yield(stub) - end + faraday.adapter(:test, Faraday::Adapter::Test::Stubs.new, &block) end end let(:response) do - {'accountUpdate'=> - {'name'=>nil, - 'template'=>false, - 'templateSkipList'=>nil, - 'title'=>nil, - 'updateAccountInput'=>nil}, - 'cloudwatchRoleArn'=>nil, - 'self'=> - {'__type'=> + { 'accountUpdate' => + { 'name' => nil, + 'template' => false, + 'templateSkipList' => nil, + 'title' => nil, + 'updateAccountInput' => nil }, + 'cloudwatchRoleArn' => nil, + 'self' => + { '__type' => 'GetAccountRequest:http://internal.amazon.com/coral/com.amazonaws.backplane.controlplane/', - 'name'=>nil, - 'template'=>false, - 'templateSkipList'=>nil, - 'title'=>nil}, - 'throttleSettings'=>{'burstLimit'=>1000, 'rateLimit'=>500.0}} + 'name' => nil, + 'template' => false, + 'templateSkipList' => nil, + 'title' => nil }, + 'throttleSettings' => { 'burstLimit' => 1000, 'rateLimit' => 500.0 } } end let(:expected_headers) do - {'User-Agent'=>"Faraday v#{Faraday::VERSION}", - 'host'=>'apigateway.us-east-1.amazonaws.com', - 'x-amz-content-sha256'=> - 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'} + { 'User-Agent' => "Faraday v#{Faraday::VERSION}", + 'host' => 'apigateway.us-east-1.amazonaws.com', + 'x-amz-content-sha256' => + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' } end let(:authz_tmpl) do - 'AWS4-HMAC-SHA256 Credential=%{access_key_id}/20150101/us-east-1/apigateway/aws4_request, ' + - "SignedHeaders=host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-security-token, " + - "Signature=%{signature}" + 'AWS4-HMAC-SHA256 Credential=%s/20150101/us-east-1/apigateway/aws4_request, ' \ + 'SignedHeaders=host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-security-token, ' \ + 'Signature=%s' end before do @@ -56,11 +56,11 @@ def faraday(options = {}) allow_any_instance_of(Aws::InstanceProfileCredentials).to receive(:get_credentials) { JSON.dump({ - 'AccessKeyId' => "akid#{Time.now.to_i}", - 'SecretAccessKey' => "secret#{Time.now.to_i}", - 'Token' => "token#{Time.now.to_i}", - 'Expiration' => Time.now + 3600, - }) + 'AccessKeyId' => "akid#{Time.now.to_i}", + 'SecretAccessKey' => "secret#{Time.now.to_i}", + 'Token' => "token#{Time.now.to_i}", + 'Expiration' => Time.now + 3600 + }) } end @@ -70,26 +70,24 @@ def faraday(options = {}) client = faraday do |stub| stub.get('/account') do |env| account_headers = env.request_headers - [200, {'Content-Type' => 'application/json'}, JSON.dump(response)] + [200, { 'Content-Type' => 'application/json' }, JSON.dump(response)] end end expect(client.get('/account').body).to eq response expect(account_headers).to include expected_headers.update( - 'x-amz-date' => '20150101T000000Z', - 'x-amz-security-token' => 'token1420070400', + 'x-amz-date' => '20150101T000000Z', + 'x-amz-security-token' => 'token1420070400' ) - expect(account_headers.fetch('authorization')).to match Regexp.new(authz_tmpl % { - access_key_id: 'akid1420070400', - signature: '(' + %w( - 8a7679e7f6e14faa3c5bc8e585f16416bba04883767b651169f745e987908c04 - 0593f7578c038c94d3d463d5b1ed0fa8b4c4f5525c7abb08ae6c095d9df5fb61 - bb9d431b7be57abce9d81b4b4fd62036eec4d9d4e9dc44ad95b1166a8b16c3f4 - 3dd176d303ac2227e8522eb13413670657821280569556d289047e6ae2ccd975 - ).join('|') + ')', - }) + expect(account_headers.fetch('authorization')).to match Regexp.new(format(authz_tmpl, access_key_id: 'akid1420070400', signature: "(#{%w[ + 8a7679e7f6e14faa3c5bc8e585f16416bba04883767b651169f745e987908c04 + 0593f7578c038c94d3d463d5b1ed0fa8b4c4f5525c7abb08ae6c095d9df5fb61 + bb9d431b7be57abce9d81b4b4fd62036eec4d9d4e9dc44ad95b1166a8b16c3f4 + 3dd176d303ac2227e8522eb13413670657821280569556d289047e6ae2ccd975 + 14af79b17c4e94c9582512125daa97f19b19b04d0b8d605d68a02bded3948770 + ].join('|')})")) # 50 minutes after Timecop.travel(Time.now + 3000) @@ -97,19 +95,17 @@ def faraday(options = {}) expect(client.get('/account').body).to eq response expect(account_headers).to include expected_headers.update( - 'x-amz-date' => '20150101T005000Z', - 'x-amz-security-token' => 'token1420070400', + 'x-amz-date' => '20150101T005000Z', + 'x-amz-security-token' => 'token1420070400' ) - expect(account_headers.fetch('authorization')).to match Regexp.new(authz_tmpl % { - access_key_id: 'akid1420070400', - signature: '(' + %w( - 936d7c18c31135cb0baebe62ada628644a4c24efcadce044ceb650bc04e3fe1d - 891f865c1a1297ed133589cd2abb575fd998b66cf79a0505941f50ef3405576b - 816c7f811b60426fb2cd232ae3a5c6568f5150058bdaa99e3233b61fe8ab7668 - 053ed3702ade746b97a3aeba3f4bfdd06154b0c7d0cc50fa9ba3db81385f6110 - ).join('|') + ')', - }) + expect(account_headers.fetch('authorization')).to match Regexp.new(format(authz_tmpl, access_key_id: 'akid1420070400', signature: "(#{%w[ + 936d7c18c31135cb0baebe62ada628644a4c24efcadce044ceb650bc04e3fe1d + 891f865c1a1297ed133589cd2abb575fd998b66cf79a0505941f50ef3405576b + 816c7f811b60426fb2cd232ae3a5c6568f5150058bdaa99e3233b61fe8ab7668 + 053ed3702ade746b97a3aeba3f4bfdd06154b0c7d0cc50fa9ba3db81385f6110 + 8ac6851c02183ca987e91116262c9afe24662aff4a7f2dcb67b8d9212cd2d4ba + ].join('|')})")) # 10 minutes after Timecop.travel(Time.now + 600) @@ -117,18 +113,16 @@ def faraday(options = {}) expect(client.get('/account').body).to eq response expect(account_headers).to include expected_headers.update( - 'x-amz-date' => '20150101T010000Z', - 'x-amz-security-token' => 'token1420074000', + 'x-amz-date' => '20150101T010000Z', + 'x-amz-security-token' => 'token1420074000' ) - expect(account_headers.fetch('authorization')).to match Regexp.new(authz_tmpl % { - access_key_id: 'akid1420074000', - signature: '(' + %w( - 42b4050c22d246f66c13357186a87bb2891ea0bebf7663cec398f9a12d869133 - f264df5cb2359d8b9d491ff48bd57237d9260f01ebf638455ca18c3dab8beb2d - 7e8b319cb3ab3d36bd4a6b34d411c03f88891d2266adcc9498573c4ee33d2088 - dca2842cb07926a4929af3708165ca2897207ca729cab19c1deb518d5d492848 - ).join('|') + ')', - }) + expect(account_headers.fetch('authorization')).to match Regexp.new(format(authz_tmpl, access_key_id: 'akid1420074000', signature: "(#{%w[ + 42b4050c22d246f66c13357186a87bb2891ea0bebf7663cec398f9a12d869133 + f264df5cb2359d8b9d491ff48bd57237d9260f01ebf638455ca18c3dab8beb2d + 7e8b319cb3ab3d36bd4a6b34d411c03f88891d2266adcc9498573c4ee33d2088 + dca2842cb07926a4929af3708165ca2897207ca729cab19c1deb518d5d492848 + c17ee288dfc7e4598e333765b85e0305959ba33835453b7c2885b7d43aabb4f2 + ].join('|')})")) end end diff --git a/spec/faraday_middleware/aws_sigv4_spec.rb b/spec/faraday_middleware/aws_sigv4_spec.rb index 6555c84..1b18199 100644 --- a/spec/faraday_middleware/aws_sigv4_spec.rb +++ b/spec/faraday_middleware/aws_sigv4_spec.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe FaradayMiddleware::AwsSigV4 do - def faraday(options = {}) + def faraday(options = {}, &block) options = { url: 'https://apigateway.us-east-1.amazonaws.com' }.merge(options) @@ -9,34 +11,32 @@ def faraday(options = {}) service: 'apigateway', region: 'us-east-1', access_key_id: 'akid', - secret_access_key: 'secret', + secret_access_key: 'secret' } faraday.request :aws_sigv4, aws_sigv4_options - faraday.response :json, :content_type => /\bjson\b/ + faraday.response :json, content_type: /\bjson\b/ - faraday.adapter(:test, Faraday::Adapter::Test::Stubs.new) do |stub| - yield(stub) - end + faraday.adapter(:test, Faraday::Adapter::Test::Stubs.new, &block) end end let(:response) do - {'accountUpdate'=> - {'name'=>nil, - 'template'=>false, - 'templateSkipList'=>nil, - 'title'=>nil, - 'updateAccountInput'=>nil}, - 'cloudwatchRoleArn'=>nil, - 'self'=> - {'__type'=> + { 'accountUpdate' => + { 'name' => nil, + 'template' => false, + 'templateSkipList' => nil, + 'title' => nil, + 'updateAccountInput' => nil }, + 'cloudwatchRoleArn' => nil, + 'self' => + { '__type' => 'GetAccountRequest:http://internal.amazon.com/coral/com.amazonaws.backplane.controlplane/', - 'name'=>nil, - 'template'=>false, - 'templateSkipList'=>nil, - 'title'=>nil}, - 'throttleSettings'=>{'burstLimit'=>1000, 'rateLimit'=>500.0}} + 'name' => nil, + 'template' => false, + 'templateSkipList' => nil, + 'title' => nil }, + 'throttleSettings' => { 'burstLimit' => 1000, 'rateLimit' => 500.0 } } end let(:signed_headers) do @@ -44,15 +44,15 @@ def faraday(options = {}) end let(:default_expected_headers) do - {'User-Agent'=>"Faraday v#{Faraday::VERSION}", - 'host'=>'apigateway.us-east-1.amazonaws.com', - 'x-amz-date'=>'20150101T000000Z', - 'x-amz-content-sha256'=> + { 'User-Agent' => "Faraday v#{Faraday::VERSION}", + 'host' => 'apigateway.us-east-1.amazonaws.com', + 'x-amz-date' => '20150101T000000Z', + 'x-amz-content-sha256' => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', - 'authorization'=> - 'AWS4-HMAC-SHA256 Credential=akid/20150101/us-east-1/apigateway/aws4_request, ' + - "SignedHeaders=#{signed_headers}, " + - "Signature=#{signature}"} + 'authorization' => + 'AWS4-HMAC-SHA256 Credential=akid/20150101/us-east-1/apigateway/aws4_request, ' \ + "SignedHeaders=#{signed_headers}, " \ + "Signature=#{signature}" } end let(:additional_expected_headers) { {} } @@ -68,19 +68,20 @@ def faraday(options = {}) authorization = expected_headers_without_authorization.delete('authorization') expect(env.request_headers).to include expected_headers_without_authorization expect(env.request_headers.fetch('authorization')).to match Regexp.new(authorization) - [200, {'Content-Type' => 'application/json'}, JSON.dump(response)] + [200, { 'Content-Type' => 'application/json' }, JSON.dump(response)] end end end context 'without query' do let(:signature) do - '(' + %w( + "(#{%w[ 4029fcbe5aae50c588651d5a587f4a9fd2b7ba25bc03e1ce57432c758d1a7816 024535e1dd5a9f9eb5a8d2eb99c64678766ad6059bdd51ad85d282f49bd20700 f15f7c05bba9addb232e39282ea70a7a7c7f2c52dffd4aafe6cc8226fb82d5ab f4299dc8cdf28ee680bb882712daf8fac89c1bcfd46f28549bd37b9412d18b72 - ).join('|') + ')' + afb745a953d7e80be81d81ed5425a0a7340cea4d8baf42470bd2c0cda14e5103 + ].join('|')})" end subject { client.get('/account').body } @@ -92,29 +93,31 @@ def faraday(options = {}) context 'include space' do let(:signature) do - '(' + %w( + "(#{%w[ 75bb1b4dbbf7b7a502ecb574abfcc2e12ce115da07f876d3b66fd3ff0ad427fd f0a9030e2e15012d61af8b708ad358c9a5e5495984162884abf1cb910275223b b13ce117f8258ebc4c157b1d216517f38476d80d6a60ace9374d0ec8d500134d 53df7eeeaec828ce3c8ca011ee35f20ab620fe1d8610ff00e6a57cab642d2436 - ).join('|') + ')' + 51e82ebaf936d6dc7a673723240a954b35ac5992e7da3408e25d14715fe24aca + ].join('|')})" end - let(:params) { {foo: 'b a r', zoo: 'b a z'} } + let(:params) { { foo: 'b a r', zoo: 'b a z' } } it { is_expected.to eq response } end context 'not include space' do let(:signature) do - '(' + %w( + "(#{%w[ 94e01cc599b3eef64cc9e08c5f079b0345d5b9dd95cc14d0ea66fc0c5923bf30 8c58f5f0decfb7f185d290bae83dac382328ba19c862861fd646089ba0083569 115cea2f319d5cf12bd4fa35b8861eaded8037dad4ccc7e8c8929d150ddf3d66 552a531f290603c378a4d01a2a307ba4b356c7e7364ac03b337e80085733b61e - ).join('|') + ')' + 3d61f6bd2c027925d3da79c87a69b5b77b595687a5c06576c2d8ff66db459415 + ].join('|')})" end - let(:params) { {foo: 'bar', zoo: 'baz'} } + let(:params) { { foo: 'bar', zoo: 'baz' } } it { is_expected.to eq response } end end diff --git a/spec/faraday_middleware/aws_sigv4_util_spec.rb b/spec/faraday_middleware/aws_sigv4_util_spec.rb index 39b50f4..1207d70 100644 --- a/spec/faraday_middleware/aws_sigv4_util_spec.rb +++ b/spec/faraday_middleware/aws_sigv4_util_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe FaradayMiddleware::AwsSigV4Util do let(:class_with_util) do Class.new do @@ -29,20 +31,20 @@ describe '#seahorse_encode_www_form' do subject do - class_with_util.new.seahorse_encode_www_form(params).split(?&) + class_with_util.new.seahorse_encode_www_form(params).split('&') end context 'not include space' do let(:params) do [ - ['foo', 'bar'], - ['bar', ['zoo', 'baz']], + %w[foo bar], + ['bar', %w[zoo baz]], ['baz', nil], - ['zoo', [nil, 'baz']], + ['zoo', [nil, 'baz']] ] end - it { is_expected.to match_array URI.encode_www_form(params).split(?&) } + it { is_expected.to match_array URI.encode_www_form(params).split('&') } end context 'include space' do @@ -51,11 +53,11 @@ ['foo', 'b a r'], ['bar', ['z o o', 'baz']], ['baz', nil], - ['zoo', [nil, 'baz']], + ['zoo', [nil, 'baz']] ] end - it { is_expected.to match_array URI.encode_www_form(params).gsub(?+, '%20').split(?&) } + it { is_expected.to match_array URI.encode_www_form(params).gsub('+', '%20').split('&') } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8ce5755..b30be3f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday_middleware' require 'faraday_middleware/aws_sigv4' require 'net/http'