2021-04-01 07:23:30 +03:00
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
from app.utils.session import generate_user_key, valid_user_session
|
2020-06-02 21:54:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_user_keys():
|
2021-04-01 07:23:30 +03:00
|
|
|
key = generate_user_key()
|
|
|
|
assert Fernet(key)
|
|
|
|
assert generate_user_key() != key
|
2020-06-02 21:54:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_valid_session(client):
|
2021-04-01 07:23:30 +03:00
|
|
|
assert not valid_user_session({'key': '', 'config': {}})
|
2020-06-02 21:54:47 +03:00
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|
|
|
|
|
|
|
|
|
2021-04-01 07:23:30 +03:00
|
|
|
def test_query_decryption(client):
|
|
|
|
# FIXME: Handle decryption errors in search.py and rewrite test
|
|
|
|
# This previously was used to test swapping decryption keys between
|
|
|
|
# queries. While this worked in theory and usually didn't cause problems,
|
|
|
|
# they were tied to session IDs and those are really unreliable (meaning
|
|
|
|
# that occasionally page navigation would break).
|
2020-06-06 01:09:04 +03:00
|
|
|
rv = client.get('/')
|
|
|
|
cookie = rv.headers['Set-Cookie']
|
|
|
|
|
|
|
|
rv = client.get('/search?q=test+1', headers={'Cookie': cookie})
|
2020-06-02 21:54:47 +03:00
|
|
|
assert rv._status_code == 200
|
|
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|
|
|
|
|
2020-06-06 01:09:04 +03:00
|
|
|
rv = client.get('/search?q=test+2', headers={'Cookie': cookie})
|
2020-06-02 21:54:47 +03:00
|
|
|
assert rv._status_code == 200
|
|
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|