Commit 5698ebe0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Don't append error messages to Git response body

parent 65c1d58c
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes"
) )
func TestFailedCloneNoGitaly(t *testing.T) { func TestFailedCloneNoGitaly(t *testing.T) {
...@@ -46,7 +47,7 @@ func TestFailedCloneNoGitaly(t *testing.T) { ...@@ -46,7 +47,7 @@ func TestFailedCloneNoGitaly(t *testing.T) {
func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
gitalyServer, socketPath := startGitalyServer(t) gitalyServer, socketPath := startGitalyServer(t, codes.OK)
defer gitalyServer.Stop() defer gitalyServer.Stop()
gitalyAddress := "unix://" + socketPath gitalyAddress := "unix://" + socketPath
...@@ -68,7 +69,7 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { ...@@ -68,7 +69,7 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
gitalyServer, socketPath := startGitalyServer(t) gitalyServer, socketPath := startGitalyServer(t, codes.OK)
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse.GitalyAddress = "unix://" + socketPath apiResponse.GitalyAddress = "unix://" + socketPath
...@@ -102,38 +103,42 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { ...@@ -102,38 +103,42 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) { func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) {
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
gitalyServer, socketPath := startGitalyServer(t) for _, code := range []codes.Code{codes.OK, codes.Unavailable} {
defer gitalyServer.Stop() func() {
gitalyServer, socketPath := startGitalyServer(t, code)
apiResponse.GitalyAddress = "unix://" + socketPath defer gitalyServer.Stop()
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() apiResponse.GitalyAddress = "unix://" + socketPath
ts := testAuthServer(nil, 200, apiResponse)
ws := startWorkhorseServer(ts.URL) defer ts.Close()
defer ws.Close()
ws := startWorkhorseServer(ts.URL)
resource := "/gitlab-org/gitlab-test.git/git-upload-pack" defer ws.Close()
resp, body := httpPost(
t, resource := "/gitlab-org/gitlab-test.git/git-upload-pack"
ws.URL+resource, resp, body := httpPost(
"application/x-git-upload-pack-request", t,
testhelper.GitalyUploadPackResponseMock, ws.URL+resource,
) "application/x-git-upload-pack-request",
testhelper.GitalyUploadPackResponseMock,
expectedBody := strings.Join([]string{ )
apiResponse.RepoPath,
apiResponse.Repository.StorageName, expectedBody := strings.Join([]string{
apiResponse.Repository.RelativePath, apiResponse.RepoPath,
string(testhelper.GitalyUploadPackResponseMock), apiResponse.Repository.StorageName,
}, "\000") apiResponse.Repository.RelativePath,
string(testhelper.GitalyUploadPackResponseMock),
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource) }, "\000")
assert.Equal(t, expectedBody, body, "POST %q: response body", resource)
testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-upload-pack-result") assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
assert.Equal(t, expectedBody, body, "POST %q: response body", resource)
testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-upload-pack-result")
}()
}
} }
func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
gitalyServer, _ := startGitalyServer(t) gitalyServer, _ := startGitalyServer(t, codes.OK)
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
...@@ -153,7 +158,7 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -153,7 +158,7 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
} }
func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
gitalyServer, _ := startGitalyServer(t) gitalyServer, _ := startGitalyServer(t, codes.OK)
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
...@@ -174,7 +179,7 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -174,7 +179,7 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
} }
func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
gitalyServer, _ := startGitalyServer(t) gitalyServer, _ := startGitalyServer(t, codes.OK)
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
...@@ -194,13 +199,13 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -194,13 +199,13 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-upload-pack-result") testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-upload-pack-result")
} }
func startGitalyServer(t *testing.T) (*grpc.Server, string) { func startGitalyServer(t *testing.T, code codes.Code) (*grpc.Server, string) {
socketPath := path.Join(scratchDir, fmt.Sprintf("gitaly-%d.sock", rand.Int())) socketPath := path.Join(scratchDir, fmt.Sprintf("gitaly-%d.sock", rand.Int()))
server := grpc.NewServer() server := grpc.NewServer()
listener, err := net.Listen("unix", socketPath) listener, err := net.Listen("unix", socketPath)
require.NoError(t, err) require.NoError(t, err)
pb.RegisterSmartHTTPServer(server, testhelper.NewGitalyServer()) pb.RegisterSmartHTTPServer(server, testhelper.NewGitalyServer(code))
go server.Serve(listener) go server.Serve(listener)
......
...@@ -39,7 +39,8 @@ func postRPCHandler(a *api.API, name string, handler func(*GitHttpResponseWriter ...@@ -39,7 +39,8 @@ func postRPCHandler(a *api.API, name string, handler func(*GitHttpResponseWriter
}() }()
if err := handler(w, r, ar); err != nil { if err := handler(w, r, ar); err != nil {
helper.Fail500(w, r, fmt.Errorf("%s: %v", name, err)) w.WriteHeader(500)
helper.LogError(r, fmt.Errorf("%s: %v", name, err))
} }
}) })
} }
......
...@@ -9,9 +9,14 @@ import ( ...@@ -9,9 +9,14 @@ import (
"strings" "strings"
pb "gitlab.com/gitlab-org/gitaly-proto/go" pb "gitlab.com/gitlab-org/gitaly-proto/go"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
) )
type GitalyTestServer struct{} type GitalyTestServer struct {
code codes.Code
}
const GitalyInfoRefsResponseMock = "Mock Gitaly InfoRefsResponse data" const GitalyInfoRefsResponseMock = "Mock Gitaly InfoRefsResponse data"
...@@ -28,8 +33,8 @@ func init() { ...@@ -28,8 +33,8 @@ func init() {
} }
} }
func NewGitalyServer() *GitalyTestServer { func NewGitalyServer(code codes.Code) *GitalyTestServer {
return &GitalyTestServer{} return &GitalyTestServer{code: code}
} }
func (s *GitalyTestServer) InfoRefsUploadPack(in *pb.InfoRefsRequest, stream pb.SmartHTTP_InfoRefsUploadPackServer) error { func (s *GitalyTestServer) InfoRefsUploadPack(in *pb.InfoRefsRequest, stream pb.SmartHTTP_InfoRefsUploadPackServer) error {
...@@ -136,6 +141,10 @@ func (s *GitalyTestServer) PostUploadPack(stream pb.SmartHTTP_PostUploadPackServ ...@@ -136,6 +141,10 @@ func (s *GitalyTestServer) PostUploadPack(stream pb.SmartHTTP_PostUploadPackServ
} }
} }
if s.code != codes.OK {
return grpc.Errorf(s.code, "error as specified by test")
}
return nil return nil
} }
......
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