aboutsummaryrefslogtreecommitdiff
path: root/internal/crud/crud_test.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-08-20 14:26:56 +0530
committerishaan <contact@ishaan.cc>2026-08-20 14:26:56 +0530
commitdf049e053bd44b063999feb8cc155dd335a884a3 (patch)
tree17b487059ef5994a570d2b9e650edb56a81ec6c1 /internal/crud/crud_test.go
parentb60ef6b303c01039107cdf6433642cfb0b337557 (diff)
add tests for temp file leak
Diffstat (limited to 'internal/crud/crud_test.go')
-rw-r--r--internal/crud/crud_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/crud/crud_test.go b/internal/crud/crud_test.go
index f9e5f47..351791a 100644
--- a/internal/crud/crud_test.go
+++ b/internal/crud/crud_test.go
@@ -271,6 +271,43 @@ func TestEditNoteSSH_NoTempFileLeak(t *testing.T) {
assert.Equal(t, before, countTempFiles(), "temp file should be wiped and removed, not leaked")
}
+func TestNewNoteSSHEdit_NoTempFileLeak(t *testing.T) {
+ pub, priv, err := ed25519.GenerateKey(rand.Reader)
+ require.NoError(t, err)
+ sshPub, err := ssh.NewPublicKey(pub)
+ require.NoError(t, err)
+ defaultPub := ssh.MarshalAuthorizedKey(sshPub)
+
+ dir := t.TempDir()
+ output := filepath.Join(dir, "test.eno")
+
+ block, err := ssh.MarshalPrivateKey(priv, "")
+ require.NoError(t, err)
+ var pemBuf bytes.Buffer
+ require.NoError(t, pem.Encode(&pemBuf, block))
+ privKeyPath := filepath.Join(dir, "id_ed25519")
+ require.NoError(t, os.WriteFile(privKeyPath, pemBuf.Bytes(), 0600))
+
+ tempDirs := []string{"/dev/shm", os.TempDir()}
+ countTempFiles := func() int {
+ n := 0
+ for _, d := range tempDirs {
+ matches, _ := filepath.Glob(filepath.Join(d, "eno-*"))
+ n += len(matches)
+ }
+ return n
+ }
+
+ old := setScannerInput("y\nn\n")
+ defer restoreScanner(old)
+
+ before := countTempFiles()
+ err = NewNoteSSHEdit(output, defaultPub, privKeyPath, "true")
+ require.NoError(t, err)
+
+ assert.Equal(t, before, countTempFiles(), "temp file should be wiped and removed, not leaked")
+}
+
func TestEditNoteSSH_WrongAuthMode(t *testing.T) {
dir := t.TempDir()
output := filepath.Join(dir, "test.eno")