Skip to content

Commit dd0e77c

Browse files
FedericoCerattoFederico Ceratto
authored and
Federico Ceratto
committed
Fix, update tests
1 parent d9db8da commit dd0e77c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

api/ooniapi/incidents.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def prepare_incident_dict(d: dict):
192192
def mismatched_email_addr(req: dict) -> bool:
193193
account_id = get_account_id_or_raise()
194194
hashed = hash_email_address(req["email_address"])
195-
return account_id == hashed
195+
if account_id == hashed:
196+
return False
197+
198+
log.info(f"Email mismatch {hashed} {account_id}")
199+
return True
196200

197201

198202
def user_cannot_update(incident_id: str) -> bool:

api/tests/integ/test_incidents.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def test_crud_user_create(cleanup, client, adminsession, usersession):
201201
],
202202
"published": False,
203203
"reported_by": "ooni",
204+
"email_address": "[email protected]",
204205
"start_time": "2020-01-01T00:00:00Z",
205206
"tags": ["integ-test"],
206207
"title": title,
@@ -219,6 +220,7 @@ def test_crud_user_create_cannot_publish(cleanup, client, adminsession, usersess
219220
start_time=datetime(2020, 1, 1),
220221
end_time=None,
221222
reported_by="ooni",
223+
email_address="[email protected]",
222224
title=title,
223225
text="foo bar\nbaz\n",
224226
event_type="incident",
@@ -243,6 +245,7 @@ def test_crud_user_create_invalid_asns(cleanup, client, adminsession, usersessio
243245
start_time=datetime(2020, 1, 1),
244246
end_time=None,
245247
reported_by="ooni",
248+
email_address="[email protected]",
246249
title=title,
247250
text="foo bar\nbaz\n",
248251
event_type="incident",
@@ -267,6 +270,7 @@ def test_crud_user_create_invalid_dates(cleanup, client, adminsession, usersessi
267270
start_time=datetime(2020, 1, 1),
268271
end_time=datetime(2019, 1, 1),
269272
reported_by="ooni",
273+
email_address="[email protected]",
270274
title=title,
271275
text="foo bar\nbaz\n",
272276
event_type="incident",
@@ -285,12 +289,39 @@ def test_crud_user_create_invalid_dates(cleanup, client, adminsession, usersessi
285289
assert r.status_code == 400, r.json
286290

287291

292+
def test_crud_user_create_mismatched_email(cleanup, client, adminsession, usersession):
293+
title = "integ-test-6"
294+
new = dict(
295+
start_time=datetime(2020, 1, 1),
296+
end_time=None,
297+
reported_by="ooni",
298+
email_address="[email protected]",
299+
title=title,
300+
short_description="integ test",
301+
text="foo bar\nbaz\n",
302+
event_type="incident",
303+
published=False,
304+
CCs=["UK", "FR"],
305+
test_names=["web_connectivity"],
306+
ASNs=[1, 2],
307+
domains=[],
308+
tags=["integ-test"],
309+
links=[
310+
"https://explorer.ooni.org/chart/mat?test_name=web_connectivity&axis_x=measurement_start_day&since=2023-04-16&until=2023-05-16&time_grain=day"
311+
],
312+
)
313+
d = dict(**new)
314+
r = usersession.post("/api/v1/incidents/create", json=d)
315+
assert r.status_code == 400, r.json
316+
317+
288318
def test_crud_invalid_fields(client, adminsession, usersession):
289319
# Create
290320
new = dict(
291321
start_time=datetime(2020, 1, 1),
292322
end_time=None,
293323
reported_by="ooni",
324+
email_address="[email protected]",
294325
title="", # empty
295326
short_description="integ test",
296327
text="foo bar\nbaz\n",
@@ -316,6 +347,7 @@ def test_crud_extra_field(client, adminsession, usersession):
316347
start_time=datetime(2020, 1, 1),
317348
end_time=None,
318349
reported_by="ooni",
350+
email_address="[email protected]",
319351
title="",
320352
short_description="integ test",
321353
text="foo bar\nbaz\n",

0 commit comments

Comments
 (0)