2014-10-07 13:05:24 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Gitlab::GitAccessWiki do
|
2017-07-25 17:09:00 +00:00
|
|
|
let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
|
2018-02-22 00:20:30 +00:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2014-10-07 13:05:24 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-09-19 07:44:58 +00:00
|
|
|
let(:changes) { ['6f6d7e7ed 570e7b2ab refs/heads/master'] }
|
2017-06-16 00:03:54 +00:00
|
|
|
let(:redirected_path) { nil }
|
2016-09-16 07:59:10 +00:00
|
|
|
let(:authentication_abilities) do
|
2016-09-15 13:40:53 +00:00
|
|
|
[
|
|
|
|
:read_project,
|
|
|
|
:download_code,
|
|
|
|
:push_code
|
|
|
|
]
|
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
describe '#push_access_check' do
|
|
|
|
context 'when user can :create_wiki' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, name: 'master', project: project)
|
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
|
|
|
subject { access.check('git-receive-pack', changes) }
|
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
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Database).to receive(:read_only?) { true }
|
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
it 'does not give access to upload wiki code' do
|
|
|
|
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "You can't push code to a read-only GitLab instance.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
end
|
2016-11-29 19:31:42 +00:00
|
|
|
|
2016-12-20 13:19:07 +00:00
|
|
|
describe '#access_check_download!' do
|
2016-11-29 19:31:42 +00:00
|
|
|
subject { access.check('git-upload-pack', '_any') }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_developer(user)
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki feature is enabled' do
|
|
|
|
it 'give access to download wiki code' do
|
2017-05-19 19:58:45 +00:00
|
|
|
expect { subject }.not_to raise_error
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
2018-02-22 00:20:30 +00:00
|
|
|
|
|
|
|
context 'when the wiki repository does not exist' do
|
|
|
|
it 'returns not found' do
|
|
|
|
wiki_repo = project.wiki.repository
|
2018-06-14 11:18:25 +00:00
|
|
|
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
FileUtils.rm_rf(wiki_repo.path)
|
|
|
|
end
|
2018-02-22 00:20:30 +00:00
|
|
|
|
|
|
|
# Sanity check for rm_rf
|
|
|
|
expect(wiki_repo.exists?).to eq(false)
|
|
|
|
|
2018-02-22 18:51:00 +00:00
|
|
|
expect { subject }.to raise_error(Gitlab::GitAccess::NotFoundError, 'A repository for this project does not exist yet.')
|
2018-02-22 00:20:30 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-29 19:31:42 +00:00
|
|
|
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)
|
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, 'You are not allowed to download code from this project.')
|
2016-11-29 19:31:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-07 13:05:24 +00:00
|
|
|
end
|