+ describe('checkOTP', function () {
+ let state, otp;
+ this.beforeEach(function () {
+ sinon.stub(authenticator.TOTP.prototype, 'validate').returns(true);
+ state = {
+ key: Buffer.from('12345678901234567890'),
+ attempt: 0,
+ epochMs: Date.now(),
+ };
+ otp = '000000';
+ });
+ it('covers valid OTP entry', function () {
+ const result = authenticator.checkOTP(state, otp);
+ assert.strictEqual(result, Enum.OTPResult.Valid);
+ });
+ it('covers invalid OTP entry', function () {
+ authenticator.TOTP.prototype.validate.returns(false);
+ const result = authenticator.checkOTP(state, otp);
+ assert.strictEqual(result, Enum.OTPResult.InvalidSoftFail);
+ });
+ it('covers invalid OTP entry, too many failures', function () {
+ state.attempt = 10;
+ authenticator.TOTP.prototype.validate.returns(false);
+ const result = authenticator.checkOTP(state, otp);
+ assert.strictEqual(result, Enum.OTPResult.InvalidHardFail);
+ });
+ it('covers invalid OTP entry', function () {
+ state.epochMs = 0;
+ authenticator.TOTP.prototype.validate.returns(false);
+ const result = authenticator.checkOTP(state, otp);
+ assert.strictEqual(result, Enum.OTPResult.InvalidHardFail);
+ });
+ }); // checkOTP
+