diff --git a/app/__init__.py b/app/__init__.py index c6b8a42..22e436d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,7 +15,6 @@ app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config app.config['CONFIG_PATH'] = os.getenv('CONFIG_VOLUME', os.path.join(app.config['STATIC_FOLDER'], 'config')) app.config['DEFAULT_CONFIG'] = os.path.join(app.config['CONFIG_PATH'], 'config.json') app.config['SESSION_FILE_DIR'] = os.path.join(app.config['CONFIG_PATH'], 'session') -app.config['SESSION_COOKIE_SAMESITE'] = 'Strict' if not os.path.exists(app.config['CONFIG_PATH']): os.makedirs(app.config['CONFIG_PATH']) diff --git a/test/conftest.py b/test/conftest.py index 3d2aa33..63aec3e 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,8 +1,13 @@ from app import app +from app.utils.misc import generate_user_keys import pytest @pytest.fixture def client(): - client = app.test_client() - yield client + with app.test_client() as client: + with client.session_transaction() as session: + session['uuid'] = 'test' + session['fernet_keys'] = generate_user_keys() + session['config'] = {} + yield client diff --git a/test/test_misc.py b/test/test_misc.py index 96ef373..8eb1d78 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -9,26 +9,23 @@ def test_generate_user_keys(): def test_valid_session(client): + assert not valid_user_session({'fernet_keys': '', 'config': {}}) with client.session_transaction() as session: - assert not valid_user_session(session) - - session['uuid'] = 'test' - session['fernet_keys'] = generate_user_keys() - session['config'] = {} - assert valid_user_session(session) def test_request_key_generation(client): - text_key = '' - rv = client.get('/search?q=test+1') + rv = client.get('/') + cookie = rv.headers['Set-Cookie'] + + rv = client.get('/search?q=test+1', headers={'Cookie': cookie}) assert rv._status_code == 200 with client.session_transaction() as session: assert valid_user_session(session) text_key = session['fernet_keys']['text_key'] - rv = client.get('/search?q=test+2') + rv = client.get('/search?q=test+2', headers={'Cookie': cookie}) assert rv._status_code == 200 with client.session_transaction() as session: