import test from 'node:test'; import assert from 'node:assert/strict'; import backupModule from '../src/main/configuration-backup.cjs'; const { sanitizeConfiguration, createEncryptedBackup, readEncryptedBackup } = backupModule; test('configuration backups exclude credentials and operation history', () => { const clean = sanitizeConfiguration({ gitea: { baseUrl: 'https://gitea.test', encryptedToken: 'secret-token' }, servers: [{ id: 'server', host: 'unraid.test', encryptedPassword: 'password', encryptedPassphrase: 'passphrase' }], operations: [{ id: 'operation', sha: 'a'.repeat(40) }], preferences: { autoRefresh: true } }); assert.equal(clean.gitea.encryptedToken, null); assert.equal('encryptedPassword' in clean.servers[0], false); assert.equal('encryptedPassphrase' in clean.servers[0], false); assert.deepEqual(clean.operations, []); }); test('configuration backups round-trip with authenticated encryption', () => { const serialized = createEncryptedBackup({ workspaceRoots: ['C:/Projects'], gitea: { encryptedToken: 'secret' } }, 'correct horse battery staple'); assert.doesNotMatch(serialized, /C:\/Projects|secret/); const restored = readEncryptedBackup(serialized, 'correct horse battery staple'); assert.deepEqual(restored.configuration.workspaceRoots, ['C:/Projects']); assert.equal(restored.configuration.gitea.encryptedToken, null); assert.throws(() => readEncryptedBackup(serialized, 'incorrect passphrase'), /could not be decrypted/i); });