From 786f4aa122c3c3a1c1c8224abacd12d0ca079cd0 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 10 May 2024 14:23:34 -0700 Subject: [PATCH] add updateOTPKey wrapper to authenticator --- lib/authenticator.js | 17 +++++++++++++++++ test/lib/authenticator.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/authenticator.js b/lib/authenticator.js index 36c1574..dc56e9e 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -319,6 +319,23 @@ class Authenticator { } + /** + * Update the authentication database with a new otp key. + * @param {*} dbCtx db context + * @param {string} identifier identifier + * @param {string=} otpKey otp key + */ + async updateOTPKey(dbCtx, identifier, otpKey) { + const _scope = _fileScope('updateOTPKey'); + try { + await this.db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey); + this.logger.info(_scope, 'otp key updated'); + } catch (e) { + this.logger.error(_scope, 'failed', { error: e, identifier }); + } + } + + /** * Check for valid Basic auth, updates ctx with identifier if valid. * @param {String} credentials diff --git a/test/lib/authenticator.js b/test/lib/authenticator.js index 534fd02..341bc9b 100644 --- a/test/lib/authenticator.js +++ b/test/lib/authenticator.js @@ -383,6 +383,22 @@ describe('Authenticator', function () { }); }); // 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 () { -- 2.44.2