Enforce API key quota within the database transaction
This commit is contained in:
@@ -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'),[]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user