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