From: Justin Wind Date: Fri, 25 Oct 2024 17:07:12 +0000 (-0700) Subject: fix tests for optional deps X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=6603183d4405dc68db8d919f4efa6f4f709aa8ab;p=squeep-authentication-module fix tests for optional deps --- diff --git a/lib/authenticator.js b/lib/authenticator.js index 2534cfa..7b61cf4 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -84,10 +84,10 @@ class Authenticator { plain: {}, }; try { - this.authn.argon2 = require('argon2'); + this.authn.argon2 = require('argon2'); // eslint-disable-line n/no-missing-require } catch (e) { /**/ } // eslint-disable-line no-unused-vars try { - this.authn.pam = require('node-linux-pam'); + this.authn.pam = require('node-linux-pam'); // eslint-disable-line n/no-missing-require this.forbiddenPAMIdentifiers = options.authenticator.forbiddenPAMIdentifiers ?? ['root']; } catch (e) { /**/ } // eslint-disable-line no-unused-vars diff --git a/test/lib/authenticator.js b/test/lib/authenticator.js index 0e55094..3b24245 100644 --- a/test/lib/authenticator.js +++ b/test/lib/authenticator.js @@ -10,9 +10,9 @@ const Config = require('../stub-config'); describe('Authenticator', function () { let authenticator, credential, ctx, identifier, password, options; - function _authMechanismRequired(a, m) { + function _authMechanismRequired(t, a, m) { if (!a.authn[m]) { // eslint-disable-line security/detect-object-injection - this.skip(); + t.skip(); } } @@ -144,7 +144,7 @@ describe('Authenticator', function () { describe('isValidBasic', function () { const b64 = (x) => Buffer.from(x).toString('base64'); it('succeeds', async function () { - _authMechanismRequired(authenticator, 'argon2'); + _authMechanismRequired(this, authenticator, 'argon2'); authenticator.db.authenticationGet.resolves({ identifier, credential, @@ -155,7 +155,7 @@ describe('Authenticator', function () { assert.strictEqual(ctx.authenticationId, identifier); }); it('fails', async function () { - _authMechanismRequired(authenticator, 'argon2'); + _authMechanismRequired(this, authenticator, 'argon2'); authenticator.db.authenticationGet.resolves({ identifier, credential, @@ -186,7 +186,7 @@ describe('Authenticator', function () { describe('isValidIdentifierCredential', function () { it('succeeds', async function () { - _authMechanismRequired(authenticator, 'argon2'); + _authMechanismRequired(this, authenticator, 'argon2'); authenticator.db.authenticationGet.resolves({ identifier, credential, @@ -197,7 +197,7 @@ describe('Authenticator', function () { }); it('succeeds with OTP', async function () { const otpKey = Buffer.from('1234567890'); - _authMechanismRequired(authenticator, 'argon2'); + _authMechanismRequired(this, authenticator, 'argon2'); authenticator.db.authenticationGet.resolves({ identifier, credential, @@ -209,7 +209,7 @@ describe('Authenticator', function () { assert.deepStrictEqual(ctx.otpKey, otpKey); }); it('fails', async function () { - _authMechanismRequired(authenticator, 'argon2'); + _authMechanismRequired(this, authenticator, 'argon2'); authenticator.db.authenticationGet.resolves({ identifier, credential, @@ -240,7 +240,7 @@ describe('Authenticator', function () { assert.strictEqual(ctx.authenticationId, undefined); }); it('covers PAM', async function () { - _authMechanismRequired(authenticator, 'pam'); + _authMechanismRequired(this, authenticator, 'pam'); sinon.stub(authenticator, '_isValidPAMIdentifier').resolves(true); authenticator.db.authenticationGet.resolves({ identifier, @@ -255,7 +255,7 @@ describe('Authenticator', function () { describe('_isValidPAMIdentifier', function () { let authData; beforeEach(function () { - _authMechanismRequired(authenticator, 'pam'); + _authMechanismRequired(this, authenticator, 'pam'); sinon.stub(authenticator.authn.pam, 'pamAuthenticatePromise'); authData = { identifier, @@ -267,13 +267,11 @@ describe('Authenticator', function () { assert.strictEqual(result, true); }); it('covers failure', async function () { - _authMechanismRequired(authenticator, 'pam'); authenticator.authn.pam.pamAuthenticatePromise.rejects(new authenticator.authn.pam.PamError()); const result = await authenticator._isValidPAMIdentifier(authData, credential); assert.strictEqual(result, false); }); it('covers error', async function () { - _authMechanismRequired(authenticator, 'pam'); const expected = new Error('blah'); authenticator.authn.pam.pamAuthenticatePromise.rejects(expected); assert.rejects(() => authenticator._isValidPAMIdentifier(authData, credential), expected);