|
@@ -24,6 +24,12 @@ class SessionTest < Test::Unit::TestCase
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ should "raise error if params passed but signature omitted" do
|
|
|
+ assert_raises(RuntimeError) do
|
|
|
+ session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token", {'foo' => 'bar'})
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
should "setup api_key and secret for all sessions" do
|
|
|
ShopifyAPI::Session.setup(:api_key => "My test key", :secret => "My test secret")
|
|
|
assert_equal "My test key", ShopifyAPI::Session.api_key
|
|
@@ -51,5 +57,14 @@ class SessionTest < Test::Unit::TestCase
|
|
|
session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
|
|
|
assert_equal "https://testshop.myshopify.com/admin", session.site
|
|
|
end
|
|
|
+
|
|
|
+ should "raise error if signature does not match expected" do
|
|
|
+ ShopifyAPI::Session.secret = 'secret'
|
|
|
+ params = {:foo => 'hello', :foo => 'world', :timestamp => Time.now}
|
|
|
+ sorted_params = params.except(:signature, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join
|
|
|
+ signature = Digest::MD5.hexdigest(ShopifyAPI::Session.secret + sorted_params)
|
|
|
+
|
|
|
+ session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token", params.merge(:signature => signature))
|
|
|
+ end
|
|
|
end
|
|
|
end
|