Prechádzať zdrojové kódy

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

Yoann Jaspar 6 rokov pred
rodič
commit
8cd2659c0f
2 zmenil súbory, kde vykonal 7 pridanie a 4 odobranie
  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
 
       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]
 
         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
     params = { 'code' => 'any-code', 'timestamp' => Time.now }
     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
 
   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' }
     to_sign = 'a=1%26b=2&c%3D3%26d=4'
     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
 
   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' }
     to_sign = 'a%253D1%2526b=2%2526c%253D3'
     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
 
   private