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:
authorBob Van Landuyt <bob@gitlab.com>2019-04-05 13:51:42 +0300
committerDouwe Maan <douwe@gitlab.com>2019-04-05 13:51:42 +0300
commit2fdda74458bb7b58a6a18b72170a572f72afdd95 (patch)
tree1d593dc1d7ac185ba1d6977865f79d0871b1f846
parent934dabaf6da42db7197e07dc95cf88d34e847306 (diff)
Fall back to project repository type by default
This makes sure that we always have a repository type when trying to parse a repository from a path. This is needed because sometimes we want to perform access checks as if the project already existed, for example when creating a project on push. Before this we were only doing that when accessing git over http, this makes sure it also works correctly when accessing git over SSH
-rw-r--r--app/controllers/projects/git_http_client_controller.rb6
-rw-r--r--lib/gitlab/gl_repository.rb4
-rw-r--r--lib/gitlab/repo_path.rb5
-rw-r--r--spec/lib/gitlab/repo_path_spec.rb6
-rw-r--r--spec/requests/api/internal_spec.rb16
5 files changed, 30 insertions, 7 deletions
diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb
index 55d5fce9214..85628dd32d8 100644
--- a/app/controllers/projects/git_http_client_controller.rb
+++ b/app/controllers/projects/git_http_client_controller.rb
@@ -98,10 +98,8 @@ class Projects::GitHttpClientController < Projects::ApplicationController
def repo_type
parse_repo_path unless defined?(@repo_type)
- # When there a project did not exist, the parsed repo_type would be empty.
- # In that case, we want to continue with a regular project repository. As we
- # could create the project if the user pushing is allowed to do so.
- @repo_type || Gitlab::GlRepository::PROJECT
+
+ @repo_type
end
def handle_basic_authentication(login, password)
diff --git a/lib/gitlab/gl_repository.rb b/lib/gitlab/gl_repository.rb
index c2be7f3d63a..a56ca1e39e7 100644
--- a/lib/gitlab/gl_repository.rb
+++ b/lib/gitlab/gl_repository.rb
@@ -35,5 +35,9 @@ module Gitlab
[project, type]
end
+
+ def self.default_type
+ PROJECT
+ end
end
end
diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb
index 207a80b7db2..b4f41b9cd9a 100644
--- a/lib/gitlab/repo_path.rb
+++ b/lib/gitlab/repo_path.rb
@@ -24,7 +24,10 @@ module Gitlab
return [project, type, redirected_path] if project
end
- nil
+ # When a project did not exist, the parsed repo_type would be empty.
+ # In that case, we want to continue with a regular project repository. As we
+ # could create the project if the user pushing is allowed to do so.
+ [nil, Gitlab::GlRepository.default_type, nil]
end
def self.find_project(project_path)
diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb
index 4c7ca4e2b57..8fbda929064 100644
--- a/spec/lib/gitlab/repo_path_spec.rb
+++ b/spec/lib/gitlab/repo_path_spec.rb
@@ -44,8 +44,10 @@ describe ::Gitlab::RepoPath do
end
end
- it "returns nil for non existent paths" do
- expect(described_class.parse("path/non-existent.git")).to eq(nil)
+ it "returns the default type for non existent paths" do
+ _project, type, _redirected = described_class.parse("path/non-existent.git")
+
+ expect(type).to eq(Gitlab::GlRepository.default_type)
end
end
diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb
index 6640ce2b07e..0919540e4ba 100644
--- a/spec/requests/api/internal_spec.rb
+++ b/spec/requests/api/internal_spec.rb
@@ -644,6 +644,22 @@ describe API::Internal do
expect(response).to have_gitlab_http_status(404)
expect(json_response["status"]).to be_falsey
end
+
+ it 'returns a 200 response when using a project path that does not exist' do
+ post(
+ api("/internal/allowed"),
+ params: {
+ key_id: key.id,
+ project: 'project/does-not-exist.git',
+ action: 'git-upload-pack',
+ secret_token: secret_token,
+ protocol: 'ssh'
+ }
+ )
+
+ expect(response).to have_gitlab_http_status(404)
+ expect(json_response["status"]).to be_falsey
+ end
end
context 'user does not exist' do