summaryrefslogtreecommitdiff
path: root/spec/views/projects/settings/operations/show.html.haml_spec.rb
blob: e6d53c526e254e8d5ab2f01ab23d05dd2a317b4a (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'projects/settings/operations/show' do
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user) }

  let_it_be(:error_tracking_setting) do
    create(:project_error_tracking_setting, project: project)
  end

  let_it_be_with_reload(:tracing_setting) do
    create(:project_tracing_setting, project: project)
  end

  let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }

  before_all do
    project.add_maintainer(user)
  end

  before do
    assign :project, project

    allow(view).to receive(:error_tracking_setting)
      .and_return(error_tracking_setting)
    allow(view).to receive(:tracing_setting)
      .and_return(tracing_setting)
    allow(view).to receive(:prometheus_service)
      .and_return(prometheus_service)
    allow(view).to receive(:current_user).and_return(user)
  end

  describe 'Operations > Alerts' do
    it 'renders the Operations Settings page' do
      render

      expect(rendered).to have_content _('Alert integrations')
      expect(rendered).to have_content _('Display alerts from all configured monitoring tools.')
    end
  end

  describe 'Operations > Error Tracking' do
    context 'Settings page ' do
      it 'renders the Operations Settings page' do
        render

        expect(rendered).to have_content _('Error tracking')
        expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token')
      end
    end
  end

  describe 'Operations > Prometheus' do
    context 'when settings_operations_prometheus_service flag is enabled' do
      it 'renders the Operations Settings page' do
        render

        expect(rendered).to have_content _('Prometheus')
        expect(rendered).to have_content _('Link Prometheus monitoring to GitLab.')
        expect(rendered).to have_content _('To enable the installation of Prometheus on your clusters, deactivate the manual configuration.')
      end
    end

    context 'when settings_operations_prometheus_service is disabled' do
      before do
        stub_feature_flags(settings_operations_prometheus_service: false)
      end

      it 'renders the Operations Settings page' do
        render

        expect(rendered).not_to have_content _('Auto configuration settings are used unless you override their values here.')
      end
    end
  end

  describe 'Operations > Tracing' do
    context 'with project.tracing_external_url' do
      it 'links to project.tracing_external_url' do
        render

        expect(rendered).to have_link('Tracing', href: tracing_setting.external_url)
      end

      context 'with malicious external_url' do
        let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" }
        let(:cleaned_url) { "https://replaceme.com/'>" }

        before do
          tracing_setting.update_column(:external_url, malicious_tracing_url)
        end

        it 'sanitizes external_url' do
          render

          expect(tracing_setting.external_url).to eq(malicious_tracing_url)
          expect(rendered).to have_link('Tracing', href: cleaned_url)
        end
      end
    end

    context 'without project.tracing_external_url' do
      let(:tracing_setting) { build(:project_tracing_setting, project: project) }

      before do
        tracing_setting.external_url = nil
      end

      it 'links to Tracing page' do
        render

        expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
      end
    end
  end
end