فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A04): verify corrupt encrypted backup rejection in installed Windows app
Native Windows NSIS/WebView2 negative-path A04 test: tamper genuine AES-GCM authentication tag; reject restore visibly without writes or audit records, clean expected error/modal via UI, then restore intact backup and sweep ten UI routes. Checks PASS: PR quality #38942948237; Windows Native VM #38942948274. No release or actual customer data.
davoodmehraban89 committed
Oct 16, 2026 at 21:29 UTC
458c31e3bc6e3b30d04c8e2d5b6c71817c291d85
2 files changed
+40
-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,
tests/windows-vm-installed-tauri-cdp.cjs
+1
@@ -307,6 +307,7 @@ async function connect(url) {
307
encryptedEnvelope: true,
308
filenameSuffix: '.fbackup',
309
wrongPasswordRejected: true,
310
+ tamperedCiphertextRejectedWithoutWrites: true,
311
sameCompanyRestore: true,
312
restoredContact: true,
313
restoreAudited: true,