diff options
author | Nick Thomas <nick@gitlab.com> | 2019-10-17 12:04:52 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-10-18 11:47:25 +0100 |
commit | 83d11f4deeb20b852a0af3433190a0f7250a0027 (patch) | |
tree | 1a9df18d6f9f59712c6f5c98e995a4918eb94a11 /go/internal/command/receivepack/customaction_test.go | |
parent | 7d5229db263a62661653431881bef8b46984d0de (diff) | |
download | gitlab-shell-83d11f4deeb20b852a0af3433190a0f7250a0027.tar.gz |
Move go code up one level
Diffstat (limited to 'go/internal/command/receivepack/customaction_test.go')
-rw-r--r-- | go/internal/command/receivepack/customaction_test.go | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/go/internal/command/receivepack/customaction_test.go b/go/internal/command/receivepack/customaction_test.go deleted file mode 100644 index bd4991d..0000000 --- a/go/internal/command/receivepack/customaction_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package receivepack - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - "testing" - - "github.com/stretchr/testify/require" - - "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs" - "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter" - "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" - "gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/accessverifier" - "gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/testserver" -) - -func TestCustomReceivePack(t *testing.T) { - repo := "group/repo" - keyId := "1" - - requests := []testserver.TestRequestHandler{ - { - Path: "/api/v4/internal/allowed", - Handler: func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var request *accessverifier.Request - require.NoError(t, json.Unmarshal(b, &request)) - - require.Equal(t, "1", request.KeyId) - - body := map[string]interface{}{ - "status": true, - "gl_id": "1", - "payload": map[string]interface{}{ - "action": "geo_proxy_to_primary", - "data": map[string]interface{}{ - "api_endpoints": []string{"/geo/proxy_git_push_ssh/info_refs", "/geo/proxy_git_push_ssh/push"}, - "gl_username": "custom", - "primary_repo": "https://repo/path", - "info_message": "info_message\none more message", - }, - }, - } - w.WriteHeader(http.StatusMultipleChoices) - require.NoError(t, json.NewEncoder(w).Encode(body)) - }, - }, - { - Path: "/geo/proxy_git_push_ssh/info_refs", - Handler: func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var request *Request - require.NoError(t, json.Unmarshal(b, &request)) - - require.Equal(t, request.Data.UserId, "key-"+keyId) - require.Empty(t, request.Output) - - err = json.NewEncoder(w).Encode(Response{Result: []byte("custom")}) - require.NoError(t, err) - }, - }, - { - Path: "/geo/proxy_git_push_ssh/push", - Handler: func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) - require.NoError(t, err) - - var request *Request - require.NoError(t, json.Unmarshal(b, &request)) - - require.Equal(t, request.Data.UserId, "key-"+keyId) - require.Equal(t, "input", string(request.Output)) - - err = json.NewEncoder(w).Encode(Response{Result: []byte("output")}) - require.NoError(t, err) - }, - }, - } - - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() - - outBuf := &bytes.Buffer{} - errBuf := &bytes.Buffer{} - input := bytes.NewBufferString("input") - - cmd := &Command{ - Config: &config.Config{GitlabUrl: url}, - Args: &commandargs.Shell{GitlabKeyId: keyId, CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}}, - ReadWriter: &readwriter.ReadWriter{ErrOut: errBuf, Out: outBuf, In: input}, - } - - require.NoError(t, cmd.Execute()) - - // expect printing of info message, "custom" string from the first request - // and "output" string from the second request - require.Equal(t, "> GitLab: info_message\n> GitLab: one more message\n", errBuf.String()) - require.Equal(t, "customoutput", outBuf.String()) -} |