File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ class BadRequestError(CustomError):
3939 error_code = "BAD_REQUEST"
4040 message = "The request is invalid."
4141
42-
4342class ForbiddenError (CustomError ):
4443 status_code = 403
4544 error_code = "FORBIDDEN"
Original file line number Diff line number Diff line change @@ -830,6 +830,23 @@ def test_update_election():
830830 )
831831 check_error_response (response , 403 , "IMMUTABLE_IDS" )
832832
833+ def test_update_election_as_non_admin ():
834+ """
835+ Tests that a non-admin user cannot update an election.
836+ """
837+ # Create a restricted election to get both an admin and a non-admin (ballot) token.
838+ body = _random_election (5 , 3 )
839+ body ["restricted" ] = True
840+ body ["num_voters" ] = 1
841+ response = client .post ("/elections" , json = body )
842+ assert response .status_code == 200
843+ election_data = response .json ()
844+ ballot_token = election_data ["invites" ][0 ] # This is a non-admin token
845+
846+ # Attempt to update the election using the ballot token.
847+ update_payload = {"ref" : election_data ["ref" ], "name" : "New Name" }
848+ response = client .put ("/elections" , json = update_payload , headers = {"Authorization" : f"Bearer { ballot_token } " })
849+ check_error_response (response , 403 , "FORBIDDEN" )
833850
834851def test_close_election2 ():
835852 """
You can’t perform that action at this time.
0 commit comments