浏览代码

Fixes to use of ActionParams rather than hash (undefined Map for AC)

Yoann Jaspar 6 年之前
父节点
当前提交
8cd2659c0f
共有 2 个文件被更改,包括 7 次插入4 次删除
  1. 1 0
      lib/shopify_api/session.rb
  2. 6 4
      test/session_test.rb

+ 1 - 0
lib/shopify_api/session.rb

@@ -51,6 +51,7 @@ module ShopifyAPI
       end
       end
 
 
       def validate_signature(params)
       def validate_signature(params)
+        params = (params.respond_to?(:to_unsafe_hash) ? params.to_unsafe_hash : 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))

+ 6 - 4
test/session_test.rb

@@ -216,7 +216,8 @@ class SessionTest < Test::Unit::TestCase
   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 = { 'code' => 'any-code', 'timestamp' => Time.now }
     params[:hmac] = generate_signature(params)
     params[:hmac] = generate_signature(params)
-    assert_equal true, ShopifyAPI::Session.validate_signature(params)
+    action_params = ActionController::Parameters.new params
+    assert_equal true, ShopifyAPI::Session.validate_signature(action_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
@@ -224,7 +225,8 @@ class SessionTest < Test::Unit::TestCase
     params = { 'a' => '1&b=2', 'c=3&d' => '4' }
     params = { 'a' => '1&b=2', 'c=3&d' => '4' }
     to_sign = 'a=1%26b=2&c%3D3%26d=4'
     to_sign = 'a=1%26b=2&c%3D3%26d=4'
     params[:hmac] = generate_signature(to_sign)
     params[:hmac] = generate_signature(to_sign)
-    assert_equal true, ShopifyAPI::Session.validate_signature(params)
+    action_params = ActionController::Parameters.new params
+    assert_equal true, ShopifyAPI::Session.validate_signature(action_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
@@ -232,8 +234,8 @@ class SessionTest < Test::Unit::TestCase
     params = { 'a%3D1%26b' => '2%26c%3D3' }
     params = { 'a%3D1%26b' => '2%26c%3D3' }
     to_sign = 'a%253D1%2526b=2%2526c%253D3'
     to_sign = 'a%253D1%2526b=2%2526c%253D3'
     params[:hmac] = generate_signature(to_sign)
     params[:hmac] = generate_signature(to_sign)
-
-    assert_equal true, ShopifyAPI::Session.validate_signature(params)
+    action_params = ActionController::Parameters.new params
+    assert_equal true, ShopifyAPI::Session.validate_signature(action_params)
   end
   end
 
 
   private
   private