Skip to content

Commit

Permalink
Limit platform to supported values (fixes GH-2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Nov 23, 2015
1 parent 124cc7d commit 63eddde
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/sentry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/coreapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
16 changes: 16 additions & 0 deletions tests/sentry/coreapi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 63eddde

Please sign in to comment.