gitea.tea/modules/git/cli_backend_test.go
Lunny Xiao 9fd40479b7 fix(git): preserve user SSH command for native git operations
tea previously set GIT_SSH_COMMAND=ssh for every SSH operation, even when
it had no identity or passphrase to inject. Let git fall back to its own
SSH command in that case so core.sshCommand, GIT_SSH_COMMAND, and the
normal OpenSSH known_hosts handling are respected.

Add regression coverage for ed25519 key parsing and CLI SSH auth setup.

Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
2026-08-22 00:02:35 -07:00

34 lines
908 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPrepareCLIAuthSSHUsesGitDefaultCommandWithoutKey(t *testing.T) {
configs, env, cleanup, err := prepareCLIAuth(&AuthMethod{Scheme: "ssh", Username: "git"})
require.NoError(t, err)
require.Empty(t, configs)
require.Empty(t, env)
require.NotNil(t, cleanup)
cleanup()
}
func TestPrepareCLIAuthSSHInjectsConfiguredKey(t *testing.T) {
keyFile := "/tmp/tea test key"
configs, env, cleanup, err := prepareCLIAuth(&AuthMethod{Scheme: "ssh", KeyFile: keyFile})
require.NoError(t, err)
require.Empty(t, configs)
require.NotNil(t, cleanup)
cleanup()
require.Len(t, env, 1)
require.Contains(t, env[0], "GIT_SSH_COMMAND=ssh ")
require.Contains(t, env[0], "IdentitiesOnly=yes")
require.Contains(t, env[0], shellQuote(keyFile))
}