2020-07-26 17:53:59 +00:00
|
|
|
from app.utils.session_utils import generate_user_keys, valid_user_session
|
2020-06-02 18:54:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_user_keys():
|
|
|
|
keys = generate_user_keys()
|
|
|
|
assert 'text_key' in keys
|
|
|
|
assert 'element_key' in keys
|
|
|
|
assert keys['text_key'] not in keys['element_key']
|
|
|
|
|
|
|
|
|
|
|
|
def test_valid_session(client):
|
2020-06-05 22:09:04 +00:00
|
|
|
assert not valid_user_session({'fernet_keys': '', 'config': {}})
|
2020-06-02 18:54:47 +00:00
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|
|
|
|
|
|
|
|
|
|
|
|
def test_request_key_generation(client):
|
2020-06-05 22:09:04 +00:00
|
|
|
rv = client.get('/')
|
|
|
|
cookie = rv.headers['Set-Cookie']
|
|
|
|
|
|
|
|
rv = client.get('/search?q=test+1', headers={'Cookie': cookie})
|
2020-06-02 18:54:47 +00:00
|
|
|
assert rv._status_code == 200
|
|
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|
2020-06-05 21:24:44 +00:00
|
|
|
text_key = session['fernet_keys']['text_key']
|
2020-06-02 18:54:47 +00:00
|
|
|
|
2020-06-05 22:09:04 +00:00
|
|
|
rv = client.get('/search?q=test+2', headers={'Cookie': cookie})
|
2020-06-02 18:54:47 +00:00
|
|
|
assert rv._status_code == 200
|
|
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
assert valid_user_session(session)
|
2020-06-05 21:24:44 +00:00
|
|
|
assert text_key not in session['fernet_keys']['text_key']
|