diff options
Diffstat (limited to 'internal/command/receivepack')
-rw-r--r-- | internal/command/receivepack/gitalycall_test.go | 3 | ||||
-rw-r--r-- | internal/command/receivepack/receivepack.go | 12 | ||||
-rw-r--r-- | internal/command/receivepack/receivepack_test.go | 5 |
3 files changed, 12 insertions, 8 deletions
diff --git a/internal/command/receivepack/gitalycall_test.go b/internal/command/receivepack/gitalycall_test.go index 8bee484..2a0c146 100644 --- a/internal/command/receivepack/gitalycall_test.go +++ b/internal/command/receivepack/gitalycall_test.go @@ -2,6 +2,7 @@ package receivepack import ( "bytes" + "context" "testing" "github.com/sirupsen/logrus" @@ -42,7 +43,7 @@ func TestReceivePack(t *testing.T) { hook := testhelper.SetupLogger() - err = cmd.Execute() + err = cmd.Execute(context.Background()) require.NoError(t, err) require.Equal(t, "ReceivePack: "+userId+" "+repo, output.String()) diff --git a/internal/command/receivepack/receivepack.go b/internal/command/receivepack/receivepack.go index 7271264..4d5c686 100644 --- a/internal/command/receivepack/receivepack.go +++ b/internal/command/receivepack/receivepack.go @@ -1,6 +1,8 @@ package receivepack import ( + "context" + "gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/accessverifier" @@ -15,14 +17,14 @@ type Command struct { ReadWriter *readwriter.ReadWriter } -func (c *Command) Execute() error { +func (c *Command) Execute(ctx context.Context) error { args := c.Args.SshArgs if len(args) != 2 { return disallowedcommand.Error } repo := args[1] - response, err := c.verifyAccess(repo) + response, err := c.verifyAccess(ctx, repo) if err != nil { return err } @@ -33,14 +35,14 @@ func (c *Command) Execute() error { ReadWriter: c.ReadWriter, EOFSent: true, } - return customAction.Execute(response) + return customAction.Execute(ctx, response) } return c.performGitalyCall(response) } -func (c *Command) verifyAccess(repo string) (*accessverifier.Response, error) { +func (c *Command) verifyAccess(ctx context.Context, repo string) (*accessverifier.Response, error) { cmd := accessverifier.Command{c.Config, c.Args, c.ReadWriter} - return cmd.Verify(c.Args.CommandType, repo) + return cmd.Verify(ctx, c.Args.CommandType, repo) } diff --git a/internal/command/receivepack/receivepack_test.go b/internal/command/receivepack/receivepack_test.go index a4632b4..44cb680 100644 --- a/internal/command/receivepack/receivepack_test.go +++ b/internal/command/receivepack/receivepack_test.go @@ -2,6 +2,7 @@ package receivepack import ( "bytes" + "context" "testing" "github.com/stretchr/testify/require" @@ -18,7 +19,7 @@ func TestForbiddenAccess(t *testing.T) { cmd, _, cleanup := setup(t, "disallowed", requests) defer cleanup() - err := cmd.Execute() + err := cmd.Execute(context.Background()) require.Equal(t, "Disallowed by API call", err.Error()) } @@ -26,7 +27,7 @@ func TestCustomReceivePack(t *testing.T) { cmd, output, cleanup := setup(t, "1", requesthandlers.BuildAllowedWithCustomActionsHandlers(t)) defer cleanup() - require.NoError(t, cmd.Execute()) + require.NoError(t, cmd.Execute(context.Background())) require.Equal(t, "customoutput", output.String()) } |