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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2019-01-24 15:49:47 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2019-01-24 15:49:50 +0300
commit26faee772e6956c3949ee227fe1fbb81a90c6a30 (patch)
tree6a0784799617da9103884eccbd878e5fe4817e46 /spec
parentcb632a436287af838cfaa50a7fb12e5f10a1908a (diff)
Merge branch 'security-fix-wiki-access-rights-with-external-wiki-enabled-11-6' into 'security-11-6'
[11.6] Fix access to internal wiki when external wiki is enabled See merge request gitlab/gitlabhq!2801 (cherry picked from commit 1edd23f18210a03ab3e1f6925aa4e434f68cee79) 24a48893 Fixed bug when external wiki is enabled
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/projects_helper_spec.rb20
-rw-r--r--spec/models/ability_spec.rb1
-rw-r--r--spec/models/project_services/external_wiki_service_spec.rb21
-rw-r--r--spec/policies/project_policy_spec.rb24
-rw-r--r--spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb54
5 files changed, 92 insertions, 28 deletions
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 28bd2ff0328..fbbe6c04147 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -358,6 +358,26 @@ describe ProjectsHelper do
end
end
end
+
+ context 'when project has external wiki' do
+ before do
+ allow(project).to receive(:has_external_wiki?).and_return(true)
+ end
+
+ it 'includes external wiki tab' do
+ is_expected.to include(:external_wiki)
+ end
+ end
+
+ context 'when project does not have external wiki' do
+ before do
+ allow(project).to receive(:has_external_wiki?).and_return(false)
+ end
+
+ it 'does not include external wiki tab' do
+ is_expected.not_to include(:external_wiki)
+ end
+ end
end
describe '#show_projects' do
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index 199f49d0bf2..eee80e9bad7 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -298,7 +298,6 @@ describe Ability do
context 'wiki named abilities' do
it 'disables wiki abilities if the project has no wiki' do
- expect(project).to receive(:has_external_wiki?).and_return(false)
expect(subject).not_to be_allowed(:read_wiki)
expect(subject).not_to be_allowed(:create_wiki)
expect(subject).not_to be_allowed(:update_wiki)
diff --git a/spec/models/project_services/external_wiki_service_spec.rb b/spec/models/project_services/external_wiki_service_spec.rb
index 25e6ce7e804..62fd97b038b 100644
--- a/spec/models/project_services/external_wiki_service_spec.rb
+++ b/spec/models/project_services/external_wiki_service_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe ExternalWikiService do
- include ExternalWikiHelper
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
@@ -25,24 +24,4 @@ describe ExternalWikiService do
it { is_expected.not_to validate_presence_of(:external_wiki_url) }
end
end
-
- describe 'External wiki' do
- let(:project) { create(:project) }
-
- context 'when it is active' do
- before do
- properties = { 'external_wiki_url' => 'https://gitlab.com' }
- @service = project.create_external_wiki_service(active: true, properties: properties)
- end
-
- after do
- @service.destroy!
- end
-
- it 'replaces the wiki url' do
- wiki_path = get_project_wiki_path(project)
- expect(wiki_path).to match('https://gitlab.com')
- end
- end
- end
end
diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb
index 00aa000375c..4191e4b18d3 100644
--- a/spec/policies/project_policy_spec.rb
+++ b/spec/policies/project_policy_spec.rb
@@ -102,15 +102,27 @@ describe ProjectPolicy do
expect(Ability).not_to be_allowed(user, :read_issue, project)
end
- context 'when the feature is disabled' do
+ context 'wiki feature' do
+ let(:permissions) { %i(read_wiki create_wiki update_wiki admin_wiki download_wiki_code) }
+
subject { described_class.new(owner, project) }
- before do
- project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
- end
+ context 'when the feature is disabled' do
+ before do
+ project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
+ end
- it 'does not include the wiki permissions' do
- expect_disallowed :read_wiki, :create_wiki, :update_wiki, :admin_wiki, :download_wiki_code
+ it 'does not include the wiki permissions' do
+ expect_disallowed(*permissions)
+ end
+
+ context 'when there is an external wiki' do
+ it 'does not include the wiki permissions' do
+ allow(project).to receive(:has_external_wiki?).and_return(true)
+
+ expect_disallowed(*permissions)
+ end
+ end
end
end
diff --git a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb
index 98d4456b277..7c394ad4bd3 100644
--- a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb
+++ b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb
@@ -49,4 +49,58 @@ describe 'layouts/nav/sidebar/_project' do
expect(rendered).to have_css('.sidebar-top-level-items > li.active', text: 'Registry')
end
end
+
+ describe 'wiki entry tab' do
+ let(:can_read_wiki) { true }
+
+ before do
+ allow(view).to receive(:can?).with(nil, :read_wiki, project).and_return(can_read_wiki)
+ end
+
+ describe 'when wiki is enabled' do
+ it 'shows the wiki tab with the wiki internal link' do
+ render
+
+ expect(rendered).to have_link('Wiki', href: project_wiki_path(project, :home))
+ end
+ end
+
+ describe 'when wiki is disabled' do
+ let(:can_read_wiki) { false }
+
+ it 'does not show the wiki tab' do
+ render
+
+ expect(rendered).not_to have_link('Wiki', href: project_wiki_path(project, :home))
+ end
+ end
+ end
+
+ describe 'external wiki entry tab' do
+ let(:properties) { { 'external_wiki_url' => 'https://gitlab.com' } }
+ let(:service_status) { true }
+
+ before do
+ project.create_external_wiki_service(active: service_status, properties: properties)
+ project.reload
+ end
+
+ context 'when it is active' do
+ it 'shows the external wiki tab with the external wiki service link' do
+ render
+
+ expect(rendered).to have_link('External Wiki', href: properties['external_wiki_url'])
+ end
+ end
+
+ context 'when it is disabled' do
+ let(:service_status) { false }
+
+ it 'does not show the external wiki tab' do
+ render
+
+ expect(rendered).not_to have_link('External Wiki', href: project_wiki_path(project, :home))
+ end
+ end
+ end
end