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

pseudonymization_helper_spec.rb « routing « helpers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10563502555310c3d88660d3769b327bad38f676 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Routing::PseudonymizationHelper do
  let_it_be(:group) { create(:group) }
  let_it_be(:subgroup) { create(:group, parent: group) }
  let_it_be(:project) { create(:project, group: group) }
  let_it_be(:issue) { create(:issue, project: project) }

  let(:merge_request) { create(:merge_request, source_project: project) }

  before do
    stub_feature_flags(mask_page_urls: true)
    allow(helper).to receive(:group).and_return(group)
    allow(helper).to receive(:project).and_return(project)
  end

  shared_examples 'masked url' do
    it 'generates masked page url' do
      expect(helper.masked_page_url).to eq(masked_url)
    end
  end

  describe 'when url has params to mask' do
    context 'with controller for MR' do
      let(:masked_url) { "http://test.host/namespace:#{group.id}/project:#{project.id}/-/merge_requests/#{merge_request.id}" }

      before do
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
         controller: "projects/merge_requests",
         action: "show",
         namespace_id: group.name,
         project_id: project.name,
         id: merge_request.id.to_s
        })
      end

      it_behaves_like 'masked url'
    end

    context 'with controller for issue' do
      let(:masked_url) { "http://test.host/namespace:#{group.id}/project:#{project.id}/-/issues/#{issue.id}" }

      before do
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
         controller: "projects/issues",
         action: "show",
         namespace_id: group.name,
         project_id: project.name,
         id: issue.id.to_s
        })
      end

      it_behaves_like 'masked url'
    end

    context 'with controller for groups with subgroups and project' do
      let(:masked_url) { "http://test.host/namespace:#{subgroup.id}/project:#{project.id}"}

      before do
        allow(helper).to receive(:group).and_return(subgroup)
        allow(helper.project).to receive(:namespace).and_return(subgroup)
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
          controller: 'projects',
          action: 'show',
          namespace_id: subgroup.name,
          id: project.name
        })
      end

      it_behaves_like 'masked url'
    end

    context 'with controller for groups and subgroups' do
      let(:masked_url) { "http://test.host/namespace:#{subgroup.id}"}

      before do
        allow(helper).to receive(:group).and_return(subgroup)
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
          controller: 'groups',
          action: 'show',
          id: subgroup.name
        })
      end

      it_behaves_like 'masked url'
    end

    context 'with controller for blob with file path' do
      let(:masked_url) { "http://test.host/namespace:#{group.id}/project:#{project.id}/-/blob/:repository_path" }

      before do
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
          controller: 'projects/blob',
          action: 'show',
          namespace_id: group.name,
          project_id: project.name,
          id: 'master/README.md'
        })
      end

      it_behaves_like 'masked url'
    end

    context 'with non identifiable controller' do
      let(:masked_url) { "http://test.host/dashboard/issues?assignee_username=root" }

      before do
        controller.request.path = '/dashboard/issues'
        controller.request.query_string = 'assignee_username=root'
        allow(Rails.application.routes).to receive(:recognize_path).and_return({
          controller: 'dashboard',
          action: 'issues'
        })
      end

      it_behaves_like 'masked url'
    end
  end

  describe 'when url has no params to mask' do
    let(:root_url) { 'http://test.host' }

    context 'returns root url' do
      it 'masked_page_url' do
        expect(helper.masked_page_url).to eq(root_url)
      end
    end
  end

  describe 'when feature flag is disabled' do
    before do
      stub_feature_flags(mask_page_urls: false)
    end

    it 'returns nil' do
      expect(helper.masked_page_url).to be_nil
    end
  end
end