summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/error_tracking/processor/sanitize_error_message_processor_spec.rb
blob: b4173617a14c57b0528f9ff9b84542f0d85ff460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ErrorTracking::Processor::SanitizeErrorMessageProcessor, :sentry do
  describe '.call' do
    let(:exception) { StandardError.new('raw error') }
    let(:event) { Raven::Event.from_exception(exception, raven_required_options) }
    let(:result_hash) { described_class.call(event).to_hash }
    let(:raven_required_options) do
      {
        configuration: Raven.configuration,
        context: Raven.context,
        breadcrumbs: Raven.breadcrumbs
      }
    end

    it 'cleans the exception message' do
      expect(Gitlab::Sanitizers::ExceptionMessage).to receive(:clean).with('StandardError', 'raw error').and_return('cleaned')

      expect(result_hash[:exception][:values].first).to include(
        type: 'StandardError',
        value: 'cleaned'
      )
    end

    context 'when event is invalid' do
      let(:event) { instance_double('Raven::Event', to_hash: { invalid: true }) }

      it 'does nothing' do
        extracted_exception = instance_double('Raven::SingleExceptionInterface', value: nil)
        allow(described_class).to receive(:extract_exceptions_from).and_return([extracted_exception])

        expect(Gitlab::Sanitizers::ExceptionMessage).not_to receive(:clean)
        expect(result_hash).to eq(invalid: true)
      end
    end
  end
end