فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): prevent cross-company audit/correction leaks in generic DataScope
davoodmehraban89 committed
Oct 16, 2026 at 16:43 UTC
ab506d88547e390cabfe163d26afc190d967ef19
1 file changed
+37
tests/a03-company-scope-immutable-stores.test.mjs
new
+37
@@ -0,0 +1,37 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import 'fake-indexeddb/auto';
4
+import { StorageService } from '../src/core/StorageService.js';
5
+import { DataScope } from '../src/core/DataScope.js';
6
+import { Auth } from '../src/core/Auth.js';
7
+import { CompanyService } from '../src/core/CompanyService.js';
8
+
9
+test('A03: common scoped reads do not leak another company audit history or corrections', async () => {
10
+ await StorageService.clearAll();
11
+ Auth.currentUser = { id: 'staff-one', username: 'one', role: 'user', companyIds: ['c1'] };
12
+ await StorageService.put('companies', { id: 'c1', name: 'Company One' });
13
+ await StorageService.put('companies', { id: 'c2', name: 'Company Two' });
14
+ CompanyService.activeCompanyId = 'c1';
15
+
16
+ await StorageService.put('audit_events', {
17
+ id: 'event-c1', companyId: 'c1', commandKey: 'c1:test', eventType: 'journal_posted'
18
+ });
19
+ await StorageService.put('audit_events', {
20
+ id: 'event-c2', companyId: 'c2', commandKey: 'c2:test', eventType: 'journal_posted'
21
+ });
22
+ await StorageService.put('document_corrections', {
23
+ id: 'cor-c1', companyId: 'c1', idempotencyKey: 'c1:cor'
24
+ });
25
+ await StorageService.put('document_corrections', {
26
+ id: 'cor-c2', companyId: 'c2', idempotencyKey: 'c2:cor'
27
+ });
28
+ assert.deepEqual((await DataScope.list('audit_events')).map(row => row.id), ['event-c1']);
29
+ assert.deepEqual((await DataScope.list('document_corrections')).map(row => row.id), ['cor-c1']);
30
+ assert.equal((await DataScope.stamp('audit_events', { eventType: 'journal_posted' })).companyId, 'c1');
31
+ assert.equal((await DataScope.stamp('document_corrections', { sourceId: 'x' })).companyId, 'c1');
32
+
33
+ CompanyService.activeCompanyId = 'c2';
34
+ // Even if a tampered UI points at another company, allowedFor returns only c1.
35
+ assert.deepEqual((await DataScope.list('audit_events')).map(row => row.id), ['event-c1']);
36
+ assert.deepEqual((await DataScope.list('document_corrections')).map(row => row.id), ['cor-c1']);
37
+});