tokens: add ip restriction

This commit is contained in:
Girish Ramakrishnan
2025-03-07 11:53:03 +01:00
parent 2b0fd17fbf
commit 5342dae5b3
21 changed files with 177 additions and 44 deletions
+29
View File
@@ -79,6 +79,35 @@ describe('Tokens API', function () {
});
});
describe('allowedIpRanges', function () {
let allowedRangeToken;
it('cannot create token with bad range', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/tokens`)
.query({ access_token: owner.token })
.send({ name: 'mytoken1', allowedIpRanges: 'What' })
.ok(() => true);
expect(response.status).to.equal(400);
});
it('can create token with valid range', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/tokens`)
.query({ access_token: owner.token })
.send({ name: 'mytoken1', allowedIpRanges: '#this is localhost\n10.0.0.0/8' });
expect(response.status).to.equal(201);
allowedRangeToken = response.body;
});
it('cannot use access restricted token', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/tokens`)
.query({ access_token: allowedRangeToken.accessToken })
.ok(() => true);
expect(response.status).to.equal(401);
});
});
describe('readonly token', function () {
it('cannot create token with read only token', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/tokens`)