Enforce API key quota within the database transaction

This commit is contained in:
2026-09-06 10:40:45 +03:00
parent 1c0b48655e
commit 1a62a876e6
5 changed files with 63 additions and 11 deletions
+13
View File
@@ -56,3 +56,16 @@ test('per-tender versions prevent stale updates; five tasks persist', () => {
assert.equal(Object.keys(store.getTenderStates('c@example.test')).length,5);
assert.deepEqual(store.getTenderStates('d@example.test'),{});
});
test('API key quota is transactional and revoked slots can be reused', () => {
const email='quota@example.test';
const key=store.createApiKey(email,' ERP ',{limit:1});
assert.equal(key.ad,'ERP');
assert.throws(()=>store.createApiKey(email,'excess',{limit:1}), {kod:'KOTA_ASILDI'});
assert.equal(store.listApiKeys(email).length,1);
assert.equal(store.revokeApiKey(email,key.id),true);
assert.ok(store.createApiKey(email,'replacement',{limit:1}).id);
assert.equal(store.listApiKeys(email).length,1);
for(const ad of [{},[],42,'x'.repeat(121)])assert.throws(()=>store.createApiKey('invalid-name@example.test',ad));
assert.deepEqual(store.listApiKeys('invalid-name@example.test'),[]);
});