Все проверки выполнены успешно
CI / test (push) Successful in 2m24s
Docker / Build and publish worker image (push) Successful in 13m24s
42 строки
1.0 KiB
Go
42 строки
1.0 KiB
Go
package installer
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"net"
|
|
"testing"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func TestFingerprintHostKeyCallback(t *testing.T) {
|
|
_, privateKey, err := ed25519.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
publicKey, err := ssh.NewPublicKey(privateKey.Public())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
callback, err := hostKeyCallback(DeployOptions{HostKeyFingerprint: ssh.FingerprintSHA256(publicKey)})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := callback("host", &net.TCPAddr{}, publicKey); err != nil {
|
|
t.Fatalf("matching fingerprint rejected: %v", err)
|
|
}
|
|
callback, err = hostKeyCallback(DeployOptions{HostKeyFingerprint: "SHA256:wrong"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := callback("host", &net.TCPAddr{}, publicKey); err == nil {
|
|
t.Fatal("mismatched fingerprint accepted")
|
|
}
|
|
}
|
|
|
|
func TestKnownHostsMissingFile(t *testing.T) {
|
|
if _, err := hostKeyCallback(DeployOptions{KnownHostsFile: t.TempDir() + "/missing"}); err == nil {
|
|
t.Fatal("missing known_hosts file accepted")
|
|
}
|
|
}
|