authelia/test/unitary/test_totp.js

33 lines
854 B
JavaScript
Raw Normal View History

2016-12-10 00:47:58 +00:00
2017-01-19 00:44:24 +00:00
var totp = require('../../src/lib/totp');
2016-12-10 00:47:58 +00:00
var sinon = require('sinon');
2017-01-21 16:41:06 +00:00
var Promise = require('bluebird');
2016-12-10 00:47:58 +00:00
2017-01-21 16:41:06 +00:00
describe('test TOTP validation', function() {
2016-12-10 00:47:58 +00:00
it('should validate the TOTP token', function() {
var totp_secret = 'NBD2ZV64R9UV1O7K';
var token = 'token';
var totp_mock = sinon.mock();
totp_mock.returns('token');
var speakeasy_mock = {
totp: totp_mock
}
2017-01-19 00:44:24 +00:00
return totp.validate(speakeasy_mock, token, totp_secret);
2016-12-10 00:47:58 +00:00
});
it('should not validate a wrong TOTP token', function() {
var totp_secret = 'NBD2ZV64R9UV1O7K';
var token = 'wrong token';
var totp_mock = sinon.mock();
totp_mock.returns('token');
var speakeasy_mock = {
totp: totp_mock
}
2017-01-21 16:41:06 +00:00
return totp.validate(speakeasy_mock, token, totp_secret)
.catch(function() {
return Promise.resolve();
});
2016-12-10 00:47:58 +00:00
});
});