tokens: add ip restriction
This commit is contained in:
@@ -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`)
|
||||
|
||||
Reference in New Issue
Block a user