Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jwt#shopify_user_id to return an integer #1103

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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