Commit 7180b0ab authored by Stan Hu's avatar Stan Hu

Merge branch '207871-namespace-check' into 'master'

Extract namespace check out of project check

See merge request gitlab-org/gitlab!33137
parents 07d27467 41526de5
......@@ -24,6 +24,7 @@ module Gitlab
deploy_key_upload: 'This deploy key does not have write access to this project.',
no_repo: 'A repository for this project does not exist yet.',
project_not_found: 'The project you were looking for could not be found.',
namespace_not_found: 'The namespace you were looking for could not be found.',
command_not_allowed: "The command you're trying to execute is not allowed.",
upload_pack_disabled_over_http: 'Pulling over HTTP is not allowed.',
receive_pack_disabled_over_http: 'Pushing over HTTP is not allowed.',
......@@ -73,6 +74,7 @@ module Gitlab
return custom_action if custom_action
check_db_accessibility!(cmd)
check_namespace!
check_project!(changes, cmd)
check_repository_existence!
......@@ -111,7 +113,6 @@ module Gitlab
private
def check_project!(changes, cmd)
check_namespace!
ensure_project_on_push!(cmd, changes)
check_project_accessibility!
add_project_moved_message!
......@@ -156,7 +157,7 @@ module Gitlab
def check_namespace!
return if namespace_path.present?
raise NotFoundError, ERROR_MESSAGES[:project_not_found]
raise NotFoundError, ERROR_MESSAGES[:namespace_not_found]
end
def check_active_user!
......
......@@ -39,11 +39,17 @@ module Gitlab
private
override :check_namespace!
def check_namespace!
return unless snippet.is_a?(ProjectSnippet)
super
end
override :check_project!
def check_project!(cmd, changes)
return unless snippet.is_a?(ProjectSnippet)
check_namespace!
check_project_accessibility!
add_project_moved_message!
end
......
......@@ -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
......@@ -228,13 +229,6 @@ describe Gitlab::GitAccess do
let(:project) { nil }
let(:project_path) { "new-project" }
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
context 'when user is allowed to create project in namespace' do
let(:namespace_path) { user.namespace.path }
let(:access) do
......@@ -1219,6 +1213,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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment