Commit 5273f2ca authored by Patrick Bajao's avatar Patrick Bajao

Accept GetArchiveRequest param

Parse the GetArchiveRequest from the send data header and
use it when making calling the GetArchive RPC on gitaly.
parent f39e248b
......@@ -184,6 +184,48 @@ func TestAllowedGetGitBlob(t *testing.T) {
func TestAllowedGetGitArchive(t *testing.T) {
skipUnlessRealGitaly(t)
// Create the repository in the Gitaly server
apiResponse := realGitalyOkBody(t)
require.NoError(t, ensureGitalyRepository(t, apiResponse))
archivePath := path.Join(scratchDir, "my/path")
archivePrefix := "repo-1"
msg := serializedProtoMessage("GetArchiveRequest", &gitalypb.GetArchiveRequest{
Repository: &apiResponse.Repository,
CommitId: "HEAD",
Prefix: archivePrefix,
Format: gitalypb.GetArchiveRequest_TAR,
Path: []byte("files"),
})
jsonParams := buildGitalyRPCParams(gitalyAddress, rpcArg{"ArchivePath", archivePath}, msg)
resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
// Ensure the tar file is readable
foundEntry := false
tr := tar.NewReader(bytes.NewReader(body))
for {
hdr, err := tr.Next()
if err != nil {
break
}
if hdr.Name == archivePrefix+"/" {
foundEntry = true
break
}
}
assert.True(t, foundEntry, "Couldn't find %v directory entry", archivePrefix)
}
func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
skipUnlessRealGitaly(t)
// Create the repository in the Gitaly server
apiResponse := realGitalyOkBody(t)
repo := apiResponse.Repository
......
......@@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
......@@ -635,6 +636,16 @@ func serializedMessage(name string, arg proto.Message) rpcArg {
return rpcArg{name, str}
}
func serializedProtoMessage(name string, arg proto.Message) rpcArg {
msg, err := proto.Marshal(arg)
if err != nil {
panic(err)
}
return rpcArg{name, base64.URLEncoding.EncodeToString(msg)}
}
type combinedServer struct {
*grpc.Server
*testhelper.GitalyTestServer
......
......@@ -15,6 +15,8 @@ import (
"regexp"
"time"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
......@@ -26,12 +28,13 @@ import (
type archive struct{ senddata.Prefix }
type archiveParams struct {
ArchivePath string
ArchivePrefix string
CommitId string
GitalyServer gitaly.Server
GitalyRepository gitalypb.Repository
DisableCache bool
ArchivePath string
ArchivePrefix string
CommitId string
GitalyServer gitaly.Server
GitalyRepository gitalypb.Repository
DisableCache bool
GetArchiveRequest []byte
}
var (
......@@ -101,7 +104,7 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
var archiveReader io.Reader
archiveReader, err = handleArchiveWithGitaly(r, params, format)
archiveReader, err = handleArchiveWithGitaly(w, r, params, format)
if err != nil {
helper.Fail500(w, r, fmt.Errorf("operations.GetArchive: %v", err))
return
......@@ -129,17 +132,27 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
}
}
func handleArchiveWithGitaly(r *http.Request, params archiveParams, format gitalypb.GetArchiveRequest_Format) (io.Reader, error) {
func handleArchiveWithGitaly(w http.ResponseWriter, r *http.Request, params archiveParams, format gitalypb.GetArchiveRequest_Format) (io.Reader, error) {
var request *gitalypb.GetArchiveRequest
c, err := gitaly.NewRepositoryClient(params.GitalyServer)
if err != nil {
return nil, err
}
request := &gitalypb.GetArchiveRequest{
Repository: &params.GitalyRepository,
CommitId: params.CommitId,
Prefix: params.ArchivePrefix,
Format: format,
if params.GetArchiveRequest != nil {
request = &gitalypb.GetArchiveRequest{}
if err := proto.Unmarshal(params.GetArchiveRequest, request); err != nil {
helper.Fail500(w, r, fmt.Errorf("SendArchive: unmarshal GetArchiveRequest: %v", err))
return nil, err
}
} else {
request = &gitalypb.GetArchiveRequest{
Repository: &params.GitalyRepository,
CommitId: params.CommitId,
Prefix: params.ArchivePrefix,
Format: format,
}
}
return c.ArchiveReader(r.Context(), request)
......
......@@ -168,3 +168,11 @@ func (s *GitalyTestServer) SetConfig(context.Context, *gitalypb.SetConfigRequest
func (s *GitalyTestServer) DiffStats(*gitalypb.DiffStatsRequest, gitalypb.DiffService_DiffStatsServer) error {
return nil
}
func (s *GitalyTestServer) FetchHTTPRemote(context.Context, *gitalypb.FetchHTTPRemoteRequest) (*gitalypb.FetchHTTPRemoteResponse, error) {
return nil, nil
}
func (s *GitalyTestServer) PreFetch(context.Context, *gitalypb.PreFetchRequest) (*gitalypb.PreFetchResponse, error) {
return nil, 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