mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 08:16:51 -04:00
Use session.clear() sign-out.
NOTE: you can not test that the session is cleared out by checking the session cookie does not exist on the index page, because ItsDangerousSession will create a new session when it hits the index page. The unit test confirms that the session has been cleared.
This commit is contained in:
@@ -8,7 +8,6 @@ from app.main import main
|
|||||||
@main.route('/sign-out', methods=(['GET']))
|
@main.route('/sign-out', methods=(['GET']))
|
||||||
@login_required
|
@login_required
|
||||||
def sign_out():
|
def sign_out():
|
||||||
if session.get('service_name', None):
|
session.clear()
|
||||||
session.pop('service_name')
|
|
||||||
logout_user()
|
logout_user()
|
||||||
return redirect(url_for('main.index'))
|
return redirect(url_for('main.index'))
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
from datetime import datetime
|
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from app.main.dao import users_dao
|
|
||||||
|
|
||||||
|
|
||||||
def test_render_sign_out_redirects_to_sign_in(app_):
|
def test_render_sign_out_redirects_to_sign_in(app_):
|
||||||
@@ -24,6 +22,8 @@ def test_sign_out_user(app_,
|
|||||||
email = 'valid@example.gov.uk'
|
email = 'valid@example.gov.uk'
|
||||||
password = 'val1dPassw0rd!'
|
password = 'val1dPassw0rd!'
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
|
with client.session_transaction() as session:
|
||||||
|
print('session: {}'.format(session))
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
# Check we are logged in
|
# Check we are logged in
|
||||||
response = client.get(
|
response = client.get(
|
||||||
@@ -33,3 +33,4 @@ def test_sign_out_user(app_,
|
|||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for(
|
||||||
'main.index', _external=True)
|
'main.index', _external=True)
|
||||||
|
assert session.get('ItsdangerousSession') is None
|
||||||
|
|||||||
Reference in New Issue
Block a user