mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 15:36:37 -04:00
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>
37 lines
887 B
Go
37 lines
887 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"encoding/pem"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func TestGetAuthForURLSupportsEd25519PrivateKey(t *testing.T) {
|
|
_, privateKey, err := ed25519.GenerateKey(rand.Reader)
|
|
require.NoError(t, err)
|
|
|
|
block, err := ssh.MarshalPrivateKey(privateKey, "")
|
|
require.NoError(t, err)
|
|
|
|
keyFile := filepath.Join(t.TempDir(), "id_ed25519")
|
|
require.NoError(t, os.WriteFile(keyFile, pem.EncodeToMemory(block), 0o600))
|
|
|
|
remoteURL, err := url.Parse("ssh://git@example.com/owner/repo")
|
|
require.NoError(t, err)
|
|
|
|
auth, err := GetAuthForURL(remoteURL, "", keyFile, nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "ssh", auth.Scheme)
|
|
require.Equal(t, keyFile, auth.KeyFile)
|
|
}
|