diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-01-26 01:23:38 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-01-27 22:12:07 +0300 |
commit | 6bece889b3784867e1b8cbb566d2d8343312cf55 (patch) | |
tree | c0f2106dfec0fd8682aa7be00616e9d69a00f17f | |
parent | 9a82a6ce05d1da620df3bb7d8ae6f00d2b036db9 (diff) |
Merge branch 'fix/26518' into 'master'
Fix access to the wiki code via HTTP when repository feature disabled
Closes #26518
See merge request !8758
-rw-r--r-- | app/controllers/projects/git_http_client_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/projects/git_http_controller.rb | 6 | ||||
-rw-r--r-- | changelogs/unreleased/fix-26518.yml | 4 | ||||
-rw-r--r-- | spec/requests/git_http_spec.rb | 22 |
4 files changed, 38 insertions, 6 deletions
diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb index 8714349e27f..70845617d3c 100644 --- a/app/controllers/projects/git_http_client_controller.rb +++ b/app/controllers/projects/git_http_client_controller.rb @@ -109,12 +109,14 @@ class Projects::GitHttpClientController < Projects::ApplicationController end def repository + wiki? ? project.wiki.repository : project.repository + end + + def wiki? + return @wiki if defined?(@wiki) + _, suffix = project_id_with_suffix - if suffix == '.wiki.git' - project.wiki.repository - else - project.repository - end + @wiki = suffix == '.wiki.git' end def render_not_found diff --git a/app/controllers/projects/git_http_controller.rb b/app/controllers/projects/git_http_controller.rb index 9184dcccac5..278098fcc58 100644 --- a/app/controllers/projects/git_http_controller.rb +++ b/app/controllers/projects/git_http_controller.rb @@ -84,7 +84,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController end def access - @access ||= Gitlab::GitAccess.new(user, project, 'http', authentication_abilities: authentication_abilities) + @access ||= access_klass.new(user, project, 'http', authentication_abilities: authentication_abilities) end def access_check @@ -102,4 +102,8 @@ class Projects::GitHttpController < Projects::GitHttpClientController access_check.allowed? end + + def access_klass + @access_klass ||= wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess + end end diff --git a/changelogs/unreleased/fix-26518.yml b/changelogs/unreleased/fix-26518.yml new file mode 100644 index 00000000000..961ac2642fb --- /dev/null +++ b/changelogs/unreleased/fix-26518.yml @@ -0,0 +1,4 @@ +--- +title: Fix access to the wiki code via HTTP when repository feature disabled +merge_request: 8758 +author: diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index 5abda28e26f..6a5ad6deb74 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -55,6 +55,28 @@ describe 'Git HTTP requests', lib: true do expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end + + context 'but the repo is disabled' do + let(:project) { create(:project, repository_access_level: ProjectFeature::DISABLED, wiki_access_level: ProjectFeature::ENABLED) } + let(:wiki) { ProjectWiki.new(project) } + let(:path) { "/#{wiki.repository.path_with_namespace}.git" } + + before do + project.team << [user, :developer] + end + + it 'allows clones' do + download(path, user: user.username, password: user.password) do |response| + expect(response).to have_http_status(200) + end + end + + it 'allows pushes' do + upload(path, user: user.username, password: user.password) do |response| + expect(response).to have_http_status(200) + end + end + end end context "when the project exists" do |