test: fix TestLoad_Errors to provide valid encryption key

Test was creating .enc files without a valid encryption key, which
triggers the crypto safety check that prevents generating new keys
when encrypted data exists.
This commit is contained in:
rcourtman 2026-01-04 18:02:39 +00:00
parent d71b6bd756
commit f2be9b60f0

View file

@ -1,6 +1,7 @@
package config
import (
"encoding/base64"
"os"
"path/filepath"
"testing"
@ -56,6 +57,16 @@ func TestLoad_Errors(t *testing.T) {
tempDir := t.TempDir()
t.Setenv("PULSE_DATA_DIR", tempDir)
// First create encryption key so crypto doesn't fail when it sees .enc files
// Key must be base64-encoded 32-byte value
keyPath := filepath.Join(tempDir, ".encryption.key")
key := make([]byte, 32)
for i := range key {
key[i] = byte(i) // Non-zero key
}
encoded := base64.StdEncoding.EncodeToString(key)
require.NoError(t, os.WriteFile(keyPath, []byte(encoded), 0600))
// 1. Corrupted Nodes
nodesPath := filepath.Join(tempDir, "nodes.enc")
require.NoError(t, os.WriteFile(nodesPath, []byte("corrupted"), 0644))