From 43979f6d933a83d9cdcb45d2e92491c473bb3e9c Mon Sep 17 00:00:00 2001 From: Bryce Lampe Date: Wed, 17 Apr 2024 12:16:03 -0700 Subject: [PATCH] Tweak ssh agent --- examples/main_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/main_test.go b/examples/main_test.go index 12d243c..b60761c 100644 --- a/examples/main_test.go +++ b/examples/main_test.go @@ -1,10 +1,8 @@ package examples import ( - "crypto/rand" "crypto/rsa" - "errors" - "io/fs" + "math/rand" "net" "os" "path/filepath" @@ -22,22 +20,21 @@ func TestMain(m *testing.M) { // sshagent crates an in-memory SSH agent with one identity. func sshagent() string { - dir := os.TempDir() - sock := filepath.Join(dir, "test.sock") - - // In case it already exists. - err := os.Remove(sock) - if err != nil && !errors.Is(err, fs.ErrNotExist) { + dir, err := os.MkdirTemp(os.TempDir(), "docker-test-*") + if err != nil { panic(err) } + sock := filepath.Join(dir, "test.sock") + l, err := net.Listen("unix", sock) if err != nil { panic(err) } 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 { panic(err) } @@ -51,7 +48,9 @@ func sshagent() string { if err != nil { panic(err) } - agent.ServeAgent(a, conn) + if err := agent.ServeAgent(a, conn); err != nil { + panic(err) + } }() return sock