Pulse/internal/config/persistence_fail_test.go
rcourtman 3fdf753a5b Enhance devcontainer and CI workflows
- Add persistent volume mounts for Go/npm caches (faster rebuilds)
- Add shell config with helpful aliases and custom prompt
- Add comprehensive devcontainer documentation
- Add pre-commit hooks for Go formatting and linting
- Use go-version-file in CI workflows instead of hardcoded versions
- Simplify docker compose commands with --wait flag
- Add gitignore entries for devcontainer auth files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:29:15 +00:00

36 lines
1.1 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestNewConfigPersistenceFailsWhenEncryptedDataPresentWithoutKey(t *testing.T) {
dir := t.TempDir()
// The crypto package tries to migrate keys from /etc/pulse/.encryption.key
// We need to temporarily rename it if it exists to properly test this scenario
systemKeyPath := "/etc/pulse/.encryption.key"
backupKeyPath := "/etc/pulse/.encryption.key.test-backup"
if _, err := os.Stat(systemKeyPath); err == nil {
// Key exists - temporarily rename it
if err := os.Rename(systemKeyPath, backupKeyPath); err != nil {
t.Skipf("cannot rename system encryption key for test isolation: %v", err)
}
t.Cleanup(func() {
// Restore the key after test
os.Rename(backupKeyPath, systemKeyPath)
})
}
// Simulate existing encrypted data without providing the encryption key.
if err := os.WriteFile(filepath.Join(dir, "nodes.enc"), []byte("ciphertext"), 0600); err != nil {
t.Fatalf("failed to write simulated encrypted file: %v", err)
}
if _, err := newConfigPersistence(dir); err == nil {
t.Fatalf("expected error when initializing persistence without encryption key")
}
}