Welcome to mirror list, hosted at ThFree Co, Russian Federation.

exception_message_spec.rb « sanitizers « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b54b3532352e9b423405b7f72a6a760ad727ab6 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

RSpec.describe Gitlab::Sanitizers::ExceptionMessage do
  describe '.clean' do
    let(:exception_name) { exception.class.name }
    let(:exception_message) { exception.message }

    subject { described_class.clean(exception_name, exception_message) }

    context 'when error is a URI::InvalidURIError' do
      let(:exception) do
        URI.parse('http://foo:bar')
      rescue URI::InvalidURIError => error
        error
      end

      it { is_expected.to eq('bad URI(is not URI?): [FILTERED]') }
    end

    context 'when error is an Addressable::URI::InvalidURIError' do
      using RSpec::Parameterized::TableSyntax

      let(:exception) do
        Addressable::URI.parse(uri)
      rescue Addressable::URI::InvalidURIError => error
        error
      end

      where(:uri, :result) do
        'http://foo:bar' | 'Invalid port number: [FILTERED]'
        'http://foo:%eb' | 'Invalid encoding in port'
        'ht%0atp://foo'  | 'Invalid scheme format: [FILTERED]'
        'http:'          | 'Absolute URI missing hierarchical segment: [FILTERED]'
        '::http'         | 'Cannot assemble URI string with ambiguous path: [FILTERED]'
        'http://foo bar' | 'Invalid character in host: [FILTERED]'
      end

      with_them do
        it { is_expected.to eq(result) }
      end
    end

    context 'with any other exception' do
      let(:exception) { StandardError.new('Error message: http://foo@bar:baz@ex:ample.com') }

      it 'is not invoked and does nothing' do
        is_expected.to eq('Error message: http://foo@bar:baz@ex:ample.com')
      end
    end
  end
end