Files
cloudron-box/src/test/janitor-test.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-10-14 22:50:07 -07:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2021-06-04 09:28:40 -07:00
const common = require('./common.js'),
2015-10-14 22:50:07 -07:00
expect = require('expect.js'),
janitor = require('../janitor.js'),
2021-06-04 09:28:40 -07:00
tokens = require('../tokens.js');
2015-10-14 22:50:07 -07:00
describe('janitor', function () {
2021-08-13 10:41:10 -07:00
const { setup, cleanup } = common;
before(setup);
after(cleanup);
2021-06-04 09:28:40 -07:00
const token1 = {
name: 'token1',
identifier: '1',
2015-10-14 22:50:07 -07:00
clientId: 'clientid-1',
2021-06-04 09:28:40 -07:00
expires: Number.MAX_SAFE_INTEGER,
lastUsedTime: null,
scope: { '*': 'rw' }
2021-06-04 09:28:40 -07:00
};
const token2 = {
name: 'token2',
identifier: '2',
clientId: 'clientid-2',
expires: Date.now(),
lastUsedTime: null,
scope: null //{ '*': 'rw '}
2015-10-14 22:50:07 -07:00
};
2021-06-04 09:28:40 -07:00
it('can cleanupTokens', async function () {
let result = await tokens.add(token1);
token1.id = result.id;
token1.accessToken = result.accessToken;
2015-10-14 22:50:07 -07:00
2021-06-04 09:28:40 -07:00
result = await tokens.add(token2);
token2.id = result.id;
token2.accessToken = result.accessToken;
2015-10-14 22:50:07 -07:00
2021-06-04 09:28:40 -07:00
await janitor.cleanupTokens();
2015-10-14 22:50:07 -07:00
});
2021-06-04 09:28:40 -07:00
it('did not remove the non-expired token', async function () {
const result = await tokens.getByAccessToken(token1.accessToken);
expect(result).to.be.eql(token1);
2015-10-14 22:50:07 -07:00
});
2021-06-04 09:28:40 -07:00
it('did remove the non-expired token', async function () {
const result = await tokens.getByAccessToken(token2.accessToken);
expect(result).to.be(null);
2015-10-14 22:50:07 -07:00
});
});