-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
allowed_drift
config option, pass to use Guardian
, note in RE…
…ADME (#63) * session tokens encoded on client may have future `nbf` value * Guardian correctly returns `{:error, :token_not_yet_valid}` * Shopify-official python package added 10s of "leeway": Shopify/shopify_python_api#609
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Shopifex.GuardianTest do | ||
use ExUnit.Case | ||
|
||
describe "allowed_drift defaults" do | ||
test "accepts tokens with nbf up to 10s in the future" do | ||
future = | ||
DateTime.utc_now() | ||
|> DateTime.add(9) | ||
|> DateTime.to_unix() | ||
|
||
{:ok, jwt} = Guardian.Token.Jwt.create_token(Shopifex.Guardian, %{"nbf" => future}) | ||
|
||
assert {:ok, _claims} = Shopifex.Guardian.decode_and_verify(jwt) | ||
end | ||
|
||
test "accepts tokens with exp up to 10s in the past" do | ||
past = | ||
DateTime.utc_now() | ||
|> DateTime.add(-9) | ||
|> DateTime.to_unix() | ||
|
||
{:ok, jwt} = Guardian.Token.Jwt.create_token(Shopifex.Guardian, %{"exp" => past}) | ||
|
||
assert {:ok, _claims} = Shopifex.Guardian.decode_and_verify(jwt) | ||
end | ||
|
||
test "rejects tokens with nbf more than 10s in the future" do | ||
future = | ||
DateTime.utc_now() | ||
|> DateTime.add(11) | ||
|> DateTime.to_unix() | ||
|
||
{:ok, jwt} = Guardian.Token.Jwt.create_token(Shopifex.Guardian, %{"nbf" => future}) | ||
|
||
assert {:error, :token_not_yet_valid} = Shopifex.Guardian.decode_and_verify(jwt) | ||
end | ||
|
||
test "rejects tokens with exp more than 10s in the past" do | ||
past = | ||
DateTime.utc_now() | ||
|> DateTime.add(-11) | ||
|> DateTime.to_unix() | ||
|
||
{:ok, jwt} = Guardian.Token.Jwt.create_token(Shopifex.Guardian, %{"exp" => past}) | ||
|
||
assert {:error, :token_expired} = Shopifex.Guardian.decode_and_verify(jwt) | ||
end | ||
end | ||
end |