Tweak ssh agent
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
package examples
|
package examples
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"errors"
|
"math/rand"
|
||||||
"io/fs"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -22,22 +20,21 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
// sshagent crates an in-memory SSH agent with one identity.
|
// sshagent crates an in-memory SSH agent with one identity.
|
||||||
func sshagent() string {
|
func sshagent() string {
|
||||||
dir := os.TempDir()
|
dir, err := os.MkdirTemp(os.TempDir(), "docker-test-*")
|
||||||
sock := filepath.Join(dir, "test.sock")
|
if err != nil {
|
||||||
|
|
||||||
// In case it already exists.
|
|
||||||
err := os.Remove(sock)
|
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sock := filepath.Join(dir, "test.sock")
|
||||||
|
|
||||||
l, err := net.Listen("unix", sock)
|
l, err := net.Listen("unix", sock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := agent.NewKeyring()
|
a := agent.NewKeyring()
|
||||||
key, err := rsa.GenerateKey(rand.Reader, 4096)
|
//nolint:gosec
|
||||||
|
key, err := rsa.GenerateKey(rand.New(rand.NewSource(42)), 2048)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -51,7 +48,9 @@ func sshagent() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
agent.ServeAgent(a, conn)
|
if err := agent.ServeAgent(a, conn); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return sock
|
return sock
|
||||||
|
|||||||
Reference in New Issue
Block a user