|
@@ -117,10 +117,10 @@ class SessionTest < Test::Unit::TestCase
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
params = {:code => 'any-code', :timestamp => Time.now}
|
|
params = {:code => 'any-code', :timestamp => Time.now}
|
|
sorted_params = make_sorted_params(params)
|
|
sorted_params = make_sorted_params(params)
|
|
- signature = Digest::MD5.hexdigest(ShopifyAPI::Session.secret + sorted_params)
|
|
|
|
|
|
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), ShopifyAPI::Session.secret, sorted_params)
|
|
fake nil, :url => 'https://testshop.myshopify.com/admin/oauth/access_token',:method => :post, :body => '{"access_token" : "any-token"}'
|
|
fake nil, :url => 'https://testshop.myshopify.com/admin/oauth/access_token',:method => :post, :body => '{"access_token" : "any-token"}'
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
- token = session.request_token(params.merge(:signature => signature))
|
|
|
|
|
|
+ token = session.request_token(params.merge(:hmac => signature))
|
|
assert_equal "any-token", token
|
|
assert_equal "any-token", token
|
|
end
|
|
end
|
|
|
|
|
|
@@ -128,11 +128,11 @@ class SessionTest < Test::Unit::TestCase
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
params = {:code => "any-code", :timestamp => Time.now}
|
|
params = {:code => "any-code", :timestamp => Time.now}
|
|
sorted_params = make_sorted_params(params)
|
|
sorted_params = make_sorted_params(params)
|
|
- signature = Digest::MD5.hexdigest(ShopifyAPI::Session.secret + sorted_params)
|
|
|
|
|
|
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), ShopifyAPI::Session.secret, sorted_params)
|
|
params[:foo] = 'world'
|
|
params[:foo] = 'world'
|
|
assert_raises(ShopifyAPI::ValidationException) do
|
|
assert_raises(ShopifyAPI::ValidationException) do
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
- session.request_token(params.merge(:signature => signature))
|
|
|
|
|
|
+ session.request_token(params.merge(:hmac => signature))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
@@ -140,11 +140,11 @@ class SessionTest < Test::Unit::TestCase
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
ShopifyAPI::Session.secret = 'secret'
|
|
params = {:code => "any-code", :timestamp => Time.now - 2.days}
|
|
params = {:code => "any-code", :timestamp => Time.now - 2.days}
|
|
sorted_params = make_sorted_params(params)
|
|
sorted_params = make_sorted_params(params)
|
|
- signature = Digest::MD5.hexdigest(ShopifyAPI::Session.secret + sorted_params)
|
|
|
|
|
|
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), ShopifyAPI::Session.secret, sorted_params)
|
|
params[:foo] = 'world'
|
|
params[:foo] = 'world'
|
|
assert_raises(ShopifyAPI::ValidationException) do
|
|
assert_raises(ShopifyAPI::ValidationException) do
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com")
|
|
- session.request_token(params.merge(:signature => signature))
|
|
|
|
|
|
+ session.request_token(params.merge(:hmac => signature))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
@@ -152,8 +152,8 @@ class SessionTest < Test::Unit::TestCase
|
|
now = Time.now
|
|
now = Time.now
|
|
params = {"code" => "any-code", "timestamp" => now}
|
|
params = {"code" => "any-code", "timestamp" => now}
|
|
sorted_params = make_sorted_params(params)
|
|
sorted_params = make_sorted_params(params)
|
|
- signature = Digest::MD5.hexdigest(ShopifyAPI::Session.secret + sorted_params)
|
|
|
|
- params = {"code" => "any-code", "timestamp" => now, "signature" => signature}
|
|
|
|
|
|
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), ShopifyAPI::Session.secret, sorted_params)
|
|
|
|
+ params = {"code" => "any-code", "timestamp" => now, "hmac" => signature}
|
|
|
|
|
|
assert_equal true, ShopifyAPI::Session.validate_signature(params)
|
|
assert_equal true, ShopifyAPI::Session.validate_signature(params)
|
|
end
|
|
end
|
|
@@ -161,7 +161,7 @@ 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, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join
|
|
|
|
|
|
+ sorted_params = params.with_indifferent_access.except(:signature, :hmac, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join('&')
|
|
end
|
|
end
|
|
|
|
|
|
end
|
|
end
|