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

show.html.haml_spec.rb « tracing « projects « views « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96dc6a18fc7448362f4a84be9cee932401cd3b57 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'projects/tracings/show' do
  let_it_be_with_reload(:project) { create(:project) }
  let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) }

  before do
    assign(:project, project)
    allow(view).to receive(:error_tracking_setting)
      .and_return(error_tracking_setting)
  end

  context 'with project.tracing_external_url' do
    let_it_be(:tracing_url) { 'https://tracing.url' }
    let_it_be(:tracing_setting) { create(:project_tracing_setting, project: project, external_url: tracing_url) }

    before do
      allow(view).to receive(:can?).and_return(true)
      allow(view).to receive(:tracing_setting).and_return(tracing_setting)
    end

    it 'renders iframe' do
      render

      expect(rendered).to match(/iframe/)
    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/'&gt;" }

      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_xpath("//iframe[@src=\"#{cleaned_url}\"]")
      end
    end
  end

  context 'without project.tracing_external_url' do
    before do
      allow(view).to receive(:can?).and_return(true)
    end

    it 'renders empty state' do
      render

      expect(rendered).to have_link('Add Jaeger URL')
      expect(rendered).not_to match(/iframe/)
    end
  end
end