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

test(A06): verify non-admin backup export and wipe are denied without data loss

davoodmehraban89 committed Oct 14, 2026 at 22:23 UTC 3ecf1bf65cab54d1946d3945697c958bc503b51d
1 file changed +37
tests/backup-admin-authorization.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 { Auth } from '../src/core/Auth.js';
6 +import { CompanyService } from '../src/core/CompanyService.js';
7 +import { SettingsController } from '../src/controllers/SettingsController.js';
8 +
9 +test('A06: ordinary users cannot export company backup data', async () => {
10 + await StorageService.clearAll();
11 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
12 + await StorageService.put('contacts', { id: 'secret-customer', companyId: 'c1', name: 'Private' });
13 + CompanyService.activeCompanyId = 'c1';
14 + Auth.currentUser = { id: 'staff', role: 'user', companyIds: ['c1'], username: 'staff' };
15 + await assert.rejects(SettingsController.exportBackup(), /فقط توسط مدیر/);
16 + assert.equal((await StorageService.get('contacts', 'secret-customer')).name, 'Private');
17 +});
18 +
19 +test('A06: ordinary users cannot erase company or global data', async () => {
20 + await StorageService.clearAll();
21 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
22 + await StorageService.put('contacts', { id: 'important-customer', companyId: 'c1', name: 'Keep' });
23 + Auth.currentUser = { id: 'staff', role: 'user', companyIds: ['c1'], username: 'staff' };
24 + await assert.rejects(SettingsController.wipeAll(), /فقط توسط مدیر/);
25 + assert.ok(await StorageService.get('companies', 'c1'));
26 + assert.equal((await StorageService.get('contacts', 'important-customer')).name, 'Keep');
27 +});
28 +
29 +test('A06: administrator retains authorized export capability', async () => {
30 + await StorageService.clearAll();
31 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
32 + CompanyService.activeCompanyId = 'c1';
33 + Auth.currentUser = { id: 'manager', role: 'admin', username: 'manager' };
34 + const backup = await SettingsController.exportBackup();
35 + assert.equal(backup.scope, 'company');
36 + assert.equal(backup.companyId, 'c1');
37 +});