Skip to content

Commit

Permalink
Deprecate validate_shop call from JWT class
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Apr 25, 2022
1 parent 6d46c25 commit 259ec46
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## Unreleased

### Fixed

- [#935](https://github.com/Shopify/shopify_api/pull/935) Fix issue [#931](https://github.com/Shopify/shopify_api/pull/931), weight of variant should be float
- [#939](https://github.com/Shopify/shopify_api/pull/939) Hotfix for `.spin.dev` JWT validation.
- [#944](https://github.com/Shopify/shopify_api/pull/944) Deprecated the `validate_shop` method from the JWT class since we can trust the token payload.

## Version 10.0.2

Expand Down
3 changes: 1 addition & 2 deletions lib/shopify_api/auth/jwt_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def initialize(token)

raise ShopifyAPI::Errors::InvalidJwtTokenError,
"Session token had invalid API key" unless @aud == Context.api_key
raise ShopifyAPI::Errors::InvalidJwtTokenError,
"Session token had invalid shop" unless validate_shop(shop)
end

sig { returns(String) }
Expand All @@ -46,6 +44,7 @@ def shop

sig { params(shop: String).returns(T::Boolean) }
def validate_shop(shop)
puts "Deprecation notice: validate_shop will be removed in the next major release."
/\A[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\.(myshopify\.(io|com)|spin\.dev)\z/.match?(shop)
end

Expand Down
9 changes: 0 additions & 9 deletions test/auth/jwt_payload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ def test_decode_jwt_payload_fails_if_not_activated_yet
end
end

def test_decode_jwt_payload_fails_if_domain_is_invalid
payload = @jwt_payload.dup
payload[:dest] = "https://notadomain"
jwt_token = JWT.encode(payload, ShopifyAPI::Context.api_secret_key, "HS256")
assert_raises(ShopifyAPI::Errors::InvalidJwtTokenError) do
ShopifyAPI::Auth::JwtPayload.new(jwt_token)
end
end

def test_decode_jwt_payload_fails_with_invalid_api_key
jwt_token = JWT.encode(@jwt_payload, ShopifyAPI::Context.api_secret_key, "HS256")

Expand Down

0 comments on commit 259ec46

Please sign in to comment.