/* eslint-env mocha */
+/* eslint-disable sonarjs/no-duplicate-string */
+/* eslint-disable jsdoc/require-jsdoc */
'use strict';
const assert = require('assert');
-const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
+const sinon = require('sinon');
const Authenticator = require('../../lib/authenticator');
const stubLogger = require('../stub-logger');
const stubDb = require('../stub-db');
it('covers success', async function () {
const otpKey = '1234567890123456789012';
await authenticator.createIdentifier(dbCtx, identifier, credential, otpKey);
- assert(authenticator.db.authenticationInsertIdentifier.called);
+ assert(authenticator.db.authenticationUpsert.called);
});
it('covers failure', async function () {
const expected = new Error('blah');
- await authenticator.db.authenticationInsertIdentifier.rejects(expected);
+ await authenticator.db.authenticationUpsert.rejects(expected);
// assert.rejects was not happy to handle this for some reason
try {
await authenticator.createIdentifier(dbCtx, identifier, credential);
assert.fail('no expecte exception');
} catch (e) {
assert.deepStrictEqual(e, expected);
- assert(authenticator.db.authenticationInsertIdentifier.called);
+ assert(authenticator.db.authenticationUpsert.called);
assert(authenticator.logger.error.called);
- }
+ }
});
}); // createIdentifier
});
}); // checkOTP
+ describe('updateOTPKey', function () {
+ let dbCtx, otpKey;
+ beforeEach(function () {
+ dbCtx = {};
+ otpKey = 'CDBGB3U3B2ILECQORMINGGSZN7LXY565';
+ });
+ it('covers success', async function () {
+ await authenticator.updateOTPKey(dbCtx, identifier, otpKey);
+ assert(authenticator.db.authenticationUpdateOTPKey.called);
+ });
+ it('covers failure', async function () {
+ authenticator.db.authenticationUpdateOTPKey.rejects();
+ assert.rejects(authenticator.updateOTPKey(dbCtx, identifier, otpKey));
+ });
+ }); // updateOTPKey
+
describe('sessionCheck', function () {
let req, res, loginPath, required, profilesAllowed;
beforeEach(function () {