diff options
Diffstat (limited to 'internal/command/receivepack')
-rw-r--r-- | internal/command/receivepack/gitalycall.go | 6 | ||||
-rw-r--r-- | internal/command/receivepack/gitalycall_test.go | 14 | ||||
-rw-r--r-- | internal/command/receivepack/receivepack.go | 10 |
3 files changed, 12 insertions, 18 deletions
diff --git a/internal/command/receivepack/gitalycall.go b/internal/command/receivepack/gitalycall.go index b27b75a..713f323 100644 --- a/internal/command/receivepack/gitalycall.go +++ b/internal/command/receivepack/gitalycall.go @@ -12,7 +12,7 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/handler" ) -func (c *Command) performGitalyCall(response *accessverifier.Response, gitProtocolVersion string) error { +func (c *Command) performGitalyCall(response *accessverifier.Response) error { gc := &handler.GitalyCommand{ Config: c.Config, ServiceName: string(commandargs.ReceivePack), @@ -26,12 +26,12 @@ func (c *Command) performGitalyCall(response *accessverifier.Response, gitProtoc GlId: response.Who, GlRepository: response.Repo, GlUsername: response.Username, - GitProtocol: gitProtocolVersion, + GitProtocol: c.Args.Env.GitProtocolVersion, GitConfigOptions: response.GitConfigOptions, } return gc.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn) (int32, error) { - ctx, cancel := gc.PrepareContext(ctx, request.Repository, response, request.GitProtocol) + ctx, cancel := gc.PrepareContext(ctx, request.Repository, response, c.Args.Env) defer cancel() rw := c.ReadWriter diff --git a/internal/command/receivepack/gitalycall_test.go b/internal/command/receivepack/gitalycall_test.go index ea07477..d756248 100644 --- a/internal/command/receivepack/gitalycall_test.go +++ b/internal/command/receivepack/gitalycall_test.go @@ -13,6 +13,7 @@ import ( "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/config" + "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" "gitlab.com/gitlab-org/gitlab-shell/internal/testhelper" "gitlab.com/gitlab-org/gitlab-shell/internal/testhelper/requesthandlers" ) @@ -25,10 +26,6 @@ func TestReceivePack(t *testing.T) { url, cleanup := testserver.StartHttpServer(t, requests) defer cleanup() - envCleanup, err := testhelper.Setenv("SSH_CONNECTION", "127.0.0.1 0") - require.NoError(t, err) - defer envCleanup() - testCases := []struct { username string keyId string @@ -46,7 +43,12 @@ func TestReceivePack(t *testing.T) { input := &bytes.Buffer{} repo := "group/repo" - args := &commandargs.Shell{CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}} + env := sshenv.Env{ + IsSSHConnection: true, + OriginalCommand: "git-receive-pack group/repo", + RemoteAddr: "127.0.0.1", + } + args := &commandargs.Shell{CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}, Env: env} if tc.username != "" { args.GitlabUsername = tc.username @@ -62,7 +64,7 @@ func TestReceivePack(t *testing.T) { hook := testhelper.SetupLogger() - err = cmd.Execute(context.Background()) + err := cmd.Execute(context.Background()) require.NoError(t, err) if tc.username != "" { diff --git a/internal/command/receivepack/receivepack.go b/internal/command/receivepack/receivepack.go index 5a67c5a..4d5c686 100644 --- a/internal/command/receivepack/receivepack.go +++ b/internal/command/receivepack/receivepack.go @@ -2,7 +2,6 @@ package receivepack import ( "context" - "os" "gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" @@ -39,14 +38,7 @@ func (c *Command) Execute(ctx context.Context) error { return customAction.Execute(ctx, response) } - var gitProtocolVersion string - if c.Args.RemoteAddr != nil { - gitProtocolVersion = c.Args.GitProtocolVersion - } else { - gitProtocolVersion = os.Getenv(commandargs.GitProtocolEnv) - } - - return c.performGitalyCall(response, gitProtocolVersion) + return c.performGitalyCall(response) } func (c *Command) verifyAccess(ctx context.Context, repo string) (*accessverifier.Response, error) { |