Skip to content
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
7 changes: 5 additions & 2 deletions helios/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def get_voter(request, user, election):
"""
voter = None
if 'CURRENT_VOTER_ID' in request.session:
voter = Voter.objects.get(id=request.session['CURRENT_VOTER_ID'])
if voter.election != election:
voter = Voter.objects.filter(id=request.session['CURRENT_VOTER_ID']).first()
if voter is None:
# the voter was removed after logging in; forget the stale session entry
del request.session['CURRENT_VOTER_ID']
elif voter.election != election:
voter = None

if not voter:
Expand Down
14 changes: 14 additions & 0 deletions helios/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,20 @@ def test_confirm_voter_upload_twice(self):
self.assertEqual(response.status_code, 302)
self.assertTrue(response['location'].endswith("/helios/elections/%s/voters/list" % self.election.uuid))

def test_private_election_view_with_deleted_session_voter(self):
# a voter logs in, then the admin removes them; their session still
# holds the old voter id, which used to raise Voter.DoesNotExist (500)
self.election.private_p = True
self.election.save()
self.client.get("/")
session = self.client.session
session['CURRENT_VOTER_ID'] = 987654321
session.save()
response = self.client.get("/helios/elections/%s/view" % self.election.uuid)
self.assertEqual(response.status_code, 302)
self.assertIn("password_voter_login", response['location'])
self.assertNotIn('CURRENT_VOTER_ID', self.client.session)

def test_election_params(self):
response = self.client.get("/helios/elections/params")
self.assertEqual(response.content, views.ELGAMAL_PARAMS_LD_OBJECT.serialize().encode('utf-8'))
Expand Down
Loading