-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix create_access_token passing hour/minute/second (#14)
* Add tests for create_access_token CLI * Hide pydantic settings missing secrets_dir warning
- Loading branch information
Showing
3 changed files
with
53 additions
and
6 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,33 @@ | ||
from calendar import timegm | ||
from datetime import datetime | ||
|
||
import jose.jwt | ||
from dateutil.tz import UTC | ||
|
||
|
||
def test_create_access_token_default_expiry_time(access_token, capsys): | ||
from dials_rest import auth | ||
from dials_rest.cli import create_access_token | ||
|
||
create_access_token.run(args=[]) | ||
captured = capsys.readouterr() | ||
token = captured.out.strip() | ||
data = jose.jwt.decode(token, auth.SECRET_KEY, algorithms=[auth.ALGORITHM]) | ||
exp = data["exp"] | ||
now = timegm(datetime.utcnow().utctimetuple()) | ||
assert exp - now <= auth.ACCESS_TOKEN_EXPIRE_MINUTES * 60 | ||
|
||
|
||
def test_create_access_token_user_expiry_time(access_token, capsys): | ||
from dials_rest import auth | ||
from dials_rest.cli import create_access_token | ||
|
||
now = timegm(datetime.utcnow().utctimetuple()) | ||
delta = 30 | ||
expiry = datetime.fromtimestamp(now + delta, tz=UTC) | ||
create_access_token.run(args=["--expiry", expiry.isoformat()]) | ||
captured = capsys.readouterr() | ||
token = captured.out.strip() | ||
data = jose.jwt.decode(token, auth.SECRET_KEY, algorithms=[auth.ALGORITHM]) | ||
exp = data["exp"] | ||
assert exp - now <= delta |