diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/git_access_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/git_access_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 150 |
1 files changed, 10 insertions, 140 deletions
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index a29c56c598f..7c09fc5cc79 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::GitAccess do let(:actor) { user } let(:project) { create(:project, :repository) } - let(:project_path) { project.path } + let(:project_path) { project&.path } let(:namespace_path) { project&.namespace&.path } let(:protocol) { 'ssh' } let(:authentication_abilities) { %i[read_project download_code push_code] } @@ -89,13 +89,14 @@ describe Gitlab::GitAccess do end end - context 'when namespace does not exist' do + context 'when namespace and project are nil' do + let(:project) { nil } let(:namespace_path) { nil } it 'does not allow push and pull access' do aggregate_failures do - expect { push_access_check }.to raise_not_found - expect { pull_access_check }.to raise_not_found + expect { push_access_check }.to raise_namespace_not_found + expect { pull_access_check }.to raise_namespace_not_found end end end @@ -227,6 +228,7 @@ describe Gitlab::GitAccess do context 'when the project is nil' do let(:project) { nil } let(:project_path) { "new-project" } + let(:namespace_path) { user.namespace.path } it 'blocks push and pull with "not found"' do aggregate_failures do @@ -234,42 +236,6 @@ 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(:namespace_path) { user.namespace.path } - let(:access) do - described_class.new(actor, nil, - protocol, authentication_abilities: authentication_abilities, - repository_path: project_path, namespace_path: namespace_path, - redirected_path: redirected_path) - end - - 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(:namespace_path) { user2.namespace.path } - let(:access) do - described_class.new(actor, nil, - protocol, authentication_abilities: authentication_abilities, - repository_path: project_path, namespace_path: namespace_path, - redirected_path: redirected_path) - end - - 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 @@ -449,106 +415,6 @@ describe Gitlab::GitAccess do end end - describe '#ensure_project_on_push!' do - let(:access) do - described_class.new(actor, project, - protocol, authentication_abilities: authentication_abilities, - repository_path: project_path, namespace_path: namespace_path, - redirected_path: redirected_path) - end - - context 'when push' do - let(:cmd) { 'git-receive-pack' } - - context 'when project does not exist' do - let(:project_path) { "nonexistent" } - let(:project) { nil } - - context 'when changes is _any' do - let(:changes) { Gitlab::GitAccess::ANY } - - context 'when authentication abilities include push code' do - let(:authentication_abilities) { [:push_code] } - - context 'when user can create project in namespace' do - let(:namespace_path) { user.namespace.path } - - it 'creates a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.to change { Project.count }.by(1) - end - end - - context 'when user cannot create project in namespace' do - let(:user2) { create(:user) } - let(:namespace_path) { user2.namespace.path } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - end - - context 'when authentication abilities do not include push code' do - let(:authentication_abilities) { [] } - - context 'when user can create project in namespace' do - let(:namespace_path) { user.namespace.path } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - end - end - - context 'when check contains actual changes' do - let(:changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch" } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - end - - context 'when project exists' do - let(:changes) { Gitlab::GitAccess::ANY } - let!(:project) { create(:project) } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - - context 'when deploy key is used' do - let(:key) { create(:deploy_key, user: user) } - let(:actor) { key } - let(:project_path) { "nonexistent" } - let(:project) { nil } - let(:namespace_path) { user.namespace.path } - let(:changes) { Gitlab::GitAccess::ANY } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - end - - context 'when pull' do - let(:cmd) { 'git-upload-pack' } - let(:changes) { Gitlab::GitAccess::ANY } - - context 'when project does not exist' do - let(:project_path) { "new-project" } - let(:namespace_path) { user.namespace.path } - let(:project) { nil } - - it 'does not create a new project' do - expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } - end - end - end - end - describe '#check_download_access!' do it 'allows maintainers to pull' do project.add_maintainer(user) @@ -1219,6 +1085,10 @@ describe Gitlab::GitAccess do raise_error(Gitlab::GitAccess::NotFoundError, 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 build_authentication_abilities [ :read_project, |