summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git_access_wiki_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/git_access_wiki_spec.rb')
-rw-r--r--spec/lib/gitlab/git_access_wiki_spec.rb61
1 files changed, 35 insertions, 26 deletions
diff --git a/spec/lib/gitlab/git_access_wiki_spec.rb b/spec/lib/gitlab/git_access_wiki_spec.rb
index 738269e4a14..688089f4862 100644
--- a/spec/lib/gitlab/git_access_wiki_spec.rb
+++ b/spec/lib/gitlab/git_access_wiki_spec.rb
@@ -4,8 +4,8 @@ require 'spec_helper'
RSpec.describe Gitlab::GitAccessWiki do
let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
- let(:project) { create(:project, :wiki_repo) }
- let(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :wiki_repo) }
+ let_it_be(:user) { create(:user) }
let(:changes) { ['6f6d7e7ed 570e7b2ab refs/heads/master'] }
let(:redirected_path) { nil }
let(:authentication_abilities) do
@@ -17,56 +17,65 @@ RSpec.describe Gitlab::GitAccessWiki do
end
describe '#push_access_check' do
+ subject { access.check('git-receive-pack', changes) }
+
context 'when user can :create_wiki' do
before do
- create(:protected_branch, name: 'master', project: project)
project.add_developer(user)
end
- subject { access.check('git-receive-pack', changes) }
-
it { expect { subject }.not_to raise_error }
context 'when in a read-only GitLab instance' do
+ let(:message) { "You can't push code to a read-only GitLab instance." }
+
before do
allow(Gitlab::Database).to receive(:read_only?) { true }
end
- it 'does not give access to upload wiki code' do
- expect { subject }.to raise_error(Gitlab::GitAccess::ForbiddenError, "You can't push code to a read-only GitLab instance.")
- end
+ it_behaves_like 'forbidden git access'
+ end
+ end
+
+ context 'the user cannot :create_wiki' do
+ it_behaves_like 'not-found git access' do
+ let(:message) { 'The wiki you were looking for could not be found.' }
end
end
end
- describe '#access_check_download!' do
+ describe '#check_download_access!' do
subject { access.check('git-upload-pack', Gitlab::GitAccess::ANY) }
- before do
- project.add_developer(user)
- end
-
- context 'when wiki feature is enabled' do
- it 'give access to download wiki code' do
- expect { subject }.not_to raise_error
+ context 'the user can :download_wiki_code' do
+ before do
+ project.add_developer(user)
end
- context 'when the wiki repository does not exist' do
- let(:project) { create(:project) }
+ context 'when wiki feature is disabled' do
+ before do
+ project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
+ end
- it 'returns not found' do
- expect(project.wiki_repository_exists?).to eq(false)
+ it_behaves_like 'forbidden git access' do
+ let(:message) { include('wiki') }
+ end
+ end
- expect { subject }.to raise_error(Gitlab::GitAccess::NotFoundError, 'A repository for this project does not exist yet.')
+ context 'when the repository does not exist' do
+ before do
+ allow(project.wiki).to receive(:repository).and_return(double('Repository', exists?: false))
+ end
+
+ it_behaves_like 'not-found git access' do
+ let(:message) { include('for this wiki') }
end
end
end
- context 'when wiki feature is disabled' do
- it 'does not give access to download wiki code' do
- project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
-
- expect { subject }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You are not allowed to download code from this project.')
+ context 'the user cannot :download_wiki_code' do
+ it_behaves_like 'not-found git access' do
+ let(:message) { include('wiki') }
end
end
end