mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 16:15:39 +00:00
fix: never write telemetry defaults over a state file that can't be read #1066
This commit is contained in:
@@ -40,6 +40,16 @@ describe('telemetry state that cannot be read', () => {
|
||||
expect((await effectiveConsent()).consent).toBe('on');
|
||||
});
|
||||
|
||||
it('refuses to write over it', async () => {
|
||||
const { updateState } = await import('@/lib/telemetry/state');
|
||||
mkdirSync(dir, { recursive: true });
|
||||
const file = path.join(dir, 'state.json');
|
||||
writeFileSync(file, '{"consent":"on","endp');
|
||||
|
||||
await expect(updateState((state) => { state.nextScheduledAt = 'x'; })).rejects.toThrow('could not be read');
|
||||
expect(readFileSync(file, 'utf8')).toBe('{"consent":"on","endp');
|
||||
});
|
||||
|
||||
it('still writes the default state on a fresh install', async () => {
|
||||
const { loadState } = await import('@/lib/telemetry/state');
|
||||
expect((await loadState()).consent).toBe('off');
|
||||
|
||||
Reference in New Issue
Block a user