def _dispatch(self, request, helper, sentry_key, project_id=None, origin=None, *args, **kwargs): if request.method != 'POST': return HttpResponseNotAllowed(['POST']) content_type = request.META.get('CONTENT_TYPE') if content_type is None or not content_type.startswith( self.content_types): raise APIError('Invalid Content-Type') request.user = AnonymousUser() project = self._get_project_from_id(project_id) helper.context.bind_project(project) auth = Auth({'sentry_key': sentry_key}, is_public=False) auth.client = 'sentry.unreal_engine' key = helper.project_key_from_auth(auth) if key.project_id != project.id: raise APIError('Two different projects were specified') helper.context.bind_auth(auth) return super(APIView, self).dispatch(request=request, project=project, auth=auth, helper=helper, key=key, **kwargs)
def _dispatch(self, request, helper, sentry_key, project_id=None, origin=None, *args, **kwargs): if request.method != 'POST': track_outcome(0, 0, None, Outcome.INVALID, "disallowed_method") return HttpResponseNotAllowed(['POST']) content_type = request.META.get('CONTENT_TYPE') if content_type is None or not content_type.startswith(self.content_types): track_outcome(0, 0, None, Outcome.INVALID, "content_type") raise APIError('Invalid Content-Type') request.user = AnonymousUser() project = self._get_project_from_id(project_id) helper.context.bind_project(project) auth = Auth({'sentry_key': sentry_key}, is_public=False) auth.client = 'sentry.unreal_engine' key = helper.project_key_from_auth(auth) if key.project_id != project.id: track_outcome( project.organization_id, project.id, None, Outcome.INVALID, "multi_project_id") raise APIError('Two different projects were specified') helper.context.bind_auth(auth) return super(APIView, self).dispatch( request=request, project=project, auth=auth, helper=helper, key=key, **kwargs )
def _dispatch(self, request, helper, project_config, sentry_key, origin=None, config_flags=None, *args, **kwargs): if request.method != 'POST': track_outcome(0, 0, None, Outcome.INVALID, "disallowed_method") return HttpResponseNotAllowed(['POST']) content_type = request.META.get('CONTENT_TYPE') if content_type is None or not content_type.startswith(self.content_types): track_outcome(0, 0, None, Outcome.INVALID, "content_type") raise APIError('Invalid Content-Type') request.user = AnonymousUser() project = project_config.project project_id = project_config.project_id auth = Auth(public_key=sentry_key, is_public=False) auth.client = 'sentry.unreal_engine' key = helper.project_key_from_auth(auth) if key.project_id != project_id: track_outcome( project_config.organization_id, project_id, None, Outcome.INVALID, "multi_project_id") raise APIError('Two different projects were specified') helper.context.bind_auth(auth) return super(APIView, self).dispatch( request=request, project=project, auth=auth, helper=helper, key=key, project_config=project_config, **kwargs )
def process_event_from_kafka(message): project = Project.objects.get_from_cache(pk=message['project_id']) remote_addr = message['remote_addr'] helper = ClientApiHelper( agent=message['agent'], project_id=project.id, ip_address=remote_addr, ) helper.context.bind_project(project) auth = Auth(message['auth'], message['auth'].pop('is_public')) helper.context.bind_auth(auth) key = helper.project_key_from_auth(auth) data = message['data'] version = data['version'] event_manager = EventManager( data, project=project, key=key, auth=auth, client_ip=remote_addr, user_agent=helper.context.agent, version=version, ) event_manager._normalized = True del data return process_event(event_manager, project, key, remote_addr, helper, attachments=None)
def process_event_from_kafka(message): from sentry.models import Project project = Project.objects.get_from_cache(pk=message['project_id']) event_type = message['type'] view = type_name_to_view[event_type] helper_cls = view.helper_cls remote_addr = message['remote_addr'] helper = helper_cls( agent=message['agent'], project_id=project.id, ip_address=remote_addr, ) auth = Auth(message['auth'], message['auth'].pop('is_public')) helper.context.bind_auth(auth) key = helper.project_key_from_auth(auth) data = message['data'] version = data['version'] event_manager = EventManager( data, project=project, key=key, auth=auth, client_ip=remote_addr, user_agent=helper.context.agent, version=version, ) event_manager._normalized = True del data return process_event(event_type, event_manager, project, key, remote_addr, helper, attachments=None)
def test_valid_with_key(self): auth = Auth({'sentry_key': self.pk.public_key}) result = self.helper.project_from_auth(auth) self.assertEquals(result, self.project)
def test_invalid_if_missing_key(self): self.assertRaises(APIUnauthorized, self.helper.project_from_auth, Auth({}))
def test_nonascii_key(self): auth = Auth({'sentry_key': '\xc3\xbc'}) with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_secret(self): auth = Auth({'sentry_key': self.pk.public_key, 'sentry_secret': 'z'}) with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_key(self): auth = Auth({'sentry_key': 'z'}) with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_key(self): auth = Auth(public_key="z") with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_if_missing_key(self): with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(Auth({}))
def test_nonascii_key(self): auth = Auth({'sentry_key': '\xc3\xbc'}) self.assertRaises(APIUnauthorized, self.helper.project_id_from_auth, auth)
def test_nonascii_key(self): auth = Auth(public_key='\xc3\xbc') with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_secret(self): auth = Auth(public_key=self.pk.public_key, secret_key='z') with pytest.raises(APIUnauthorized): self.helper.project_id_from_auth(auth)
def test_invalid_key(self): auth = Auth({'sentry_key': 'z'}) self.assertRaises(APIUnauthorized, self.helper.project_from_auth, auth)
def test_invalid_secret(self): auth = Auth({'sentry_key': self.pk.public_key, 'sentry_secret': 'z'}) self.assertRaises(APIUnauthorized, self.helper.project_from_auth, auth)
def test_valid_with_key(self): auth = Auth({'sentry_key': self.pk.public_key}) result = self.helper.project_id_from_auth(auth) assert result == self.project.id