summaryrefslogtreecommitdiff
path: root/spec/models/project_tracing_setting_spec.rb
blob: a7e4e557b2588c58e19970bbf65c3917f448cafc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProjectTracingSetting do
  describe '#external_url' do
    let_it_be(:project) { create(:project) }

    let(:tracing_setting) { project.build_tracing_setting }

    describe 'Validations' do
      describe 'external_url' do
        it 'accepts a valid url' do
          tracing_setting.external_url = 'https://gitlab.com'

          expect(tracing_setting).to be_valid
        end

        it 'fails with an invalid url' do
          tracing_setting.external_url = 'gitlab.com'

          expect(tracing_setting).to be_invalid
        end

        it 'fails with a blank string' do
          tracing_setting.external_url = nil

          expect(tracing_setting).to be_invalid
        end

        it 'sanitizes the url' do
          tracing_setting.external_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}

          expect(tracing_setting).to be_valid
          expect(tracing_setting.external_url).to eq(%{https://replaceme.com/'&gt;})
        end
      end
    end
  end
end