فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): verify full backup head anchor against tampering and truncation
davoodmehraban89 committed
Oct 20, 2026 at 08:43 UTC
3a0ef50d6ecafb4f144c97d5661869f65991a301
1 file changed
+23
tests/a03-audit-integration.test.mjs
+23
@@ -292,3 +292,26 @@ test('A03: legacy v6 company backup without audit hashes is migrated', async ()
292
assert.match(restored.eventHash, /^[0-9a-f]{64}$/);
293
assert.equal((await AuditService.verifyChain()).valid, true);
294
});
295
+
296
+
297
+test('A03: full backup anchor detects changed, missing, reordered and truncated audit history', async () => {
298
+ const state = await setup();
299
+ await AccountingService.postJournal(journal(state));
300
+ const snapshot = await StorageService.exportAll();
301
+ assert.equal(snapshot.auditAnchors[company].count, 2);
302
+ const events = snapshot.data.audit_events.filter(row => row.companyId === company);
303
+ for (const kind of ['tamper', 'middle-delete', 'reorder', 'tail-delete']) {
304
+ const changed = structuredClone(snapshot);
305
+ const target = changed.data.audit_events;
306
+ if (kind === 'tamper') target[0].eventType = 'period_closed';
307
+ if (kind === 'middle-delete') target.splice(target.findIndex(row => row.id === events[0].id), 1);
308
+ if (kind === 'reorder') target.reverse();
309
+ if (kind === 'tail-delete') target.splice(target.findIndex(row => row.id === events[1].id), 1);
310
+ if (kind === 'reorder') {
311
+ // Full-backup imports normalize input order; reordering serialized rows alone is harmless.
312
+ await StorageService.importAll(changed);
313
+ } else {
314
+ await assert.rejects(StorageService.importAll(changed), /زنجیره ممیزی|لنگر/);
315
+ }
316
+ }
317
+});