Skip to content

Commit f11028f

Browse files
committed
Improved: the generic ForbiddenError response now uses the new error format
1 parent 326fd28 commit f11028f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class BadRequestError(CustomError):
3939
error_code = "BAD_REQUEST"
4040
message = "The request is invalid."
4141

42-
4342
class ForbiddenError(CustomError):
4443
status_code = 403
4544
error_code = "FORBIDDEN"

app/tests/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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

834851
def test_close_election2():
835852
"""

0 commit comments

Comments
 (0)