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

57 lines
1.4 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-06-04 09:28:40 -07:00
before(common.setup);
after(common.cleanup);
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: 'unused'
};
const token2 = {
name: 'token2',
identifier: '2',
clientId: 'clientid-2',
expires: Date.now(),
2021-03-15 12:47:57 -07:00
lastUsedTime: null
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
});
});