Localize notification_utils to the admin

This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
Carlo Costino
2024-05-16 10:37:37 -04:00
parent 6bab682edd
commit 9a83ba7475
122 changed files with 49925 additions and 268 deletions

View 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