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();
}
}
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,
assert.strictEqual(ctx.authenticationId, identifier);
});
it('fails', async function () {
- _authMechanismRequired(authenticator, 'argon2');
+ _authMechanismRequired(this, authenticator, 'argon2');
authenticator.db.authenticationGet.resolves({
identifier,
credential,
describe('isValidIdentifierCredential', function () {
it('succeeds', async function () {
- _authMechanismRequired(authenticator, 'argon2');
+ _authMechanismRequired(this, authenticator, 'argon2');
authenticator.db.authenticationGet.resolves({
identifier,
credential,
});
it('succeeds with OTP', async function () {
const otpKey = Buffer.from('1234567890');
- _authMechanismRequired(authenticator, 'argon2');
+ _authMechanismRequired(this, authenticator, 'argon2');
authenticator.db.authenticationGet.resolves({
identifier,
credential,
assert.deepStrictEqual(ctx.otpKey, otpKey);
});
it('fails', async function () {
- _authMechanismRequired(authenticator, 'argon2');
+ _authMechanismRequired(this, authenticator, 'argon2');
authenticator.db.authenticationGet.resolves({
identifier,
credential,
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,
describe('_isValidPAMIdentifier', function () {
let authData;
beforeEach(function () {
- _authMechanismRequired(authenticator, 'pam');
+ _authMechanismRequired(this, authenticator, 'pam');
sinon.stub(authenticator.authn.pam, 'pamAuthenticatePromise');
authData = {
identifier,
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);