X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fintegration.js;h=eed37e2c55f5070c4031f4c47d1a8491ace96588;hb=3ca7fccb306d0b23626befc3791ffa360b3db1e7;hp=7eb7d91670295b0f4bafad18f15b2e8bb31e7f56;hpb=1c37a7c533a5530390489ea9a49dcca492db1074;p=websub-hub diff --git a/test/src/db/integration.js b/test/src/db/integration.js index 7eb7d91..eed37e2 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -83,33 +83,51 @@ describe('Database Integration', function () { }); describe('Authentication', function () { - let identifier, credential; + let identifier, credential, otpKey; beforeEach(function () { identifier = 'username'; credential = 'myEncryptedPassword'; + otpKey = '1234567890123456789012'; }); - step('create auth entry', async function() { + step('create auth entry', async function () { await db.context(async (dbCtx) => { await db.authenticationUpsert(dbCtx, identifier, credential); }); }); - step('get auth entry', async function() { + step('get auth entry', async function () { await db.context(async (dbCtx) => { const authInfo = await db.authenticationGet(dbCtx, identifier); assert.strictEqual(authInfo.credential, credential); }); }); - step('valid auth event', async function() { + step('valid auth event', async function () { await db.context(async (dbCtx) => { await db.authenticationSuccess(dbCtx, identifier); const authInfo = await db.authenticationGet(dbCtx, identifier); assert.notStrictEqual(authInfo.lastAuthentication, undefined); }); }); - step('update auth entry', async function() { + step('update auth entry', async function () { await db.context(async (dbCtx) => { credential = 'myNewPassword'; - await db.authenticationUpsert(dbCtx, identifier, credential); + await db.authenticationUpsert(dbCtx, identifier, credential, otpKey); + const authInfo = await db.authenticationGet(dbCtx, identifier); + assert.strictEqual(authInfo.credential, credential); + assert.strictEqual(authInfo.otpKey, otpKey); + }); + }); + step('update auth otp key', async function () { + await db.context(async (dbCtx) => { + const removedOTPKey = null; + await db.authenticationUpdateOTPKey(dbCtx, identifier, removedOTPKey); + const authInfo = await db.authenticationGet(dbCtx, identifier); + assert.strictEqual(authInfo.otpKey, removedOTPKey); + }); + }); + step('update credential', async function () { + await db.context(async (dbCtx) => { + credential = '$plain$anotherCredential'; + await db.authenticationUpdateCredential(dbCtx, identifier, credential); const authInfo = await db.authenticationGet(dbCtx, identifier); assert.strictEqual(authInfo.credential, credential); });