فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A04): reject corrupted native AES-GCM backup with zero writes and audit

davoodmehraban89 committed Oct 16, 2026 at 21:21 UTC 307af42d693f96b051285e8aff61c161369e575f
1 file changed +39 -1
tests/windows-vm-encrypted-company-backup-browser.js
+39 -1
@@ -111,10 +111,47 @@
111 throw Error('Failed recovery dialog could not be closed');
112 }
113
114 + // Corrupt the AES-GCM authentication tag of the genuine exported .fbackup.
115 + // This must fail in the REAL installed Settings UI with no partial writes
116 + // or false-positive backup_restored audit receipts.
117 + const auditCountBeforeCorruption = (await store.getAll('audit_events')).length;
118 + const damagedBytes = Uint8Array.from(atob(envelope.ciphertext), c => c.charCodeAt(0));
119 + if (damagedBytes.length < 17) throw Error('Encrypted backup test ciphertext too short');
120 + damagedBytes[damagedBytes.length - 1] ^= 1;
121 + const damagedCiphertext = btoa(Array.from(damagedBytes,
122 + byte => String.fromCharCode(byte)).join(''));
123 + restoreFile(JSON.stringify({ ...envelope, ciphertext: damagedCiphertext }));
124 + window.prompt = () => password;
125 + await window.SettingsView.restoreBackup();
126 + if (await store.get('contacts', contactId)) {
127 + throw Error('Tampered encrypted backup wrote the deleted synthetic contact');
128 + }
129 + if ((await store.getAll('audit_events')).length !== auditCountBeforeCorruption) {
130 + throw Error('Tampered encrypted backup incorrectly wrote an audit event');
131 + }
132 + if (capturedErrors.length !== 2 || !capturedErrors[1].includes(expectedError)) {
133 + throw Error('Tampered encrypted backup did not show its expected error');
134 + }
135 + const damagedToasts = [...document.querySelectorAll('.toast-error')];
136 + if (damagedToasts.length !== 1 ||
137 + !damagedToasts[0].textContent.includes(expectedError)) {
138 + throw Error('Tampered backup failure did not display exactly one error toast');
139 + }
140 + const corruptedToastClose = damagedToasts[0].querySelector('.toast-close');
141 + if (!corruptedToastClose) throw Error('Tampered backup toast missing dismiss action');
142 + corruptedToastClose.click();
143 + if (document.querySelector('.toast-error') || !document.getElementById('restoreFile')) {
144 + throw Error('Tampered backup left an unexpected error or dismissed the recovery form');
145 + }
146 + FINORA.Modal.close();
147 + if (document.getElementById('restoreFile')) {
148 + throw Error('Tampered backup recovery dialog was not closed');
149 + }
150 +
151 restoreFile(encryptedText);
152 window.prompt = () => password;
153 await window.SettingsView.restoreBackup();
117 - if (capturedErrors.length !== 1 || document.querySelector('.toast-error') ||
154 + if (capturedErrors.length !== 2 || document.querySelector('.toast-error') ||
155 document.querySelector('.modal-backdrop')) {
156 throw Error('Correct-password restore failed or left modal/error state');
157 }
@@ -131,6 +168,7 @@
168 encryptedEnvelope: true,
169 filenameSuffix: '.fbackup',
170 wrongPasswordRejected: true,
171 + tamperedCiphertextRejectedWithoutWrites: true,
172 sameCompanyRestore: true,
173 restoredContact: true,
174 restoreAudited: true,