mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Removed one more utils reference in the README and fixed directory name
Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
36
tests/notifications_utils/test_url_safe_tokens.py
Normal file
36
tests/notifications_utils/test_url_safe_tokens.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import urllib
|
||||
|
||||
from itsdangerous import BadSignature, SignatureExpired
|
||||
from pytest import fail
|
||||
|
||||
from notifications_utils.url_safe_token import check_token, generate_token
|
||||
|
||||
|
||||
def test_should_return_payload_from_signed_token():
|
||||
payload = "email@something.com"
|
||||
token = generate_token(payload, "secret-key", "dangerous-salt")
|
||||
token = urllib.parse.unquote(token)
|
||||
assert payload == check_token(token, "secret-key", "dangerous-salt", 30)
|
||||
|
||||
|
||||
def test_should_throw_exception_when_token_is_tampered_with():
|
||||
import uuid
|
||||
|
||||
token = generate_token(str(uuid.uuid4()), "secret-key", "dangerous-salt")
|
||||
try:
|
||||
check_token(token + "qerqwer", "secret-key", "dangerous-salt", 30)
|
||||
fail()
|
||||
except BadSignature:
|
||||
pass
|
||||
|
||||
|
||||
def test_return_none_when_token_is_expired():
|
||||
max_age = -1000
|
||||
payload = "some_payload"
|
||||
token = generate_token(payload, "secret-key", "dangerous-salt")
|
||||
token = urllib.parse.unquote(token)
|
||||
try:
|
||||
assert check_token(token, "secret-key", "dangerous-salt", max_age) is None
|
||||
fail("Expected a SignatureExpired exception")
|
||||
except SignatureExpired:
|
||||
pass
|
||||
Reference in New Issue
Block a user