Esempio n. 1
0
    def test_process_event_mutate_and_save(self, mock_default_cache,
                                           mock_save_event):
        project = self.create_project()

        data = {
            "project": project.id,
            "platform": "mattlang",
            "logentry": {
                "formatted": "test"
            },
            "extra": {
                "foo": "bar"
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key="e:1", start_time=1)

        # The event mutated, so make sure we save it back
        (_, (key, event, duration), _), = mock_default_cache.set.mock_calls

        assert key == "e:1"
        assert "extra" not in event
        assert duration == 3600

        mock_save_event.delay.assert_called_once_with(cache_key="e:1",
                                                      data=None,
                                                      start_time=1,
                                                      event_id=None,
                                                      project_id=project.id)
Esempio n. 2
0
    def test_process_event_no_mutate_and_save(self, mock_default_cache,
                                              mock_save_event):
        project = self.create_project()

        data = {
            "project": project.id,
            "platform": "noop",
            "logentry": {
                "formatted": "test"
            },
            "extra": {
                "foo": "bar"
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key="e:1", start_time=1)

        # The event did not mutate, so we shouldn't reset it in cache
        assert mock_default_cache.set.call_count == 0

        mock_save_event.delay.assert_called_once_with(cache_key="e:1",
                                                      data=None,
                                                      start_time=1,
                                                      event_id=None,
                                                      project_id=project.id)
Esempio n. 3
0
    def test_process_event_unprocessed(self, mock_default_cache,
                                       mock_save_event):
        project = self.create_project()

        data = {
            "project": project.id,
            "platform": "holdmeclose",
            "logentry": {
                "formatted": "test"
            },
            "extra": {
                "foo": "bar"
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key="e:1", start_time=1)

        (_, (key, event, duration), _), = mock_default_cache.set.mock_calls
        assert key == "e:1"
        assert event["unprocessed"] is True
        assert duration == 3600

        mock_save_event.delay.assert_called_once_with(cache_key="e:1",
                                                      data=None,
                                                      start_time=1,
                                                      event_id=None,
                                                      project_id=project.id)
Esempio n. 4
0
    def test_process_event_no_mutate_and_save(self, mock_default_cache, mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'noop',
            'logentry': {
                'formatted': 'test',
            },
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        # The event did not mutate, so we shouldn't reset it in cache
        mock_default_cache.set.call_count == 0

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1', data=None, start_time=1, event_id=None,
            project_id=project.id
        )
Esempio n. 5
0
    def test_process_event_mutate_and_save(self, mock_default_cache,
                                           mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'mattlang',
            'logentry': {
                'formatted': 'test',
            },
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        # The event mutated, so make sure we save it back
        (_, (key, event, duration), _), = mock_default_cache.set.mock_calls

        assert key == 'e:1'
        assert 'extra' not in event
        assert duration == 3600

        mock_save_event.delay.assert_called_once_with(cache_key='e:1',
                                                      data=None,
                                                      start_time=1,
                                                      event_id=None,
                                                      project_id=project.id)
Esempio n. 6
0
    def test_process_event_unprocessed(self, mock_default_cache,
                                       mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'holdmeclose',
            'logentry': {
                'formatted': 'test',
            },
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        (_, (key, event, duration), _), = mock_default_cache.set.mock_calls
        assert key == 'e:1'
        assert event['unprocessed'] is True
        assert duration == 3600

        mock_save_event.delay.assert_called_once_with(cache_key='e:1',
                                                      data=None,
                                                      start_time=1,
                                                      event_id=None,
                                                      project_id=project.id)
Esempio n. 7
0
    def test_process_event_unprocessed(self, mock_default_cache, mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'holdmeclose',
            'message': 'test',
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        mock_default_cache.set.assert_called_once_with(
            'e:1', {
                'project': project.id,
                'platform': 'holdmeclose',
                'message': 'test',
                'extra': {
                    'foo': 'bar'
                },
                'unprocessed': True,
            }, 3600
        )

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1', data=None, start_time=1, event_id=None,
            project_id=project.id
        )
Esempio n. 8
0
def test_process_event_mutate_and_save(default_project,
                                       mock_event_processing_store,
                                       mock_save_event, register_plugin):
    register_plugin(globals(), BasicPreprocessorPlugin)

    data = {
        "project": default_project.id,
        "platform": "mattlang",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "foo": "bar"
        },
    }

    mock_event_processing_store.get.return_value = data
    mock_event_processing_store.store.return_value = "e:1"

    process_event(cache_key="e:1", start_time=1)

    # The event mutated, so make sure we save it back
    ((_, (event, ), _), ) = mock_event_processing_store.store.mock_calls

    assert "extra" not in event

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 9
0
    def test_process_event_mutate_and_save(self, mock_default_cache, mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'mattlang',
            'message': 'test',
            'extra': {'foo': 'bar'},
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        # The event mutated, so make sure we save it back
        mock_default_cache.set.assert_called_once_with(
            'e:1', {
                'project': project.id,
                'platform': 'mattlang',
                'message': 'test',
            }, 3600,
        )

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1', data=None, start_time=1,
        )
Esempio n. 10
0
    def test_process_event_unprocessed(self, mock_default_cache, mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'holdmeclose',
            'message': 'test',
            'extra': {'foo': 'bar'},
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        mock_default_cache.set.assert_called_once_with(
            'e:1', {
                'project': project.id,
                'platform': 'holdmeclose',
                'message': 'test',
                'extra': {'foo': 'bar'},
                'unprocessed': True,
            }, 3600
        )

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1', data=None, start_time=1,
        )
Esempio n. 11
0
def test_process_event_no_mutate_and_save(default_project, mock_default_cache,
                                          mock_save_event, register_plugin):
    register_plugin(BasicPreprocessorPlugin)

    data = {
        "project": default_project.id,
        "platform": "noop",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "foo": "bar"
        },
    }

    mock_default_cache.get.return_value = data

    process_event(cache_key="e:1", start_time=1)

    # The event did not mutate, so we shouldn't reset it in cache
    assert mock_default_cache.set.call_count == 0

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 12
0
def test_process_event_unprocessed(default_project, mock_default_cache,
                                   mock_save_event, register_plugin):
    register_plugin(BasicPreprocessorPlugin)

    data = {
        "project": default_project.id,
        "platform": "holdmeclose",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "foo": "bar"
        },
    }

    mock_default_cache.get.return_value = data

    process_event(cache_key="e:1", start_time=1)

    (_, (key, event, duration), _), = mock_default_cache.set.mock_calls
    assert key == "e:1"
    assert event["unprocessed"] is True
    assert duration == 3600

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 13
0
def test_process_event_mutate_and_save(default_project, mock_default_cache,
                                       mock_save_event, register_plugin):
    register_plugin(BasicPreprocessorPlugin)

    data = {
        "project": default_project.id,
        "platform": "mattlang",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "foo": "bar"
        },
    }

    mock_default_cache.get.return_value = data

    process_event(cache_key="e:1", start_time=1)

    # The event mutated, so make sure we save it back
    (_, (key, event, duration), _), = mock_default_cache.set.mock_calls

    assert key == "e:1"
    assert "extra" not in event
    assert duration == 3600

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 14
0
    def test_process_event_mutate_and_save(self, mock_default_cache,
                                           mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'mattlang',
            'message': 'test',
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        # The event mutated, so make sure we save it back
        mock_default_cache.set.assert_called_once_with(
            'e:1',
            {
                'project': project.id,
                'platform': 'mattlang',
                'message': 'test',
            },
            3600,
        )

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1',
            data=None,
            start_time=1,
        )
Esempio n. 15
0
    def test_process_event_no_mutate_and_save(self, mock_default_cache,
                                              mock_save_event):
        project = self.create_project()

        data = {
            'project': project.id,
            'platform': 'noop',
            'message': 'test',
            'extra': {
                'foo': 'bar'
            },
        }

        mock_default_cache.get.return_value = data

        process_event(cache_key='e:1', start_time=1)

        # The event did not mutate, so we shouldn't reset it in cache
        mock_default_cache.set.call_count == 0

        mock_save_event.delay.assert_called_once_with(
            cache_key='e:1',
            data=None,
            start_time=1,
        )
Esempio n. 16
0
def test_process_event_unprocessed(default_project,
                                   mock_event_processing_store,
                                   mock_save_event, register_plugin):
    register_plugin(globals(), BasicPreprocessorPlugin)

    data = {
        "project": default_project.id,
        "platform": "holdmeclose",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "foo": "bar"
        },
    }

    mock_event_processing_store.get.return_value = data
    mock_event_processing_store.store.return_value = "e:1"

    process_event(cache_key="e:1", start_time=1)

    ((_, (event, ), _), ) = mock_event_processing_store.store.mock_calls
    assert event["unprocessed"] is True

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 17
0
def test_scrubbing_after_processing(default_project, default_organization,
                                    mock_save_event, register_plugin,
                                    mock_default_cache):
    @register_plugin
    class TestPlugin(Plugin2):
        def get_event_enhancers(self, data):
            def more_extra(data):
                data["extra"]["new_aaa"] = "remove me"
                return data

            return [more_extra]

        def get_event_preprocessors(self, data):
            # Right now we do not scrub data from event preprocessors, only
            # from event enhancers.
            def more_extra(data):
                data["extra"]["new_aaa2"] = "event preprocessor"
                return data

            return [more_extra]

        def is_enabled(self, project=None):
            return True

    default_project.update_option("sentry:sensitive_fields", ["a"])
    default_project.update_option("sentry:scrub_data", True)

    data = {
        "project": default_project.id,
        "platform": "python",
        "logentry": {
            "formatted": "test"
        },
        "event_id": EVENT_ID,
        "extra": {
            "aaa": "do not remove me"
        },
    }

    mock_default_cache.get.return_value = data

    with Feature({"organizations:datascrubbers-v2": True}):
        process_event(cache_key="e:1", start_time=1)

    (_, (key, event, duration), _), = mock_default_cache.set.mock_calls
    assert key == "e:1"
    assert event["extra"] == {
        u"aaa": u"do not remove me",
        u"new_aaa": u"[Filtered]",
        u"new_aaa2": u"event preprocessor",
    }
    assert duration == 3600

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1",
        data=None,
        start_time=1,
        event_id=EVENT_ID,
        project_id=default_project.id)
Esempio n. 18
0
def test_scrubbing_after_processing(
    default_project,
    default_organization,
    mock_save_event,
    register_plugin,
    mock_default_cache,
    setting_method,
    options_model,
):
    @register_plugin
    class TestPlugin(Plugin2):
        def get_event_preprocessors(self, data):
            # Right now we do not scrub data from event preprocessors
            def more_extra(data):
                data["extra"]["aaa2"] = "event preprocessor"
                return data

            return [more_extra]

        def is_enabled(self, project=None):
            return True

    if setting_method == "datascrubbers":
        options_model.update_option("sentry:sensitive_fields", ["a"])
        options_model.update_option("sentry:scrub_data", True)
    elif setting_method == "piiconfig":
        options_model.update_option(
            "sentry:relay_pii_config", '{"applications": {"extra.aaa": ["@anything:replace"]}}'
        )
    else:
        raise ValueError(setting_method)

    data = {
        "project": default_project.id,
        "platform": "python",
        "logentry": {"formatted": "test"},
        "event_id": EVENT_ID,
        "extra": {"aaa": "remove me"},
    }

    mock_default_cache.get.return_value = data

    with Feature({"organizations:datascrubbers-v2": True}):
        # We pass data_has_changed=True to pretend that we've added "extra" attribute
        # to "data" shortly before (e.g. during symbolication).
        process_event(cache_key="e:1", start_time=1, data_has_changed=True)

    ((_, (key, event, duration), _),) = mock_default_cache.set.mock_calls
    assert key == "e:1"
    assert event["extra"] == {u"aaa": u"[Filtered]", u"aaa2": u"event preprocessor"}
    assert duration == 3600

    mock_save_event.delay.assert_called_once_with(
        cache_key="e:1", data=None, start_time=1, event_id=EVENT_ID, project_id=default_project.id
    )