Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1e73be6
bug-2053888: Don't return crash pings unless explicitly requested.
smarnach Sep 22, 2026
4bb575f
bug-2053888: Rename default submission type setting.
smarnach Sep 25, 2026
b5aeb61
bug-2053888: Remove unused code.
smarnach Sep 25, 2026
d1cd728
bug-2053888: Disable submission type default for CrashVerify endpoint.
smarnach Sep 25, 2026
8a961e5
bug-2053888: Make the verifyprocessed cron job verify all submission …
smarnach Sep 25, 2026
0dca580
bug-2053888: Add a submission_type query parameter to the topcrashers
smarnach Oct 20, 2026
203ddc3
bug-2053888: Improve test coverage for
smarnach Oct 20, 2026
ed35aff
bug-2053888: Fix typo in docstring.
smarnach Nov 9, 2026
0346f35
bug-2053888: Ignore default submission type in updatesignatures manag…
smarnach Nov 9, 2026
7a81ad1
bug-2053888: Fix quoting of default values on the API documentation p…
smarnach Nov 10, 2026
b265166
bug-2053888: Ignore the submission type default filter when determini…
smarnach Nov 10, 2026
2021c8f
bug-2053888: Add Supersearch test for legacy crash reports without su…
smarnach Nov 10, 2026
d9e3a5f
bug-2053888: Reformat code to make linter happy.
smarnach Nov 11, 2026
c967ac6
bug-2053888: Make omiiting the submission_type filter more explicit.
smarnach Nov 11, 2026
aed9f1b
bug-2053888: Add comment explaining PyQuery selectors in test.
smarnach Nov 16, 2026
e160dca
bug-2053888: Fix updatesignatures test to actually run Supersearch.
smarnach Nov 18, 2026
1bc54ad
bug-2053888: Use a for-loop instead of parametrize for Django-based t…
smarnach Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions webapp/crashstats/api/templatetags/jinja_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import datetime
from urllib.parse import quote
import warnings

from django_jinja import library
Expand Down Expand Up @@ -57,7 +56,7 @@ def make_test_input(parameter, defaults):
if parameter["type"] is not str:
classes.append("validate-%s" % parameter["type"].__name__)
if defaults.get(parameter["name"]):
data["value"] = quote(str(defaults.get(parameter["name"])))
data["value"] = markupsafe.escape(str(defaults.get(parameter["name"])))
else:
data["value"] = ""

Expand Down
19 changes: 18 additions & 1 deletion webapp/crashstats/api/tests/test_jinja_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

from crashstats.api.templatetags.jinja_helpers import pluralize
import pyquery
import pytest

from crashstats.api.templatetags.jinja_helpers import make_test_input, pluralize


class TestMakeTestInput:
@pytest.mark.parametrize(
"value", ["!ping", "ping", "with spaces", '"><script>alert("x")</script>&']
Comment thread
smarnach marked this conversation as resolved.
Resolved
)
def test_default_value(self, value):
parameter = {"name": "submission_type", "type": str, "required": False}
html = make_test_input(parameter, {"submission_type": value})
doc = pyquery.PyQuery(html)

assert doc("input").attr("value") == value
assert set(doc("input")[0].attrib) == {"type", "name", "value"}
assert not doc("script")


class TestPluralize:
Expand Down
63 changes: 53 additions & 10 deletions webapp/crashstats/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from django.utils.encoding import smart_str
from markus.testing import MetricsMock

from socorro.lib.libdatetime import utc_now
from socorro.lib.libooid import create_new_ooid


Expand Down Expand Up @@ -87,6 +88,25 @@ def test_documentation_home_page(self):
for elt in doc("#mainbody .panel .title h2 a"):
assert elt.text in valid_names

def test_submission_type_default(self):
url = reverse("api:documentation")
for submission_type in ["!ping", "ping"]:
with self.subTest(submission_type=submission_type):
with self.settings(
SUPERSEARCH_DEFAULT_SUBMISSION_TYPE_FILTER=submission_type
):
response = self.client.get(url)
assert response.status_code == 200
doc = pyquery.PyQuery(response.content)
# Select the input tag for the submission_type value.
test_input = doc("#SuperSearch input[name='submission_type']")
assert test_input.attr("value") == submission_type
# Select the row containing the input tag, and the column with index 3, i.e.
# the fourth column, containing the default value.
assert (
test_input.closest("tr").find("td").eq(3).text() == submission_type
)


class TestViews(BaseTestViews):
def test_invalid_url(self):
Expand Down Expand Up @@ -471,9 +491,14 @@ def mocked_get(**params):
url = reverse("api:model_wrapper", args=("SuperSearch",))

# The bare request relies on defaults that are all public fields
response = self.client.get(url)
assert response.status_code == 200
assert json.loads(response.content)["hits"]
for default_submission_type in ["report", "ping"]:
with self.settings(
SUPERSEARCH_DEFAULT_SUBMISSION_TYPE_FILTER=default_submission_type
):
response = self.client.get(url)
assert response.status_code == 200
assert json.loads(response.content)["hits"]
assert params_before_query["submission_type"] == [default_submission_type]

# Query with only public fields
response = self.client.get(
Expand Down Expand Up @@ -639,7 +664,11 @@ class TestSuperSearchUnredacted(BaseTestViews):
"crashstats.supersearch.models.SuperSearchUnredacted.get_implementation"
)
def test_api(self, mock_implementation):
params_before_query = {}

def mocked_get(**params):
params_before_query.clear()
params_before_query.update(params)
assert "url" in params
if "product" in params:
assert params["product"] == ["WaterWolf", "NightTrain"]
Expand Down Expand Up @@ -671,8 +700,13 @@ def mocked_get(**params):
user = self._login()
self._add_permission(user, "view_pii")

response = self.client.get(url, {"url": "example.com"})
assert response.status_code == 200
for default_submission_type in ["report", "ping"]:
with self.settings(
SUPERSEARCH_DEFAULT_SUBMISSION_TYPE_FILTER=default_submission_type
):
response = self.client.get(url, {"url": "example.com"})
assert response.status_code == 200
assert params_before_query["submission_type"] == [default_submission_type]
res = json.loads(response.content)

assert res["hits"]
Expand Down Expand Up @@ -768,14 +802,23 @@ def test_bad_uuid(self, client):
data = json.loads(resp.content)
assert data == {"error": "unknown crash id"}

def test_elastcsearch_has_crash(self, storage_helper, client):
@pytest.mark.parametrize("submission_type", ["report", "ping", None])
def test_elasticsearch_has_crash(
self, storage_helper, es_helper, client, submission_type
):
self.create_storage_buckets(storage_helper)

uuid = create_new_ooid()

with self.supersearch_returns_crashes([uuid]):
url = reverse("api:crash_verify")
resp = client.get(url, {"crash_id": uuid})
crash_data = {
"uuid": uuid,
"date_processed": utc_now(),
"signature": "/api/CrashVerify",
}
if submission_type is not None:
crash_data["submission_type"] = submission_type
es_helper.index_crash(processed_crash=crash_data)
url = reverse("api:crash_verify")
resp = client.get(url, {"crash_id": uuid})

assert resp.status_code == 200
data = json.loads(resp.content)
Expand Down
62 changes: 2 additions & 60 deletions webapp/crashstats/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _describe_model(model_name, model):
"name": model_name,
"url": reverse("api:model_wrapper", args=(model_name,)),
"parameters": params,
"defaults": getattr(model, "defaults", {}),
"defaults": getattr(model_inst, "defaults", {}),
"methods": methods,
"help_text": help_text,
"required_permissions": required_permissions,
Expand Down Expand Up @@ -460,65 +460,6 @@ def _handle_ratelimit(*args, **kwargs):
return _handle_ratelimit


@csrf_exempt
@handle_ratelimit
@ratelimit(key="ip", method=["GET"], rate=utils.ratelimit_rate, block=True)
@utils.json_view
def crash_verify(request):
"""Verifies crash data in crash data destinations"""
if request.method == "OPTIONS":
return http.JsonResponse({}, status=200)

crash_id = request.GET.get("crash_id", None)

if not crash_id or not is_crash_id_valid(crash_id):
return http.JsonResponse({"error": "unknown crash id"}, status=400)

data = {"uuid": crash_id}

# Check crash bucket for raw and processed crash data
raw_api = models.RawCrash()
try:
raw_api.get(crash_id=crash_id, dont_cache=True, refresh_cache=True)
has_raw_crash = True
except CrashIDNotFound:
has_raw_crash = False
data["raw_crash"] = has_raw_crash

processed_api = models.ProcessedCrash()
try:
processed_api.get(crash_id=crash_id, dont_cache=True, refresh_cache=True)
has_processed_crash = True
except CrashIDNotFound:
has_processed_crash = False
data["processed_crash"] = has_processed_crash

# Check Elasticsearch for crash data
supersearch_api = supersearch_models.SuperSearch()
params = {
"_columns": ["uuid"],
"_results_number": 1,
"uuid": crash_id,
"dont_cache": True,
"refresh_cache": True,
}
results = supersearch_api.get(**params)
data["elasticsearch_crash"] = (
results["total"] == 1 and results["hits"][0]["uuid"] == crash_id
)

# Check telemetry bucket for crash data
telemetry_api = models.TelemetryCrash()
try:
telemetry_api.get(crash_id=crash_id, dont_cache=True, refresh_cache=True)
has_telemetry_crash = True
except CrashIDNotFound:
has_telemetry_crash = False
data["telemetry_crash"] = has_telemetry_crash

return http.JsonResponse(data, status=200)


class SocorroAPIView(APIView):
"""Django REST Framework APIView that supports CORS"""

Expand Down Expand Up @@ -684,6 +625,7 @@ def get(self, request):
"_columns": ["uuid"],
"_results_number": 1,
"uuid": crash_id,
"submission_type": models.FILTER_ANY,
"dont_cache": True,
"refresh_cache": True,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.utils import timezone
from django.utils.dateparse import parse_datetime

from crashstats.crashstats.models import Signature
from crashstats.crashstats.models import FILTER_ANY, Signature
from crashstats.supersearch.models import SuperSearch
from crashstats.supersearch.libsupersearch import get_supersearch_fields
from socorro.lib.libdatetime import string_to_datetime
Expand Down Expand Up @@ -99,6 +99,8 @@ def handle(self, **options):
"_columns": ["signature", "build_id", "date"],
"_facets_size": 0,
"_fields": all_fields,
# Include all submission types, even documents without an explicit type.
"submission_type": FILTER_ANY,
# Set up first page
"_results_offset": 0,
"_results_number": MAX_PAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.utils import timezone
from django.utils.dateparse import parse_date, parse_datetime

from crashstats.crashstats.models import MissingProcessedCrash, Reprocessing
from crashstats.crashstats.models import FILTER_ANY, MissingProcessedCrash, Reprocessing
from crashstats.supersearch.models import SuperSearchUnredacted
from socorro import settings as socorro_settings
from socorro.lib.libooid import date_from_ooid
Expand Down Expand Up @@ -57,6 +57,7 @@ def check_elasticsearch(supersearch, crash_ids):
params = {
"uuid": crash_ids,
"date": [">=%s" % start_date, "<=%s" % end_date],
"submission_type": FILTER_ANY,
"_columns": ["uuid"],
"_facets": [],
"_facets_size": 0,
Expand Down
8 changes: 8 additions & 0 deletions webapp/crashstats/crashstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
PROCESSED_CRASH_SCHEMA = get_schema("processed_crash.schema.yaml")


# Explicitly omit a filter, even when the middleware defines a default for it.
FILTER_ANY = object()


# Django models first


Expand Down Expand Up @@ -397,12 +401,16 @@ def _options(self, method="options"):
return {}, False

def parse_parameters(self, kwargs):
"""Apply defaults and aliases, omitting filters set to FILTER_ANY."""
defaults = getattr(self, "defaults", {})
aliases = getattr(self, "aliases", {})

for key, value in defaults.items():
kwargs[key] = kwargs.get(key) or value

kwargs = {
key: value for key, value in kwargs.items() if value is not FILTER_ANY
}
params = self.kwargs_to_params(kwargs)
for param in list(params):
if aliases.get(param):
Expand Down
37 changes: 35 additions & 2 deletions webapp/crashstats/crashstats/tests/test_updatesignatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import datetime
import io
from unittest import mock

from django.core.management import call_command
import pytest

from crashstats.crashstats.models import Signature
from socorro.lib.libdatetime import utc_now
from socorro.lib.libooid import create_new_ooid


class FakeModel:
Expand Down Expand Up @@ -38,6 +42,35 @@ def fetch_crashstats_signature_data(self):
)
]

@pytest.mark.parametrize("submission_type_filter", ["!ping", "ping"])
def test_all_submission_types(
self, submission_type_filter, es_helper, settings, db
):
"""Test processing crash documents with different submission types."""
settings.SUPERSEARCH_DEFAULT_SUBMISSION_TYPE_FILTER = submission_type_filter
run_time = utc_now().replace(second=0, microsecond=0)
date_processed = run_time - datetime.timedelta(minutes=5)
for submission_type in [None, "report", "ping"]:
processed_crash = {
"uuid": create_new_ooid(),
"signature": str(submission_type),
"date_processed": date_processed,
"build": "20180420000000",
"date": "2018-05-03T12:00:00.00000+00:00",
}
if submission_type is not None:
processed_crash["submission_type"] = submission_type
es_helper.index_crash(processed_crash=processed_crash)

call_command(
"updatesignatures", run_time=run_time.isoformat(), stdout=io.StringIO()
)

signatures_in_db = [
sig["signature"] for sig in self.fetch_crashstats_signature_data()
]
assert signatures_in_db == ["None", "ping", "report"]

@mock.patch(
"crashstats.crashstats.management.commands.updatesignatures.SuperSearch"
)
Expand Down Expand Up @@ -139,12 +172,12 @@ def test_multiple_crash_processing(self, mock_supersearch, db):
"hits": [
{
"build_id": "20180426000000",
# This is the earliest date of the three
# This is the earliest date
"date": "2018-05-03T16:00:00.00000+00:00",
"signature": "OOM | large",
},
{
# This is the earliest build id of the three
# This is the earliest build id
"build_id": "20180322000000",
"date": "2018-05-03T18:00:00.00000+00:00",
"signature": "OOM | large",
Expand Down
Loading