Skip to content

Commit

Permalink
fix: missing None check on alias contacts api
Browse files Browse the repository at this point in the history
  • Loading branch information
cquintana92 committed Oct 24, 2024
1 parent 9646f84 commit c1cd129
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/api/views/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ def create_contact_route(alias_id):
if not data:
return jsonify(error="request body cannot be empty"), 400

alias: Alias = Alias.get(alias_id)

if alias.user_id != g.user.id:
alias: Optional[Alias] = Alias.get_by(id=alias_id, user_id=g.user.id)
if not alias:
return jsonify(error="Forbidden"), 403

contact_address = data.get("contact")
Expand Down
13 changes: 13 additions & 0 deletions tests/api/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,19 @@ def test_create_contact_route_invalid_alias(flask_client):
assert r.status_code == 403


def test_create_contact_route_non_existing_alias(flask_client):
user, api_key = get_new_user_and_api_key()
Session.commit()

r = flask_client.post(
url_for("api.create_contact_route", alias_id=99999999),
headers={"Authentication": api_key.code},
json={"contact": "First Last <[email protected]>"},
)

assert r.status_code == 403


def test_create_contact_route_free_users(flask_client):
user, api_key = get_new_user_and_api_key()

Expand Down

0 comments on commit c1cd129

Please sign in to comment.