Esempio n. 1
0
    def test_content_encoding_gzip(self):
        kwargs = {'message': 'hello'}

        message = json.dumps(kwargs)

        fp = StringIO()

        try:
            f = GzipFile(fileobj=fp, mode='w')
            f.write(message)
        finally:
            f.close()

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        with self.tasks():
            resp = self.client.post(
                self.path, fp.getvalue(),
                content_type='application/octet-stream',
                HTTP_CONTENT_ENCODING='gzip',
                HTTP_X_SENTRY_AUTH=get_auth_header('_postWithHeader', key, secret),
            )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)['id']
        instance = Event.objects.get(event_id=event_id)

        assert instance.message == 'hello'
Esempio n. 2
0
    def test_content_encoding_gzip(self):
        kwargs = {
            "message": "hello",
            "timestamp": iso_format(before_now(seconds=1))
        }

        message = json.dumps(kwargs)

        fp = StringIO()

        try:
            f = GzipFile(fileobj=fp, mode="w")
            f.write(message)
        finally:
            f.close()

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        with self.tasks():
            resp = self.client.post(
                self.path,
                fp.getvalue(),
                content_type="application/octet-stream",
                HTTP_CONTENT_ENCODING="gzip",
                HTTP_X_SENTRY_AUTH=get_auth_header("_postWithHeader", key,
                                                   secret),
            )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)["id"]
        instance = self.get_event(event_id)

        assert instance.message == "hello"
Esempio n. 3
0
    def test_content_encoding_gzip(self):
        kwargs = {'message': 'hello'}

        message = json.dumps(kwargs)

        fp = StringIO()

        try:
            f = GzipFile(fileobj=fp, mode='w')
            f.write(message)
        finally:
            f.close()

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        with self.tasks():
            resp = self.client.post(
                self.path,
                fp.getvalue(),
                content_type='application/octet-stream',
                HTTP_CONTENT_ENCODING='gzip',
                HTTP_X_SENTRY_AUTH=get_auth_header('_postWithHeader', key, secret),
            )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)['id']
        instance = Event.objects.get(event_id=event_id)

        assert instance.message == 'hello'
Esempio n. 4
0
    def test_traceparent_header_wsgi(self):
        # Assert that posting something to store will not create another
        # (transaction) event under any circumstances.
        #
        # We use Werkzeug's test client because Django's test client bypasses a
        # lot of request handling code that we want to test implicitly (such as
        # all our WSGI middlewares and the entire Django instrumentation by
        # sentry-sdk).
        #
        # XXX(markus): Ideally methods such as `_postWithHeader` would always
        # call the WSGI application => swap out Django's test client with e.g.
        # Werkzeug's.
        client = WerkzeugClient(application)

        calls = []

        def new_disable_transaction_events():
            with configure_scope() as scope:
                assert scope.span.sampled
                assert scope.span.transaction
                disable_transaction_events()
                assert not scope.span.sampled

            calls.append(1)

        events = []

        auth = get_auth_header("_postWithWerkzeug/0.0.0",
                               self.projectkey.public_key,
                               self.projectkey.secret_key, "7")

        with mock.patch("sentry.web.api.disable_transaction_events",
                        new_disable_transaction_events):
            with self.tasks():
                with Hub(
                        Client(
                            transport=events.append,
                            integrations=[
                                CeleryIntegration(),
                                DjangoIntegration()
                            ],
                        )):
                    app_iter, status, headers = client.post(
                        reverse("sentry-api-store"),
                        data=b'{"message": "hello"}',
                        headers={
                            "x-sentry-auth": auth,
                            "sentry-trace": "1",
                            "content-type": "application/octet-stream",
                        },
                        environ_base={"REMOTE_ADDR": "127.0.0.1"},
                    )

                    body = "".join(app_iter)

        assert status == "200 OK", body
        assert set(
            (e.get("type"), e.get("transaction"))
            for e in events) == {("transaction", "rule_processor_apply")}
        assert calls == [1]
Esempio n. 5
0
    def test_content_encoding_deflate(self):
        kwargs = {
            "message": "hello",
            "timestamp": iso_format(before_now(seconds=1))
        }
        message = zlib.compress(json.dumps(kwargs))

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        with self.tasks():
            resp = self.client.post(
                self.path,
                message,
                content_type="application/octet-stream",
                HTTP_CONTENT_ENCODING="deflate",
                HTTP_X_SENTRY_AUTH=get_auth_header("_postWithHeader", key,
                                                   secret),
            )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)["id"]
        instance = self.get_event(event_id)

        assert instance.message == "hello"
Esempio n. 6
0
    def test_traceparent_header_wsgi(self):
        # Assert that posting something to store will not create another
        # (transaction) event under any circumstances.
        #
        # We use Werkzeug's test client because Django's test client bypasses a
        # lot of request handling code that we want to test implicitly (such as
        # all our WSGI middlewares and the entire Django instrumentation by
        # sentry-sdk).
        #
        # XXX(markus): Ideally methods such as `_postWithHeader` would always
        # call the WSGI application => swap out Django's test client with e.g.
        # Werkzeug's.
        client = WerkzeugClient(application)

        calls = []

        def new_disable_transaction_events():
            with configure_scope() as scope:
                assert scope.span.sampled
                assert scope.span.transaction
                disable_transaction_events()
                assert not scope.span.sampled

            calls.append(1)

        events = []

        auth = get_auth_header('_postWithWerkzeug/0.0.0',
                               self.projectkey.public_key,
                               self.projectkey.secret_key, '7')

        with mock.patch('sentry.web.api.disable_transaction_events',
                        new_disable_transaction_events):
            with self.tasks():
                with Hub(
                        Client(transport=events.append,
                               integrations=[
                                   CeleryIntegration(),
                                   DjangoIntegration()
                               ])):
                    app_iter, status, headers = client.post(
                        reverse('sentry-api-store'),
                        data=b'{"message": "hello"}',
                        headers={
                            'x-sentry-auth': auth,
                            'sentry-trace': '1',
                            'content-type': 'application/octet-stream',
                        },
                        environ_base={'REMOTE_ADDR': '127.0.0.1'})

                    body = ''.join(app_iter)

        assert status == '200 OK', body
        assert not events
        assert calls == [1]
Esempio n. 7
0
    def relay_setup_fixtures(
        self,
        settings,
        live_server,
        get_relay_store_url,
        get_relay_minidump_url,
        get_relay_unreal_url,
        get_relay_security_url,
        wait_for_ingest_consumer,
    ):
        self.auth_header = get_auth_header(
            "TEST_USER_AGENT/0.0.0", self.projectkey.public_key, self.projectkey.secret_key, "7"
        )

        self.settings = settings
        self.get_relay_store_url = get_relay_store_url  # noqa
        self.get_relay_minidump_url = get_relay_minidump_url  # noqa
        self.get_relay_unreal_url = get_relay_unreal_url  # noqa
        self.get_relay_security_url = get_relay_security_url  # noqa
        self.wait_for_ingest_consumer = wait_for_ingest_consumer(settings)  # noqa
Esempio n. 8
0
    def test_content_encoding_deflate(self):
        kwargs = {'message': 'hello'}

        message = zlib.compress(json.dumps(kwargs))

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        resp = self.client.post(
            self.path, message,
            content_type='application/octet-stream',
            HTTP_CONTENT_ENCODING='deflate',
            HTTP_X_SENTRY_AUTH=get_auth_header('_postWithHeader', key, secret),
        )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)['id']
        instance = Event.objects.get(event_id=event_id)

        assert instance.message == 'hello'
Esempio n. 9
0
    def test_content_encoding_deflate(self):
        kwargs = {'message': 'hello'}

        message = zlib.compress(json.dumps(kwargs))

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        resp = self.client.post(
            self.path, message,
            content_type='application/octet-stream',
            HTTP_CONTENT_ENCODING='deflate',
            HTTP_X_SENTRY_AUTH=get_auth_header('_postWithHeader', key, secret),
        )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)['id']
        instance = Event.objects.get(event_id=event_id)

        assert instance.message == 'hello'
Esempio n. 10
0
    def test_content_encoding_deflate(self):
        kwargs = {"message": "hello"}

        message = zlib.compress(json.dumps(kwargs))

        key = self.projectkey.public_key
        secret = self.projectkey.secret_key

        with self.tasks():
            resp = self.client.post(
                self.path,
                message,
                content_type="application/octet-stream",
                HTTP_CONTENT_ENCODING="deflate",
                HTTP_X_SENTRY_AUTH=get_auth_header("_postWithHeader", key, secret),
            )

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)["id"]
        instance = Event.objects.get(event_id=event_id)

        assert instance.message == "hello"
Esempio n. 11
0
 def test_success(self):
     data = {'message': 'hello', 'server_name': 'not_dcramer.local', 'level': 40, 'site': 'not_a_real_site'}
     message = self._makeMessage(data)
     header = get_auth_header('udpTest', api_key=self.pk.public_key, secret_key=self.pk.secret_key)
     packet = header + '\n\n' + message
     self.assertEquals(None, self.server.handle(packet, self.address))
Esempio n. 12
0
 def setUp(self):  # NOQA
     self.auth_header = get_auth_header("TEST_USER_AGENT/0.0.0",
                                        self.projectkey.public_key,
                                        self.projectkey.secret_key, "7")
     adjust_settings_for_relay_tests(self.settings)