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