From f0641ae39b4f47f2cbfe77bf77dab196dbe941a8 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 18 Mar 2025 10:54:07 +0100 Subject: [PATCH] fix(symbol sources): Correct schema and validate builtin sources Second attempt of #86878. Validating the builtin symbol sources against the schema revealed that it was incorrect in several ways (missing file types, filters, `is_public`). I also added the validation of the builtin sources as a test so that in the future a mistake like #86873 fails in CI. Unlike #86878, this temporarily keeps around an incorrect piece of the old schema for backwards compatibility. It will be reomved when the sources using it have been fixed. --- src/sentry/lang/native/sources.py | 31 ++++++++++++++++++- .../api/endpoints/test_project_details.py | 8 +++-- ...redsourcesfiltering.py => test_sources.py} | 10 +++++- 3 files changed, 45 insertions(+), 4 deletions(-) rename tests/sentry/lang/native/{test_ignoredsourcesfiltering.py => test_sources.py} (94%) diff --git a/src/sentry/lang/native/sources.py b/src/sentry/lang/native/sources.py index 509db8b6fbf49e..5ae568c547fd72 100644 --- a/src/sentry/lang/native/sources.py +++ b/src/sentry/lang/native/sources.py @@ -34,7 +34,23 @@ "slashsymbols", ) -VALID_FILE_TYPES = ("pe", "pdb", "mach_debug", "mach_code", "elf_debug", "elf_code", "breakpad") +VALID_FILE_TYPES = ( + "pe", + "pdb", + "portablepdb", + "mach_debug", + "mach_code", + "elf_debug", + "elf_code", + "wasm_debug", + "wasm_code", + "breakpad", + "sourcebundle", + "uuidmap", + "bcsymbolmap", + "il2cpp", + "proguard", +) VALID_CASINGS = ("lowercase", "uppercase", "default") @@ -48,11 +64,24 @@ "additionalProperties": False, } +FILTERS_SCHEMA = { + "type": "object", + "properties": { + "filetypes": {"type": "array", "items": {"type": "string", "enum": list(VALID_FILE_TYPES)}}, + "path_patterns": {"type": "array", "items": {"type": "string"}}, + "requires_checksum": {"type": "boolean"}, + }, + "additionalProperties": False, +} + COMMON_SOURCE_PROPERTIES = { "id": {"type": "string", "minLength": 1}, "name": {"type": "string"}, "layout": LAYOUT_SCHEMA, + "filters": FILTERS_SCHEMA, + # FIXME: This is temporarily included for backwards compatibility. "filetypes": {"type": "array", "items": {"type": "string", "enum": list(VALID_FILE_TYPES)}}, + "is_public": {"type": "boolean"}, } APP_STORE_CONNECT_SCHEMA = { diff --git a/tests/sentry/api/endpoints/test_project_details.py b/tests/sentry/api/endpoints/test_project_details.py index f3aecb68b4227c..eec583f86dde35 100644 --- a/tests/sentry/api/endpoints/test_project_details.py +++ b/tests/sentry/api/endpoints/test_project_details.py @@ -1127,7 +1127,7 @@ def test_redacted_symbol_source_secrets(self, create_audit_entry): "layout": { "type": "native", }, - "filetypes": ["pe"], + "filters": {"filetypes": ["pe"]}, "type": "http", "url": "http://honk.beep", "username": "honkhonk", @@ -1180,7 +1180,7 @@ def test_redacted_symbol_source_secrets_unknown_secret(self, create_audit_entry) "layout": { "type": "native", }, - "filetypes": ["pe"], + "filters": {"filetypes": ["pe"]}, "type": "http", "url": "http://honk.beep", "username": "honkhonk", @@ -1215,6 +1215,8 @@ def symbol_sources(self): "layout": { "type": "native", }, + "filters": {"filetypes": ["pe"]}, + # FIXME: This is temporarily included for backwards compatibility. "filetypes": ["pe"], "type": "http", "url": "http://honk.beep", @@ -1228,6 +1230,8 @@ def symbol_sources(self): "layout": { "type": "native", }, + "filters": {"filetypes": ["pe"]}, + # FIXME: This is temporarily included for backwards compatibility. "filetypes": ["pe"], "type": "http", "url": "http://honk.beep", diff --git a/tests/sentry/lang/native/test_ignoredsourcesfiltering.py b/tests/sentry/lang/native/test_sources.py similarity index 94% rename from tests/sentry/lang/native/test_ignoredsourcesfiltering.py rename to tests/sentry/lang/native/test_sources.py index e00a82b4db4c65..bda341e344d691 100644 --- a/tests/sentry/lang/native/test_ignoredsourcesfiltering.py +++ b/tests/sentry/lang/native/test_sources.py @@ -1,10 +1,18 @@ +import jsonschema import pytest +from django.conf import settings -from sentry.lang.native.sources import filter_ignored_sources +from sentry.lang.native.sources import SOURCE_SCHEMA, filter_ignored_sources from sentry.testutils.helpers import override_options from sentry.testutils.pytest.fixtures import django_db_all +@django_db_all +def test_validate_builtin_sources(): + for source in settings.SENTRY_BUILTIN_SOURCES.values(): + jsonschema.validate(source, SOURCE_SCHEMA) + + class TestIgnoredSourcesFiltering: @pytest.fixture def sources(self):