Skip to content

Commit c825cfc

Browse files
authored
Merge pull request #25 from freelawproject/19-add-more-courts-to-mapping-tweak-log
19 Ignore invalid subdomains that are not courts
2 parents fb88380 + 302b93d commit c825cfc

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

cl/recap_email/app/app.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from requests.exceptions import HTTPError, Timeout
1111
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
1212

13-
from .pacer import map_pacer_to_cl_id
13+
from .pacer import map_pacer_to_cl_id, sub_domains_to_ignore
1414
from .utils import retry # pylint: disable=import-error
1515

1616
# NOTE - This is necessary for the relative imports.
@@ -142,15 +142,19 @@ def log_invalid_court_error(response, message_id):
142142
return
143143

144144
for msg in response.json().get("court", []):
145-
if "Invalid pk" in msg:
146-
match = re.search(r'Invalid pk "([^"]+)"', msg)
147-
if match:
148-
error_message = (
149-
f"Invalid court pk: {match.group(1)} - "
150-
f"message_id: {message_id}"
151-
)
152-
sentry_sdk.capture_message(error_message, level="error")
153-
break
145+
if "Invalid pk" not in msg:
146+
continue
147+
match = re.search(r'Invalid pk "([^"]+)"', msg)
148+
if not match:
149+
continue
150+
court_id = match.group(1)
151+
error_message = (
152+
f"Invalid court pk: {court_id} - message_id: {message_id}"
153+
)
154+
sentry_sdk.capture_message(
155+
error_message, level="error", fingerprint=["invalid-court-pk"]
156+
)
157+
break
154158

155159

156160
@retry(
@@ -230,8 +234,10 @@ def handler(event, context): # pylint: disable=unused-argument
230234
if verdict not in {"PASS", "GRAY"}:
231235
return validation_failure(email, receipt, verdict)
232236

233-
# Check domain is valid (comes from uscourts.gov)
234237
domain_verdict = get_valid_domain_verdict(email)
235-
if domain_verdict != "PASS":
238+
court_id = get_cl_court_id(email)
239+
# Check domain is valid (comes from uscourts.gov)
240+
# Ignore messages that are not from courts, such as updates.uscourts.gov
241+
if domain_verdict != "PASS" or court_id in sub_domains_to_ignore:
236242
return validation_domain_failure(email, receipt, domain_verdict)
237243
return send_to_court_listener(email, receipt)

cl/recap_email/app/pacer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"cfc": "uscfc", # Court of Federal Claims
1111
}
1212

13+
sub_domains_to_ignore = ["usdoj", "law", "psc", "updates", "MIWD"]
14+
1315
# Reverse dict of pacer_to_cl_ids
1416
cl_to_pacer_ids = {v: k for k, v in pacer_to_cl_ids.items()}
1517

cl/tests/unit/test_recap_email_handler.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,32 @@ def test_report_request_for_invalid_court(
295295
"Invalid court pk: whla - "
296296
"message_id: 171jjm4scn8vgcn5vrcv4su427obcred7bekus81"
297297
)
298-
mock_sentry_capture.assert_called_with(expected_error, level="error")
298+
mock_sentry_capture.assert_called_with(
299+
expected_error, level="error", fingerprint=["invalid-court-pk"]
300+
)
301+
302+
303+
@mock.patch.dict(
304+
os.environ,
305+
{
306+
"RECAP_EMAIL_ENDPOINT": "http://host.docker.internal:8000/api/rest/v3/recap-email/", # noqa: E501 pylint: disable=line-too-long
307+
"AUTH_TOKEN": "************************",
308+
},
309+
)
310+
def test_ignore_messages_from_invalid_court_ids(
311+
pacer_event_one,
312+
requests_mock, # noqa: F811
313+
):
314+
"""Confirm that if an invalid court_id in sub_domains_to_ignore is sent, a
315+
validation_domain_failure is sent."""
316+
317+
with mock.patch(
318+
"recap_email.app.app.get_cl_court_id", return_value="updates"
319+
):
320+
requests_mock.post(
321+
"http://host.docker.internal:8000/api/rest/v3/recap-email/",
322+
json={"mail": {}, "receipt": {}},
323+
)
324+
response = app.handler(pacer_event_one, "")
325+
assert response["statusCode"] == 424
326+
assert response["valid_domain"]["status"] == "FAILED"

0 commit comments

Comments
 (0)