mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Updated generate_token to use encrypt the entire url.
Created notify_client.sender to hold the methods to send notifications.
This commit is contained in:
0
tests/app/main/notify_client/__init__.py
Normal file
0
tests/app/main/notify_client/__init__.py
Normal file
35
tests/app/main/notify_client/test_sender.py
Normal file
35
tests/app/main/notify_client/test_sender.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from itsdangerous import BadSignature
|
||||
from pytest import fail
|
||||
|
||||
from app.notify_client.sender import generate_token, check_token
|
||||
|
||||
|
||||
def test_should_return_email_from_signed_token(notifications_admin,
|
||||
notifications_admin_db,
|
||||
notify_db_session):
|
||||
email = 'email@something.com'
|
||||
token = generate_token(email)
|
||||
assert email == check_token(token)
|
||||
|
||||
|
||||
def test_should_throw_exception_when_token_is_tampered_with(notifications_admin,
|
||||
notifications_admin_db,
|
||||
notify_db_session):
|
||||
email = 'email@something.com'
|
||||
token = generate_token(email)
|
||||
try:
|
||||
check_token(token + 'qerqwer')
|
||||
fail()
|
||||
except BadSignature:
|
||||
pass
|
||||
|
||||
|
||||
def test_return_none_when_token_is_expired(notifications_admin,
|
||||
notifications_admin_db,
|
||||
notify_db_session):
|
||||
with notifications_admin.test_request_context():
|
||||
notifications_admin.config['TOKEN_MAX_AGE_SECONDS'] = -1000
|
||||
email = 'email@something.com'
|
||||
token = generate_token(email)
|
||||
assert check_token(token) is None
|
||||
notifications_admin.config['TOKEN_MAX_AGE_SECONDS'] = 120000
|
||||
Reference in New Issue
Block a user