Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-01-22 21:10:56 +0300
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-02-06 16:35:35 +0300
commitbc78ae6985ee37f9ac2ffc2dbf6f445078d16038 (patch)
tree1b53d4292becd29f1fe37a4fbb3e1562b3b80c40 /spec/lib/gitlab/git_access_spec.rb
parent32b2ff26011a5274bdb8a3dd41ad360a67c3148a (diff)
Add specs
Diffstat (limited to 'spec/lib/gitlab/git_access_spec.rb')
-rw-r--r--spec/lib/gitlab/git_access_spec.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb
index 457e219c1a5..3c98c95e301 100644
--- a/spec/lib/gitlab/git_access_spec.rb
+++ b/spec/lib/gitlab/git_access_spec.rb
@@ -152,6 +152,30 @@ describe Gitlab::GitAccess do
expect { push_access_check }.to raise_not_found
end
end
+
+ context 'when user is allowed to create project in namespace' do
+ let(:access) { described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path, target_namespace: user.namespace) }
+
+ it 'blocks pull access with "not found"' do
+ expect { pull_access_check }.to raise_not_found
+ end
+
+ it 'allows push access' do
+ expect { push_access_check }.not_to raise_error
+ end
+ end
+
+ context 'when user is not allowed to create project in namespace' do
+ let(:user2) { create(:user) }
+ let(:access) { described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path, target_namespace: user2.namespace) }
+
+ it 'blocks push and pull with "not found"' do
+ aggregate_failures do
+ expect { pull_access_check }.to raise_not_found
+ expect { push_access_check }.to raise_not_found
+ end
+ end
+ end
end
end
@@ -311,6 +335,51 @@ describe Gitlab::GitAccess do
end
end
+ describe '#check_namespace_accessibility!' do
+ context 'when project exists' do
+ context 'when user can pull or push' do
+ before do
+ project.add_master(user)
+ end
+
+ it 'does not block pull or push' do
+ aggregate_failures do
+ expect { push_access_check }.not_to raise_error
+ expect { pull_access_check }.not_to raise_error
+ end
+ end
+ end
+ end
+
+ context 'when project does not exist' do
+ context 'when namespace does not exist' do
+ let(:access) { described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path, target_namespace: nil) }
+
+ it 'blocks push and pull' do
+ aggregate_failures do
+ expect { push_access_check }.not_to raise_namespace_not_found
+ expect { pull_access_check }.not_to raise_namespace_not_found
+ end
+ end
+ end
+
+ context 'when namespace exists' do
+ context 'when user is unable to push to namespace' do
+ let(:user2) { create(:user) }
+ let(:access) { described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path, target_namespace: user2.namespace) }
+
+ it 'blocks push' do
+ expect { push_access_check }.to raise_project_create
+ end
+
+ it 'does not block pull' do
+ expect { push_access_check }.to raise_error
+ end
+ end
+ end
+ end
+ end
+
describe '#check_download_access!' do
it 'allows masters to pull' do
project.add_master(user)
@@ -773,6 +842,16 @@ describe Gitlab::GitAccess do
Gitlab::GitAccess::ERROR_MESSAGES[:project_not_found])
end
+ def raise_namespace_not_found
+ raise_error(Gitlab::GitAccess::NotFoundError,
+ Gitlab::GitAccess::ERROR_MESSAGES[:namespace_not_found])
+ end
+
+ def raise_project_create
+ raise_error(Gitlab::GitAccess::NotFoundError,
+ Gitlab::GitAccess::ERROR_MESSAGES[:create])
+ end
+
def build_authentication_abilities
[
:read_project,