From 54ca04e330d14a12344ddc2b161c1d9b55bfd7d7 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Sat, 16 Mar 2024 13:51:31 -0700 Subject: [PATCH] use existing auth db method for identifier creation --- lib/authenticator.js | 4 ++-- test/lib/authenticator.js | 6 +++--- test/stub-db.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/authenticator.js b/lib/authenticator.js index 7390db5..36c1574 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -33,7 +33,7 @@ class Authenticator { * @property {(DBContextExec) => Promise} context * @property {(dbCtx: any, identifier: String) => Promise } authenticationGet * @property {(dbCtx: any, identifier: String) => Promise} authenticationSuccess - * @property {(dbCtx: any, identifier: String, credential: String, otpKey: String=) => Promise} authenticationInsertIdentifier + * @property {(dbCtx: any, identifier: String, credential: String, otpKey: String=) => Promise} authenticationUpsert * @property {(dbCtx: any, identifier: String, otpKey: String) => Promise} authenticationUpdateOTPKey * @property {(dbCtx: any, identifier: String, credential: AuthInfo) => Promise} authenticationUpdateCredential */ @@ -117,7 +117,7 @@ class Authenticator { const _scope = _fileScope('createIdentifier'); try { const secureCredential = await this._secureCredential(credential); - await this.db.authenticationInsertIdentifier(dbCtx, identifier, secureCredential, otpKey); + await this.db.authenticationUpsert(dbCtx, identifier, secureCredential, otpKey); } catch (e) { this.logger.error(_scope, 'failed', { error: e, identifier }); throw e; diff --git a/test/lib/authenticator.js b/test/lib/authenticator.js index dea4a84..534fd02 100644 --- a/test/lib/authenticator.js +++ b/test/lib/authenticator.js @@ -60,18 +60,18 @@ describe('Authenticator', function () { 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); } }); diff --git a/test/stub-db.js b/test/stub-db.js index 62f5f3d..0df6b9e 100644 --- a/test/stub-db.js +++ b/test/stub-db.js @@ -10,7 +10,7 @@ const spyFns = [ const stubFns = [ 'authenticationGet', - 'authenticationInsertIdentifier', + 'authenticationUpsert', 'authenticationSuccess', 'authenticationUpdateCredential', 'authenticationUpdateOTPKey', -- 2.45.2