Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"github.com/1f349/orchid/database"
"github.com/1f349/orchid/logger"
"github.com/1f349/orchid/test"
"github.com/charmbracelet/log"
"github.com/gobuffalo/nulls"
"github.com/mrmelon54/certgen"
Expand Down Expand Up @@ -79,7 +80,7 @@ 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")
assert.Contains(t, err.Error(), test.PathErrorMessageStringComponent)
Comment thread
Captain-ALM marked this conversation as resolved.
Outdated
})

// generate example certificate
Expand Down Expand Up @@ -112,7 +113,7 @@ 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")
assert.Contains(t, err.Error(), test.PathErrorMessageStringComponent)
})

err = os.WriteFile(filepath.Join(keyDir, "420.key.pem"), tlsCert.GetKeyPem(), 0600)
Expand Down
5 changes: 5 additions & 0 deletions test/not_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !windows

package test

const PathErrorMessageStringComponent = "no such file or directory"
5 changes: 5 additions & 0 deletions test/win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build windows

package test

const PathErrorMessageStringComponent = "system cannot find the file specified"
Loading