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

require 'spec_helper'

describe ProjectMetricsSetting do
  describe 'Associations' do
    it { is_expected.to belong_to(:project) }
  end

  describe 'Validations' do
    context 'when external_dashboard_url is over 255 chars' do
      before do
        subject.external_dashboard_url = 'https://' + 'a' * 250
      end

      it 'fails validation' do
        expect(subject).not_to be_valid
        expect(subject.errors.messages[:external_dashboard_url])
          .to include('is too long (maximum is 255 characters)')
      end
    end

    context 'with unsafe url' do
      before do
        subject.external_dashboard_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}
      end

      it { is_expected.to be_invalid }
    end

    context 'non ascii chars in external_dashboard_url' do
      before do
        subject.external_dashboard_url = 'http://gitlab.com/api/0/projects/project1/something€'
      end

      it { is_expected.to be_invalid }
    end

    context 'internal url in external_dashboard_url' do
      before do
        subject.external_dashboard_url = 'http://192.168.1.1'
      end

      it { is_expected.to be_valid }
    end

    context 'external_dashboard_url is blank' do
      before do
        subject.external_dashboard_url = ''
      end

      it { is_expected.to be_invalid }
    end
  end
end