Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to index after session expiration on /generate #4496

Merged
merged 2 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions securedrop/source_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def setup_g():
# clear the session after we render the message so it's localized
session.clear()

# Redirect to index with flashed message
flash(Markup(msg), "important")
return redirect(url_for('main.index'))

session['expires'] = datetime.utcnow() + \
timedelta(minutes=getattr(config,
Expand Down
29 changes: 28 additions & 1 deletion securedrop/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import subprocess
import six
import time

from io import BytesIO
from flask import session, escape, current_app, url_for, g
Expand Down Expand Up @@ -667,7 +668,33 @@ def test_source_session_expiration(config, source_app):
# which is always present and 'csrf_token' which leaks no info)
session.pop('expires', None)
session.pop('csrf_token', None)
assert not session, session
assert not session

text = resp.data.decode('utf-8')
assert 'Your session timed out due to inactivity' in text


def test_source_session_expiration_create(config, source_app):
with source_app.test_client() as app:

seconds_session_expire = 1
config.SESSION_EXPIRATION_MINUTES = seconds_session_expire / 60.

# Make codename, and then wait for session to expire.
resp = app.get(url_for('main.generate'))
assert resp.status_code == 200

time.sleep(seconds_session_expire + 0.1)

# Now when we click create, the session will have expired.
resp = app.post(url_for('main.create'), follow_redirects=True)

# check that the session was cleared (apart from 'expires'
# which is always present and 'csrf_token' which leaks no info)
session.pop('expires', None)
session.pop('csrf_token', None)
assert not session

text = resp.data.decode('utf-8')
assert 'Your session timed out due to inactivity' in text

Expand Down