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

test(A06): enforce signed tenant/user quotas, writable lease and preserve existing records

davoodmehraban89 committed Oct 23, 2026 at 11:14 UTC d28aa4540205801edc091498090e7704732155ab
1 file changed +67
tests/a06-signed-license-integration.test.mjs
+67
@@ -3,6 +3,11 @@ import assert from 'node:assert/strict';
3 import { canonical } from '../src/core/EntitlementVerifier.mjs';
4 import { loadProductionLicensePublicKey, validateOfflineActivation }
5 from '../src/core/LicenseActivationCore.mjs';
6 +import 'fake-indexeddb/auto';
7 +import { StorageService as db } from '../src/core/StorageService.js';
8 +import { Auth } from '../src/core/Auth.js';
9 +import { CompanyService } from '../src/core/CompanyService.js';
10 +import { LicenseService } from '../src/core/LicenseService.js';
11
12 const NOW = Date.UTC(2026, 9, 15);
13 async function newSignedExample() {
@@ -76,3 +81,65 @@ test('A06: invalid wall-clock inputs cannot validate a signed offline lease', as
81 }
82 assert.equal(await validateOfflineActivation(token, pub, payload.installationId, NOW), true);
83 });
84 +
85 +test('A06: initialized verified quota limits new companies and users; existing data stays readable',async()=>{
86 + const previous={state:LicenseService.state,verifiedPayload:LicenseService.verifiedPayload,
87 + clockRollback:LicenseService.clockRollback,user:Auth.currentUser,
88 + company:CompanyService.activeCompanyId};
89 + try {
90 + await db.clearAll();
91 + await db.put('users',{id:'quota-admin',role:'admin',username:'quota-admin'});
92 + await db.put('companies',{id:'quota-primary',name:'Existing company'});
93 + Auth.currentUser={id:'quota-admin',role:'admin',username:'quota-admin'};
94 + CompanyService.activeCompanyId='quota-primary';
95 + const now=new Date().toISOString();
96 + LicenseService.state={installationId:'quota-device',lastSeenAt:now};
97 + // The signature/installation verification is tested above. Here we
98 + // simulate its already verified in-memory payload at the service boundary.
99 + LicenseService.verifiedPayload={
100 + product:'Factor-easyPro',installationId:'quota-device',
101 + perpetual:true,issuedAt:now,lastOnlineCheckAt:now,
102 + maxCompanies:1,maxUsers:1,maxDevices:1
103 + };
104 + LicenseService.clockRollback=false;
105 + await assert.rejects(CompanyService.create({name:'Blocked extra company'}),/تعداد شرکت/);
106 + await assert.rejects(Auth.createUser({
107 + username:'quota-staff',password:'secure-password-012345',
108 + displayName:'Employee'
109 + }),/تعداد کاربر/);
110 + assert.equal((await db.getAll('companies')).length,1);
111 + assert.equal((await db.getAll('users')).length,1);
112 + assert.equal((await CompanyService.list()).length,1);
113 + LicenseService.verifiedPayload={
114 + ...LicenseService.verifiedPayload,maxCompanies:2,maxUsers:2
115 + };
116 + const newCompany=await CompanyService.create({name:'Allowed second company'});
117 + assert.ok(newCompany.id);
118 + const newUser=await Auth.createUser({
119 + username:'quota-staff',password:'secure-password-012345',
120 + displayName:'Employee'
121 + });
122 + assert.equal(newUser.username,'quota-staff');
123 + assert.equal((await db.getAll('companies')).length,2);
124 + assert.equal((await db.getAll('users')).length,2);
125 + await assert.rejects(CompanyService.create({name:'Third company'}),/تعداد شرکت/);
126 + await assert.rejects(Auth.createUser({
127 + username:'third-staff',password:'secure-password-012345'
128 + }),/تعداد کاربر/);
129 + LicenseService.clockRollback=true;
130 + await assert.rejects(CompanyService.create({name:'Expired write'}),/پایان/);
131 + await assert.rejects(Auth.createUser({
132 + username:'expired-staff',password:'secure-password-012345'
133 + }),/پایان/);
134 + assert.equal((await db.getAll('companies')).length,2,
135 + 'Read-only license must not delete existing company data');
136 + assert.equal((await db.getAll('users')).length,2,
137 + 'Read-only license must not delete existing accounts');
138 + } finally {
139 + LicenseService.state=previous.state;
140 + LicenseService.verifiedPayload=previous.verifiedPayload;
141 + LicenseService.clockRollback=previous.clockRollback;
142 + Auth.currentUser=previous.user;
143 + CompanyService.activeCompanyId=previous.company;
144 + }
145 +});