X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fintegration.js;h=c26e277878f344573481c8ae0b1196bc43b51a7a;hb=f0bf29c75b0fd405ff92fa76f058e61162b87e43;hp=7634b30c748a05726332457baf098e9cc7749bb6;hpb=b0103b0d496262c438b40bc20304081dbfe41e73;p=squeep-indie-auther diff --git a/test/src/db/integration.js b/test/src/db/integration.js index 7634b30..c26e277 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -1,5 +1,4 @@ -/* eslint-env mocha */ -/* eslint-disable sonarjs/no-identical-functions */ +/* eslint-disable security/detect-object-injection */ 'use strict'; /** @@ -17,7 +16,7 @@ */ const assert = require('assert'); -const { step } = require('mocha-steps'); // eslint-disable-line node/no-unpublished-require +const { step } = require('mocha-steps'); const StubLogger = require('../../stub-logger'); // const DBErrors = require('../../../src/db/errors'); // const testData = require('../../test-data/db-integration'); @@ -137,9 +136,10 @@ describe('Database Integration', function () { }); // Resources describe('Users and Profiles and Scopes', function () { - let credential; + let credential, otpKey; beforeEach(function () { credential = '$plain$myPassword'; + otpKey = '1234567890123456789012'; }); step('returns nothing when auth does not exist', async function () { await db.context(async (dbCtx) => { @@ -170,9 +170,25 @@ describe('Database Integration', function () { step('update auth entry', async function () { await db.context(async (dbCtx) => { credential = '$plain$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 credential', async function () { + await db.context(async (dbCtx) => { + credential = '$plain$anotherNewPassword'; + await db.authenticationUpdateCredential(dbCtx, identifier, credential); + const authInfo = await db.authenticationGet(dbCtx, identifier); + assert.strictEqual(authInfo.credential, credential); + }); + }); + step('update auth otp', async function () { + await db.context(async (dbCtx) => { + await db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey); + const authInfo = await db.authenticationGet(dbCtx, identifier); + assert.strictEqual(authInfo.otpKey, otpKey); }); }); step('profile is not valid', async function () { @@ -405,6 +421,65 @@ describe('Database Integration', function () { }); }); // Token + describe('Ticket Token Tracking', function () { + let redeemedData; + beforeEach(function () { + redeemedData = { + subject: 'https://entity.example.com/', + resource: 'https://blog.example.com/secret_entry', + iss: 'https://idp.example.com/', + ticket: 'xxxTICKETxxx', + token: 'xxxTOKENxxx', + }; + }); + step('stores redeemed ticket data', async function () { + await db.context(async (dbCtx) => { + await db.ticketRedeemed(dbCtx, redeemedData); + }); + }); + step('gets one pending-publish ticket tokens', async function () { + await db.context(async (dbCtx) => { + const unpublished = await db.ticketTokenGetUnpublished(dbCtx); + assert.strictEqual(unpublished.length, 1); + const record = unpublished[0]; + assert(record.created); + assert(!record.published); + assert(record.ticketId); + delete record.created; + delete record.published; + delete record.ticketId; + assert.deepStrictEqual(record, redeemedData); + }); + }); + step('stores published ticket token data', async function () { + await db.context(async (dbCtx) => { + await db.ticketTokenPublished(dbCtx, redeemedData); + }); + }); + step('gets no pending-publish ticket tokens', async function () { + await db.context(async (dbCtx) => { + const unpublished = await db.ticketTokenGetUnpublished(dbCtx); + assert.strictEqual(unpublished.length, 0); + }); + }); + }); // Ticket Token Tracking + + describe('Bookkeeping', function () { + let event, date; + beforeEach(function () { + event = 'integrationTestEvent'; + date = new Date('Fri Dec 22 03:27 UTC 2023'); + }); + step('inserts event', async function () { + await db.context(async (dbCtx) => { + await db.almanacUpsert(dbCtx, event, date); + const result = await db.almanacGetAll(dbCtx); + const [storedEvent] = result.filter((e) => e.event === event); + assert.deepStrictEqual(storedEvent.date, date); + }); + }); + }); // Bookkeeping + describe('Refreshable Token', function () { let created, codeId, scopes, clientId, profileData, lifespanSeconds, refreshLifespanSeconds, removeScopes; beforeEach(function () {