Commit 5058a8f9 authored by Jacob Vosmaer's avatar Jacob Vosmaer Committed by Rubén Dávila

Add test for GitConfigOptions in PostReceivePack

parent 1313bc17
......@@ -141,6 +141,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
defer gitalyServer.Stop()
apiResponse.GitalyServer.Address = "unix://" + socketPath
apiResponse.GitConfigOptions = []string{"git-config-hello=world"}
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......@@ -154,22 +155,26 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
ws.URL+resource,
map[string]string{
"Content-Type": "application/x-git-receive-pack-request",
"Git-Protocol": "fake Git protocol",
"Git-Protocol": gitProtocol,
},
testhelper.GitalyReceivePackResponseMock,
)
expectedBody := strings.Join([]string{
apiResponse.Repository.StorageName,
apiResponse.Repository.RelativePath,
apiResponse.GL_ID,
apiResponse.GL_USERNAME,
gitProtocol,
string(testhelper.GitalyReceivePackResponseMock),
}, "\000")
split := strings.SplitN(body, "\000", 2)
require.Len(t, split, 2)
gitalyRequest := &pb.PostReceivePackRequest{}
require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest))
require.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
require.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath)
require.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId)
require.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername)
require.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions)
require.Equal(t, gitProtocol, gitalyRequest.GitProtocol)
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
assert.Equal(t, expectedBody, body, "POST %q: response body", resource)
require.Equal(t, string(testhelper.GitalyReceivePackResponseMock), split[1])
testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result")
}
......
......@@ -8,6 +8,7 @@ import (
"strings"
"sync"
"github.com/golang/protobuf/jsonpb"
log "github.com/sirupsen/logrus"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
......@@ -119,17 +120,17 @@ func (s *GitalyTestServer) PostReceivePack(stream pb.SmartHTTPService_PostReceiv
}
repo := req.GetRepository()
if err := validateRepository(req.GetRepository()); err != nil {
if err := validateRepository(repo); err != nil {
return err
}
data := []byte(strings.Join([]string{
repo.GetStorageName(),
repo.GetRelativePath(),
req.GlId,
req.GlUsername,
req.GitProtocol,
}, "\000") + "\000")
marshaler := &jsonpb.Marshaler{}
jsonString, err := marshaler.MarshalToString(req)
if err != nil {
return err
}
data := []byte(jsonString + "\000")
// The body of the request starts in the second message
for {
......
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