debian-mirror-gitlab/spec/lib/gitlab/git_access_wiki_spec.rb

83 lines
2.3 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::GitAccessWiki do
2017-09-10 17:25:29 +05:30
let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
2020-10-24 23:57:45 +05:30
let_it_be(:project) { create(:project, :wiki_repo) }
let_it_be(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
let(:changes) { ['6f6d7e7ed 570e7b2ab refs/heads/master'] }
2017-09-10 17:25:29 +05:30
let(:redirected_path) { nil }
2016-09-29 09:46:39 +05:30
let(:authentication_abilities) do
[
:read_project,
:download_code,
:push_code
]
end
2015-04-26 12:48:37 +05:30
2018-03-17 18:26:18 +05:30
describe '#push_access_check' do
2020-10-24 23:57:45 +05:30
subject { access.check('git-receive-pack', changes) }
2018-03-17 18:26:18 +05:30
context 'when user can :create_wiki' do
before do
project.add_developer(user)
end
2015-04-26 12:48:37 +05:30
2018-03-17 18:26:18 +05:30
it { expect { subject }.not_to raise_error }
context 'when in a read-only GitLab instance' do
2020-10-24 23:57:45 +05:30
let(:message) { "You can't push code to a read-only GitLab instance." }
2018-03-17 18:26:18 +05:30
before do
allow(Gitlab::Database).to receive(:read_only?) { true }
end
2015-04-26 12:48:37 +05:30
2020-10-24 23:57:45 +05:30
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.' }
2018-03-17 18:26:18 +05:30
end
end
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
describe '#check_download_access!' do
2019-02-15 15:39:39 +05:30
subject { access.check('git-upload-pack', Gitlab::GitAccess::ANY) }
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
context 'the user can :download_wiki_code' do
before do
project.add_developer(user)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
2020-10-24 23:57:45 +05:30
context 'when wiki feature is disabled' do
before do
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
end
2018-03-17 18:26:18 +05:30
2020-10-24 23:57:45 +05:30
it_behaves_like 'forbidden git access' do
let(:message) { include('wiki') }
end
end
2018-03-17 18:26:18 +05:30
2020-10-24 23:57:45 +05:30
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') }
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
end
2020-10-24 23:57:45 +05:30
context 'the user cannot :download_wiki_code' do
it_behaves_like 'not-found git access' do
let(:message) { include('wiki') }
2017-08-17 22:00:37 +05:30
end
end
end
2015-04-26 12:48:37 +05:30
end