Commit 4055c2fe authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-fix-503-argument-errors' into 'master'

Properly handle 503 errors in info/refs endpoint

Closes #32925

See merge request gitlab-org/gitlab!18177
parents 418ad84e f1b857a5
...@@ -6,10 +6,10 @@ class Projects::GitHttpController < Projects::GitHttpClientController ...@@ -6,10 +6,10 @@ class Projects::GitHttpController < Projects::GitHttpClientController
before_action :access_check before_action :access_check
prepend_before_action :deny_head_requests, only: [:info_refs] prepend_before_action :deny_head_requests, only: [:info_refs]
rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403 rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403_with_exception
rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404 rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404_with_exception
rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422 rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422_with_exception
rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503 rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503_with_exception
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull) # GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push) # GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
...@@ -58,19 +58,19 @@ class Projects::GitHttpController < Projects::GitHttpClientController ...@@ -58,19 +58,19 @@ class Projects::GitHttpController < Projects::GitHttpClientController
render json: Gitlab::Workhorse.git_http_ok(repository, repo_type, user, action_name) render json: Gitlab::Workhorse.git_http_ok(repository, repo_type, user, action_name)
end end
def render_403(exception) def render_403_with_exception(exception)
render plain: exception.message, status: :forbidden render plain: exception.message, status: :forbidden
end end
def render_404(exception) def render_404_with_exception(exception)
render plain: exception.message, status: :not_found render plain: exception.message, status: :not_found
end end
def render_422(exception) def render_422_with_exception(exception)
render plain: exception.message, status: :unprocessable_entity render plain: exception.message, status: :unprocessable_entity
end end
def render_503(exception) def render_503_with_exception(exception)
render plain: exception.message, status: :service_unavailable render plain: exception.message, status: :service_unavailable
end end
......
...@@ -22,5 +22,30 @@ describe Projects::GitHttpController do ...@@ -22,5 +22,30 @@ describe Projects::GitHttpController do
expect(response.status).to eq(401) expect(response.status).to eq(401)
end end
context 'with exceptions' do
let(:project) { create(:project, :public, :repository) }
before do
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
end
it 'returns 503 with GRPC Unavailable' do
allow(controller).to receive(:access_check).and_raise(GRPC::Unavailable)
get :info_refs, params: { service: 'git-upload-pack', namespace_id: project.namespace.to_param, project_id: project.path + '.git' }
expect(response.status).to eq(503)
end
it 'returns 503 with timeout error' do
allow(controller).to receive(:access_check).and_raise(Gitlab::GitAccess::TimeoutError)
get :info_refs, params: { service: 'git-upload-pack', namespace_id: project.namespace.to_param, project_id: project.path + '.git' }
expect(response.status).to eq(503)
expect(response.body).to eq 'Gitlab::GitAccess::TimeoutError'
end
end
end end
end end
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