Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gobuffalo/nulls"
"golang.org/x/crypto/ssh"
"os"
"path"
"path/filepath"
"sync"
"time"
Expand Down Expand Up @@ -220,11 +221,12 @@ func (a *Agent) copySingleCertPair(scpClient *scp.Client, row database.FindAgent
defer openKey.Close()

// copy cert and key to agent
err = scpClient.CopyFromFile(context.Background(), *openCert, filepath.Join(row.Dir, "certificates", certName), "0600")
// use path rather than filepath here as scpClient unfortunately uses path.Base rather than filepath.Base
err = scpClient.CopyFromFile(context.Background(), *openCert, path.Join(row.Dir, "certificates", certName), "0600")
if err != nil {
return fmt.Errorf("copy cert file: %w", err)
}
err = scpClient.CopyFromFile(context.Background(), *openKey, filepath.Join(row.Dir, "keys", keyName), "0600")
err = scpClient.CopyFromFile(context.Background(), *openKey, path.Join(row.Dir, "keys", keyName), "0600")
if err != nil {
return fmt.Errorf("copy cert file: %w", err)
}
Expand Down
13 changes: 11 additions & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/netip"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -79,7 +80,11 @@ func TestAgentSyncing(t *testing.T) {
CertNotAfter: nulls.NewTime(now),
})
assert.Contains(t, err.Error(), "open cert file:")
assert.Contains(t, err.Error(), "no such file or directory")
if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "system cannot find the file specified")
} else {
assert.Contains(t, err.Error(), "no such file or directory")
}
})

// generate example certificate
Expand Down Expand Up @@ -112,7 +117,11 @@ func TestAgentSyncing(t *testing.T) {
CertNotAfter: nulls.NewTime(now),
})
assert.Contains(t, err.Error(), "open key file:")
assert.Contains(t, err.Error(), "no such file or directory")
if runtime.GOOS == "windows" {
assert.Contains(t, err.Error(), "system cannot find the file specified")
} else {
assert.Contains(t, err.Error(), "no such file or directory")
}
})

err = os.WriteFile(filepath.Join(keyDir, "420.key.pem"), tlsCert.GetKeyPem(), 0600)
Expand Down
Loading