浏览代码

Merge pull request #468 from yjaspar/master

Fix Rails 5 deprecation warning with_indifferent_access
Rafael França 6 年之前
父节点
当前提交
d63a293cd2
共有 2 个文件被更改,包括 11 次插入11 次删除
  1. 0 1
      lib/shopify_api/session.rb
  2. 11 10
      test/session_test.rb

+ 0 - 1
lib/shopify_api/session.rb

@@ -51,7 +51,6 @@ module ShopifyAPI
       end
       end
 
 
       def validate_signature(params)
       def validate_signature(params)
-        params = params.with_indifferent_access
         return false unless signature = params[:hmac]
         return false unless signature = params[:hmac]
 
 
         calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), secret, encoded_params_for_signature(params))
         calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), secret, encoded_params_for_signature(params))

+ 11 - 10
test/session_test.rb

@@ -214,25 +214,24 @@ class SessionTest < Test::Unit::TestCase
   end
   end
 
 
   test "return true when the signature is valid and the keys of params are strings" do
   test "return true when the signature is valid and the keys of params are strings" do
-    params = {"code" => "any-code", "timestamp" => Time.now}
-    params["hmac"] = generate_signature(params)
+    params = { 'code' => 'any-code', 'timestamp' => Time.now }
+    params[:hmac] = generate_signature(params)
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
   end
   end
 
 
   test "return true when validating signature of params with ampersand and equal sign characters" do
   test "return true when validating signature of params with ampersand and equal sign characters" do
     ShopifyAPI::Session.secret = 'secret'
     ShopifyAPI::Session.secret = 'secret'
-    params = {'a' => '1&b=2', 'c=3&d' => '4'}
-    to_sign = "a=1%26b=2&c%3D3%26d=4"
-    params['hmac'] = generate_signature(to_sign)
-
+    params = { 'a' => '1&b=2', 'c=3&d' => '4' }
+    to_sign = 'a=1%26b=2&c%3D3%26d=4'
+    params[:hmac] = generate_signature(to_sign)
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
   end
   end
 
 
   test "return true when validating signature of params with percent sign characters" do
   test "return true when validating signature of params with percent sign characters" do
     ShopifyAPI::Session.secret = 'secret'
     ShopifyAPI::Session.secret = 'secret'
-    params = {'a%3D1%26b' => '2%26c%3D3'}
-    to_sign = "a%253D1%2526b=2%2526c%253D3"
-    params['hmac'] = generate_signature(to_sign)
+    params = { 'a%3D1%26b' => '2%26c%3D3' }
+    to_sign = 'a%253D1%2526b=2%2526c%253D3'
+    params[:hmac] = generate_signature(to_sign)
 
 
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
     assert_equal true, ShopifyAPI::Session.validate_signature(params)
   end
   end
@@ -240,7 +239,9 @@ class SessionTest < Test::Unit::TestCase
   private
   private
 
 
   def make_sorted_params(params)
   def make_sorted_params(params)
-    sorted_params = params.with_indifferent_access.except(:signature, :hmac, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join('&')
+    params.with_indifferent_access.except(
+      :signature, :hmac, :action, :controller
+    ).collect { |k, v| "#{k}=#{v}" }.sort.join('&')
   end
   end
 
 
   def generate_signature(params)
   def generate_signature(params)