fix: harden security resource lifecycles

This commit is contained in:
Andy Dixon
2026-07-29 12:37:02 +01:00
parent f0a1a0b8f2
commit b5c7528160
17 changed files with 460 additions and 76 deletions
@@ -3,6 +3,7 @@ package exportimport
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/andydixon/nexus/internal/models"
@@ -104,6 +105,26 @@ func TestEncryptEmptyProfiles(t *testing.T) {
}
}
func TestEncryptAndExportRestrictsExistingFilePermissions(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("POSIX permission bits are not enforced on Windows")
}
path := filepath.Join(t.TempDir(), "profiles.nexus")
if err := os.WriteFile(path, []byte("old"), 0644); err != nil {
t.Fatal(err)
}
if err := EncryptAndExport([]models.Profile{{ID: "1"}}, "password", path); err != nil {
t.Fatal(err)
}
info, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if got := info.Mode().Perm(); got != 0600 {
t.Fatalf("export permissions = %04o, want 0600", got)
}
}
func TestEncryptEmptyPassword(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "test.nexus")