tokens: async'ify
This commit is contained in:
@@ -22,7 +22,6 @@ const appdb = require('../appdb.js'),
|
||||
reverseProxy = require('../reverseproxy.js'),
|
||||
settingsdb = require('../settingsdb.js'),
|
||||
taskdb = require('../taskdb.js'),
|
||||
tokendb = require('../tokendb.js'),
|
||||
userdb = require('../userdb.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
@@ -551,142 +550,6 @@ describe('database', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('token', function () {
|
||||
var TOKEN_0 = {
|
||||
id: 'tid-0',
|
||||
name: 'token0',
|
||||
accessToken: hat(8 * 32),
|
||||
identifier: '0',
|
||||
clientId: 'clientid-0',
|
||||
expires: Date.now() + 60 * 60000,
|
||||
lastUsedTime: null,
|
||||
scope: ''
|
||||
};
|
||||
var TOKEN_1 = {
|
||||
id: 'tid-1',
|
||||
name: 'token1',
|
||||
accessToken: hat(8 * 32),
|
||||
identifier: '1',
|
||||
clientId: 'clientid-1',
|
||||
expires: Number.MAX_SAFE_INTEGER,
|
||||
lastUsedTime: null,
|
||||
scope: ''
|
||||
};
|
||||
var TOKEN_2 = {
|
||||
id: 'tid-2',
|
||||
name: 'token2',
|
||||
accessToken: hat(8 * 32),
|
||||
identifier: '2',
|
||||
clientId: 'clientid-2',
|
||||
expires: Date.now(),
|
||||
lastUsedTime: null,
|
||||
scope: ''
|
||||
};
|
||||
|
||||
it('add succeeds', function (done) {
|
||||
tokendb.add(TOKEN_0, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('add of same token fails', function (done) {
|
||||
tokendb.add(TOKEN_0, function (error) {
|
||||
expect(error).to.be.a(BoxError);
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get succeeds', function (done) {
|
||||
tokendb.get(TOKEN_0.id, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.be.eql(TOKEN_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getByAccessToken succeeds', function (done) {
|
||||
tokendb.getByAccessToken(TOKEN_0.accessToken, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.be.eql(TOKEN_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get of nonexisting token fails', function (done) {
|
||||
tokendb.getByAccessToken(TOKEN_1.accessToken, function (error, result) {
|
||||
expect(error).to.be.a(BoxError);
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
expect(result).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getByIdentifier succeeds', function (done) {
|
||||
tokendb.getByIdentifier(TOKEN_0.identifier, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(result[0]).to.be.an('object');
|
||||
expect(result[0]).to.be.eql(TOKEN_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delete fails', function (done) {
|
||||
tokendb.del(TOKEN_0.id + 'x', function (error) {
|
||||
expect(error).to.be.a(BoxError);
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delete succeeds', function (done) {
|
||||
tokendb.del(TOKEN_0.id, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getByIdentifier succeeds after token deletion', function (done) {
|
||||
tokendb.getByIdentifier(TOKEN_0.identifier, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot delete previously delete record', function (done) {
|
||||
tokendb.del(TOKEN_0.id, function (error) {
|
||||
expect(error).to.be.a(BoxError);
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delExpired succeeds', function (done) {
|
||||
tokendb.add(TOKEN_2, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
tokendb.delExpired(function (error, result) {
|
||||
expect(error).to.not.be.ok();
|
||||
expect(result).to.eql(1);
|
||||
|
||||
tokendb.getByAccessToken(TOKEN_2.accessToken, function (error, result) {
|
||||
expect(error).to.be.a(BoxError);
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
expect(result).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('apps', function () {
|
||||
var APP_0 = {
|
||||
id: 'appid-0',
|
||||
|
||||
Reference in New Issue
Block a user