diff --git a/src/sentry/constants.py b/src/sentry/constants.py index e4d0f9c5bf24ae..44ad628a28a3dc 100644 --- a/src/sentry/constants.py +++ b/src/sentry/constants.py @@ -166,6 +166,23 @@ def get_all_languages(): 'access_token', ) +VALID_PLATFORMS = set([ + 'as3', + 'c', + 'cfml', + 'csharp', + 'go', + 'java', + 'javascript', + 'node', + 'objc', + 'other', + 'perl', + 'php', + 'python', + 'ruby', +]) + OK_PLUGIN_ENABLED = _("The {name} integration has been enabled.") OK_PLUGIN_DISABLED = _("The {name} integration has been disabled.") diff --git a/src/sentry/coreapi.py b/src/sentry/coreapi.py index 82e0987310a1fe..947cbfff1806b2 100644 --- a/src/sentry/coreapi.py +++ b/src/sentry/coreapi.py @@ -26,7 +26,7 @@ from sentry.cache import default_cache from sentry.constants import ( CLIENT_RESERVED_ATTRS, DEFAULT_LOG_LEVEL, LOG_LEVELS, MAX_TAG_VALUE_LENGTH, - MAX_TAG_KEY_LENGTH + MAX_TAG_KEY_LENGTH, VALID_PLATFORMS ) from sentry.interfaces.base import get_interface, InterfaceValidationError from sentry.interfaces.csp import Csp @@ -384,6 +384,9 @@ def validate_data(self, project, data): 'value': data['fingerprint'], }) + if 'platform' not in data or data['platform'] not in VALID_PLATFORMS: + data['platform'] = 'other' + if data.get('modules') and type(data['modules']) != dict: self.log.info( 'Discarded invalid type for modules: %s', diff --git a/tests/sentry/coreapi/tests.py b/tests/sentry/coreapi/tests.py index 421dbebe9760f6..b1d87e352af0d9 100644 --- a/tests/sentry/coreapi/tests.py +++ b/tests/sentry/coreapi/tests.py @@ -288,6 +288,22 @@ def test_release_as_non_string(self): }) assert data.get('release') == '42' + def test_valid_platform(self): + data = self.helper.validate_data(self.project, { + 'platform': 'python', + }) + assert data.get('platform') == 'python' + + def test_no_platform(self): + data = self.helper.validate_data(self.project, {}) + assert data.get('platform') == 'other' + + def test_invalid_platform(self): + data = self.helper.validate_data(self.project, { + 'platform': 'foobar', + }) + assert data.get('platform') == 'other' + class GetInterfaceTest(TestCase): def test_does_not_let_through_disallowed_name(self):