Skip to content

Commit

Permalink
Update jwt#shopify_user_id to return an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed authored and NabeelAhsen committed Nov 6, 2020
1 parent 2401342 commit ca9a806
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/shopify_app/session/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def shopify_domain
end

def shopify_user_id
@payload && @payload['sub']
@payload['sub'].to_i if @payload && @payload['sub']
end

private
Expand Down
14 changes: 11 additions & 3 deletions test/shopify_app/session/jwt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ShopifyApp
class JWTTest < ActiveSupport::TestCase
TEST_SHOPIFY_DOMAIN = 'https://test.myshopify.io'
TEST_SANITIZED_SHOPIFY_DOMAIN = 'test.myshopify.io'
TEST_USER_ID = 'test-user'
TEST_USER_ID = '121'

setup do
ShopifyApp.configuration.api_key = 'api_key'
Expand All @@ -19,7 +19,7 @@ class JWTTest < ActiveSupport::TestCase
jwt = JWT.new(token(p))

assert_equal TEST_SANITIZED_SHOPIFY_DOMAIN, jwt.shopify_domain
assert_equal TEST_USER_ID, jwt.shopify_user_id
assert_equal TEST_USER_ID.to_i, jwt.shopify_user_id
end

test "#shopify_domain and #shopify_user_id are returned using the old secret" do
Expand All @@ -28,7 +28,15 @@ class JWTTest < ActiveSupport::TestCase
jwt = JWT.new(t)

assert_equal TEST_SANITIZED_SHOPIFY_DOMAIN, jwt.shopify_domain
assert_equal TEST_USER_ID, jwt.shopify_user_id
assert_equal TEST_USER_ID.to_i, jwt.shopify_user_id
end

test "#shopify_user_id returns nil if sub is nil on token payload" do
p = payload
p['sub'] = nil
jwt = JWT.new(token(p))

assert_nil jwt.shopify_user_id
end

test "shopify_domain and shopify_user_id are nil if the jwt is invalid" do
Expand Down

0 comments on commit ca9a806

Please sign in to comment.