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

75 lines
1.9 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';
var async = require('async'),
BoxError = require('../boxerror.js'),
2015-10-14 22:50:07 -07:00
database = require('../database'),
expect = require('expect.js'),
2019-02-15 14:40:15 -08:00
hat = require('../hat.js'),
2015-10-14 22:50:07 -07:00
janitor = require('../janitor.js'),
tokendb = require('../tokendb.js');
describe('janitor', function () {
var TOKEN_0 = {
2019-02-15 14:40:15 -08:00
id: 'tid-0',
accessToken: hat(8 * 32),
identifier: '0',
2015-10-14 22:50:07 -07:00
clientId: 'clientid-0',
expires: Date.now() + 60 * 60 * 1000,
2018-08-27 14:50:41 -07:00
scope: 'settings',
name: 'clientid0'
2015-10-14 22:50:07 -07:00
};
var TOKEN_1 = {
2019-02-15 14:40:15 -08:00
id: 'tid-1',
accessToken: hat(8 * 32),
identifier: '1',
2015-10-14 22:50:07 -07:00
clientId: 'clientid-1',
expires: Date.now() - 1000,
scope: 'apps',
2018-08-27 14:50:41 -07:00
name: 'clientid1'
2015-10-14 22:50:07 -07:00
};
before(function (done) {
async.series([
database.initialize,
database._clear,
2019-02-15 14:40:15 -08:00
tokendb.add.bind(null, TOKEN_0),
tokendb.add.bind(null, TOKEN_1)
2015-10-14 22:50:07 -07:00
], done);
});
after(function (done) {
async.series([
database._clear,
database.uninitialize
], done);
2015-10-14 22:50:07 -07:00
});
it('can cleanupTokens', function (done) {
janitor.cleanupTokens(done);
});
it('did not remove the non-expired token', function (done) {
tokendb.getByAccessToken(TOKEN_0.accessToken, function (error, result) {
2015-10-14 22:50:07 -07:00
expect(error).to.be(null);
expect(result).to.be.eql(TOKEN_0);
done();
});
});
it('did remove the non-expired token', function (done) {
tokendb.getByAccessToken(TOKEN_1.accessToken, function (error, result) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
2015-10-14 22:50:07 -07:00
expect(result).to.not.be.ok();
done();
});
});
});