2019-11-08 03:06:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-10-07 13:05:24 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::GitAccessWiki do
|
2020-07-21 18:09:45 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
2020-10-05 15:08:56 +00:00
|
|
|
let_it_be(:project) { create(:project, :wiki_repo) }
|
|
|
|
let_it_be(:wiki) { create(:project_wiki, project: project) }
|
2021-04-21 06:09:28 +00:00
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
let(:changes) { ['6f6d7e7ed 570e7b2ab refs/heads/master'] }
|
2020-10-05 15:08:56 +00:00
|
|
|
let(:authentication_abilities) { %i[read_project download_code push_code] }
|
2017-06-16 00:03:54 +00:00
|
|
|
let(:redirected_path) { nil }
|
2020-10-05 15:08:56 +00:00
|
|
|
|
|
|
|
let(:access) do
|
|
|
|
described_class.new(user, wiki, 'web',
|
|
|
|
authentication_abilities: authentication_abilities,
|
|
|
|
redirected_path: redirected_path)
|
2016-09-15 13:40:53 +00:00
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
describe '#push_access_check' do
|
2020-07-21 18:09:45 +00:00
|
|
|
subject { access.check('git-receive-pack', changes) }
|
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
context 'when user can :create_wiki' do
|
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_developer(user)
|
2017-09-19 07:44:58 +00:00
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
it { expect { subject }.not_to raise_error }
|
|
|
|
|
|
|
|
context 'when in a read-only GitLab instance' do
|
2020-07-21 18:09:45 +00:00
|
|
|
let(:message) { "You can't push code to a read-only GitLab instance." }
|
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
before do
|
2021-08-02 09:10:09 +00:00
|
|
|
allow(Gitlab::Database).to receive(:read_only?) { true }
|
2017-09-19 07:44:58 +00:00
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
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.' }
|
2017-09-19 07:44:58 +00:00
|
|
|
end
|
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
end
|
2016-11-29 19:31:42 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
describe '#check_download_access!' do
|
2018-12-20 16:25:48 +00:00
|
|
|
subject { access.check('git-upload-pack', Gitlab::GitAccess::ANY) }
|
2016-11-29 19:31:42 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
context 'the user can :download_wiki_code' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
2018-02-22 00:20:30 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
context 'when wiki feature is disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
|
|
|
|
end
|
2018-02-22 00:20:30 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
it_behaves_like 'forbidden git access' do
|
|
|
|
let(:message) { include('wiki') }
|
|
|
|
end
|
|
|
|
end
|
2018-02-22 00:20:30 +00:00
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
context 'when the repository does not exist' do
|
|
|
|
before do
|
2020-10-05 15:08:56 +00:00
|
|
|
allow(wiki.repository).to receive(:exists?).and_return(false)
|
2020-07-21 18:09:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'not-found git access' do
|
|
|
|
let(:message) { include('for this wiki') }
|
2018-02-22 00:20:30 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
|
|
|
|
2020-07-21 18:09:45 +00:00
|
|
|
context 'the user cannot :download_wiki_code' do
|
|
|
|
it_behaves_like 'not-found git access' do
|
|
|
|
let(:message) { include('wiki') }
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
|
|
|
end
|
2021-12-07 03:12:22 +00:00
|
|
|
|
|
|
|
context 'when the actor is a deploy token' do
|
|
|
|
let_it_be(:actor) { create(:deploy_token, projects: [project]) }
|
|
|
|
let_it_be(:user) { actor }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attribute(:wiki_access_level, wiki_access_level)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { access.check('git-upload-pack', changes) }
|
|
|
|
|
|
|
|
context 'when the wiki is enabled' do
|
|
|
|
let(:wiki_access_level) { ProjectFeature::ENABLED }
|
|
|
|
|
|
|
|
it { expect { subject }.not_to raise_error }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the wiki is disabled' do
|
|
|
|
let(:wiki_access_level) { ProjectFeature::DISABLED }
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden git access' do
|
|
|
|
let(:message) { 'You are not allowed to download files from this wiki.' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
end
|