Skip to content

Commit

Permalink
added session expiration test for source interface
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed Oct 1, 2017
1 parent a8cbe82 commit 1dd76f5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions securedrop/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,34 @@ def test_login_with_overly_long_codename(self, mock_hash_codename):
self.assertFalse(mock_hash_codename.called,
"Called hash_codename for codename w/ invalid "
"length")

def test_source_session_expiration(self):
try:
old_expiration = config.SESSION_EXPIRATION_MINUTES
has_session_expiration = True
except AttributeError:
has_session_expiration = False

try:
with self.client as client:
codename = new_codename(client, session)

# set the expiration to ensure we trigger an expiration
config.SESSION_EXPIRATION_MINUTES = -1

resp = client.post('/login',
data=dict(codename=codename),
follow_redirects=True)
assert resp.status_code == 200
resp = client.get('/lookup', 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, session
assert ('You have been logged out due to inactivity' in
resp.data.decode('utf-8'))
finally:
if has_session_expiration:
config.SESSION_EXPIRATION_MINUTES = old_expiration

0 comments on commit 1dd76f5

Please sign in to comment.