diff options
Diffstat (limited to 'go/internal/command/receivepack')
-rw-r--r-- | go/internal/command/receivepack/receivepack.go | 9 | ||||
-rw-r--r-- | go/internal/command/receivepack/receivepack_test.go | 18 |
2 files changed, 4 insertions, 23 deletions
diff --git a/go/internal/command/receivepack/receivepack.go b/go/internal/command/receivepack/receivepack.go index d1ff3f8..d6b788c 100644 --- a/go/internal/command/receivepack/receivepack.go +++ b/go/internal/command/receivepack/receivepack.go @@ -1,18 +1,13 @@ package receivepack import ( - "errors" - "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/command/shared/accessverifier" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/shared/disallowedcommand" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" ) -var ( - disallowedCommandError = errors.New("> GitLab: Disallowed command") -) - type Command struct { Config *config.Config Args *commandargs.CommandArgs @@ -22,7 +17,7 @@ type Command struct { func (c *Command) Execute() error { args := c.Args.SshArgs if len(args) != 2 { - return disallowedCommandError + return disallowedcommand.Error } repo := args[1] diff --git a/go/internal/command/receivepack/receivepack_test.go b/go/internal/command/receivepack/receivepack_test.go index 874bac3..e5263f5 100644 --- a/go/internal/command/receivepack/receivepack_test.go +++ b/go/internal/command/receivepack/receivepack_test.go @@ -2,8 +2,6 @@ package receivepack import ( "bytes" - "encoding/json" - "net/http" "testing" "github.com/stretchr/testify/require" @@ -12,23 +10,11 @@ import ( "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/testserver" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/testhelper/requesthandlers" ) func TestForbiddenAccess(t *testing.T) { - requests := []testserver.TestRequestHandler{ - { - Path: "/api/v4/internal/allowed", - Handler: func(w http.ResponseWriter, r *http.Request) { - body := map[string]interface{}{ - "status": false, - "message": "Disallowed by API call", - } - w.WriteHeader(http.StatusForbidden) - require.NoError(t, json.NewEncoder(w).Encode(body)) - }, - }, - } - + requests := requesthandlers.BuildDisallowedByApiHandlers(t) url, cleanup := testserver.StartHttpServer(t, requests) defer cleanup() |