Skip to content
代码片段 群组 项目
未验证 提交 633fdb90 编辑于 作者: Ash McKenzie's avatar Ash McKenzie 提交者: GitLab
浏览文件

Merge branch 'ash2k/gitaly-not-found' into 'master'

Turn NotFound from Gitaly into 404 for InfoRefs

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/162697



Merged-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Approved-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Reviewed-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Co-authored-by: default avatarMikhail Mazurskiy <mmazurskiy@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -46,10 +46,18 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response) ...@@ -46,10 +46,18 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
status := grpcstatus.Convert(err) status := grpcstatus.Convert(err)
err = fmt.Errorf("handleGetInfoRefs: %v", err) err = fmt.Errorf("handleGetInfoRefs: %v", err)
if status != nil && status.Code() == grpccodes.Unavailable { if status == nil {
fail.Request(responseWriter, r, err)
return
}
switch status.Code() {
case grpccodes.Unavailable:
fail.Request(responseWriter, r, err, fail.WithStatus(http.StatusServiceUnavailable), fail.Request(responseWriter, r, err, fail.WithStatus(http.StatusServiceUnavailable),
fail.WithBody("The git server, Gitaly, is not available at this time. Please contact your administrator.")) fail.WithBody("The git server, Gitaly, is not available at this time. Please contact your administrator."))
} else { case grpccodes.NotFound:
fail.Request(responseWriter, r, err, fail.WithStatus(http.StatusNotFound),
fail.WithBody("Not Found."))
default:
fail.Request(responseWriter, r, err) fail.Request(responseWriter, r, err)
} }
} }
......
package git package git
import ( import (
"net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
...@@ -22,7 +23,7 @@ func (srv *smartHTTPServiceServerWithInfoRefs) InfoRefsUploadPack(r *gitalypb.In ...@@ -22,7 +23,7 @@ func (srv *smartHTTPServiceServerWithInfoRefs) InfoRefsUploadPack(r *gitalypb.In
return srv.InfoRefsUploadPackFunc(r, s) return srv.InfoRefsUploadPackFunc(r, s)
} }
func TestGetInfoRefsHandler(t *testing.T) { func TestGetInfoRefsHandler_Unavailable(t *testing.T) {
addr := startSmartHTTPServer(t, &smartHTTPServiceServerWithInfoRefs{ addr := startSmartHTTPServer(t, &smartHTTPServiceServerWithInfoRefs{
InfoRefsUploadPackFunc: func(_ *gitalypb.InfoRefsRequest, _ gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error { InfoRefsUploadPackFunc: func(_ *gitalypb.InfoRefsRequest, _ gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error {
return grpcstatus.Error(grpccodes.Unavailable, "error") return grpcstatus.Error(grpccodes.Unavailable, "error")
...@@ -34,8 +35,26 @@ func TestGetInfoRefsHandler(t *testing.T) { ...@@ -34,8 +35,26 @@ func TestGetInfoRefsHandler(t *testing.T) {
a := &api.Response{GitalyServer: api.GitalyServer{Address: addr}} a := &api.Response{GitalyServer: api.GitalyServer{Address: addr}}
handleGetInfoRefs(NewHTTPResponseWriter(w), r, a) handleGetInfoRefs(NewHTTPResponseWriter(w), r, a)
require.Equal(t, 503, w.Code) require.Equal(t, http.StatusServiceUnavailable, w.Code)
msg := "The git server, Gitaly, is not available at this time. Please contact your administrator.\n" msg := "The git server, Gitaly, is not available at this time. Please contact your administrator.\n"
require.Equal(t, msg, w.Body.String()) require.Equal(t, msg, w.Body.String())
} }
func TestGetInfoRefsHandler_NotFound(t *testing.T) {
addr := startSmartHTTPServer(t, &smartHTTPServiceServerWithInfoRefs{
InfoRefsUploadPackFunc: func(_ *gitalypb.InfoRefsRequest, _ gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error {
return grpcstatus.Error(grpccodes.NotFound, "error")
},
})
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/?service=git-upload-pack", nil)
a := &api.Response{GitalyServer: api.GitalyServer{Address: addr}}
handleGetInfoRefs(NewHTTPResponseWriter(w), r, a)
require.Equal(t, http.StatusNotFound, w.Code)
msg := "Not Found.\n"
require.Equal(t, msg, w.Body.String())
}
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册