Преглед на файлове

Fix key limit check and add test

production
Jack Foltz преди 5 години
родител
ревизия
d28ce97ff5
Signed by: foltik <jack@foltz.io> GPG Key ID: 303F88F996E95541
променени са 2 файла, в които са добавени 16 реда и са изтрити 1 реда
  1. +1
    -1
      app/routes/api/keys.js
  2. +15
    -0
      test/api.js

+ 1
- 1
app/routes/api/keys.js Целия файл

@@ -15,7 +15,7 @@ const createParams = [
{name: 'identifier', type: 'string', sanitize: true},
{name: 'scope', instance: Array}];
router.post('/create', requireAuth('key.create'), bodyVerifier(createParams), wrap(async (req, res) => {
const keyCount = await Key.countDocuments({username: req.username});
const keyCount = await Key.countDocuments({issuer: req.username});
if (keyCount >= config.get('Key.limit'))
return res.status(403).json({message: 'Key limit reached.'});



+ 15
- 0
test/api.js Целия файл

@@ -687,6 +687,21 @@ describe('Keys', () => {
util.verifyResponse(res, 403, 'Requested scope exceeds own scope.');
});
});

describe('2 Key Limit', () => {
it('must not create additional keys beyond the limit', async () => {
await util.createSession(agent, ['key.create', 'file.upload']);
const limit = config.get('Key.limit');

// Create keys upto the limit (key0, key1, key2, ...)
await Promise.all(
[...Array(limit)]
.map(idx => util.createKey({identifier: 'key' + idx, scope: ['file.upload']}, agent)));

const res = await util.createKey({identifier: 'toomany', scope: ['file.upload']}, agent);
util.verifyResponse(res, 403, 'Key limit reached.');
});
});
});

describe('/POST delete', () => {


Loading…
Отказ
Запис