mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 22:43:38 +00:00
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* fix: Fence Auth User Cache Writes After Eviction and Evict Favorite Holders An eviction now leaves a per-user fence in the auth user cache that outlives every document read before it. The reader skips a cached document while its user is fenced, and a lookup slower than one cache TTL is not cached, so a request that read the user before a change can no longer repopulate the cache afterwards, and a document the reverse index lost is hidden as well. Role and user methods share one bulk eviction helper, and the terms reset only waits out the TTL when an eviction failed. Deleting an agent, deleting a user's agents and removing an agent from favorites now evict the cached auth documents of the users whose favorites changed. * fix: Anchor Cached Auth Document Expiry to the Lookup Start A stalled reverse-index write could land a stale document after the eviction fence expired, with a fresh TTL. The document now carries an expiry two cache TTLs after its lookup began; its Redis TTL is computed after the index write and the reader refuses it past that expiry. * refactor: Time the Auth User Lookup in the API Package The lookup start that anchors a cached document's lifetime is now stamped by timeAuthUserLookup in packages/api, so the OpenID JWT strategy only wires the lookup through it. * fix: Wait Out the Full Cached Document Lifetime After Failed Eviction A document read just before a change can live two cache TTLs from its lookup, so a credential change or terms reset whose eviction failed now waits that long before reporting success. * fix: Recheck Cached Auth Document Expiry After the Fence Read A fence read that stalls can return after both the fence and the document expired, so the reader checks the document's expiry again before serving it.
419 lines
17 KiB
TypeScript
419 lines
17 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import os from 'os';
|
|
import { Keyv } from 'keyv';
|
|
import KeyvRedis from '@keyv/redis';
|
|
import { expect, test } from '@playwright/test';
|
|
import { isAuthUserDocEvictionFenced } from '@librechat/data-schemas';
|
|
import {
|
|
CacheKeys,
|
|
AUTH_USER_DOC_BY_ID_PREFIX,
|
|
AUTH_USER_DOC_CACHE_TTL_MS,
|
|
AUTH_USER_DOC_MAX_AGE_MS,
|
|
AUTH_USER_DOC_EVICTED_PREFIX,
|
|
AUTH_USER_DOC_EVICTION_FENCE_TTL_MS,
|
|
} from 'librechat-data-provider';
|
|
import { spawn } from 'node:child_process';
|
|
import { randomInt, randomUUID } from 'node:crypto';
|
|
import { withMongo, seedPasskey, deleteUserByEmail } from '../db';
|
|
|
|
const PASSWORD = 'test1234!';
|
|
const NEW_PASSWORD = 'fresh-password-1';
|
|
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
const NO_AUTO_INDEX = path.join(__dirname, 'no-auto-index.cjs');
|
|
|
|
type RuntimeEnv = { MONGO_URI?: string };
|
|
|
|
function getMongoUri(): string {
|
|
const runtimeEnvPath =
|
|
process.env.E2E_RUNTIME_ENV_PATH ??
|
|
path.resolve(__dirname, '../../.test-results/runtime-env.json');
|
|
try {
|
|
const env = JSON.parse(fs.readFileSync(runtimeEnvPath, 'utf8')) as RuntimeEnv;
|
|
if (env.MONGO_URI) {
|
|
return env.MONGO_URI;
|
|
}
|
|
} catch {
|
|
/* fall through to env */
|
|
}
|
|
return process.env.MONGO_URI ?? 'mongodb://127.0.0.1:27017/LibreChat-e2e';
|
|
}
|
|
|
|
/**
|
|
* Drives the interactive reset CLI the way an administrator would, answering
|
|
* each prompt as it appears rather than pre-loading stdin, which the prompt
|
|
* loop would consume as one burst.
|
|
*/
|
|
function runResetCli(
|
|
email: string,
|
|
cwd: string,
|
|
env: NodeJS.ProcessEnv,
|
|
): Promise<{
|
|
code: number | null;
|
|
stdout: string;
|
|
stderr: string;
|
|
/** Milliseconds between confirming the new password and the CLI reporting success. */
|
|
reportDelayMs?: number;
|
|
}> {
|
|
const child = spawn(process.execPath, [path.join(REPO_ROOT, 'config/reset-password.js')], {
|
|
cwd,
|
|
env: {
|
|
...env,
|
|
MONGO_URI: getMongoUri(),
|
|
/** The harness server already built the indexes; skip the module-scope rebuild. */
|
|
NODE_OPTIONS: process.env.NODE_OPTIONS
|
|
? `${process.env.NODE_OPTIONS} --require ${NO_AUTO_INDEX}`
|
|
: `--require ${NO_AUTO_INDEX}`,
|
|
},
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
});
|
|
const answers: Array<[string, string] | null> = [
|
|
['Enter user email: ', email],
|
|
['Enter new password: ', NEW_PASSWORD],
|
|
['Confirm new password: ', NEW_PASSWORD],
|
|
];
|
|
let stdout = '';
|
|
let confirmedAt: number | undefined;
|
|
let reportedAt: number | undefined;
|
|
child.stdout?.on('data', (chunk: Buffer) => {
|
|
stdout += chunk.toString();
|
|
answers.forEach((answer, index) => {
|
|
if (answer !== null && stdout.includes(answer[0])) {
|
|
child.stdin?.write(`${answer[1]}\n`);
|
|
answers[index] = null;
|
|
confirmedAt = Date.now();
|
|
}
|
|
});
|
|
if (reportedAt === undefined && stdout.includes('Password successfully reset!')) {
|
|
reportedAt = Date.now();
|
|
}
|
|
});
|
|
let stderr = '';
|
|
child.stderr?.on('data', (chunk: Buffer) => (stderr += chunk.toString()));
|
|
return new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
child.kill('SIGKILL');
|
|
reject(new Error(`reset CLI timed out; stdout: ${stdout.slice(-400)}`));
|
|
}, 60_000);
|
|
child.on('error', (error) => {
|
|
clearTimeout(timer);
|
|
reject(error);
|
|
});
|
|
child.on('close', (code) => {
|
|
clearTimeout(timer);
|
|
child.stdin?.end();
|
|
const reportDelayMs =
|
|
confirmedAt !== undefined && reportedAt !== undefined
|
|
? reportedAt - confirmedAt
|
|
: undefined;
|
|
resolve({ code, stdout, stderr, reportDelayMs });
|
|
});
|
|
});
|
|
}
|
|
|
|
test.describe('CLI password reset', () => {
|
|
test.skip(process.env.E2E_STREAM_STORE !== 'redis', 'Runs in the Redis integration lane');
|
|
for (const [source, scenario] of [
|
|
['environment', '@scenario:cli-reset-revokes-old-tokens'],
|
|
['dotenv', '@scenario:cli-reset-loads-cache-env'],
|
|
]) {
|
|
test(`evicts cached credentials with ${source} configuration ${scenario}`, async ({
|
|
playwright,
|
|
baseURL,
|
|
}) => {
|
|
test.setTimeout(90_000);
|
|
// The harness trusts one proxy; isolate each scenario's login rate-limit budget.
|
|
const request = await playwright.request.newContext({
|
|
baseURL,
|
|
extraHTTPHeaders: {
|
|
'X-Forwarded-For': `127.${randomInt(1, 255)}.${randomInt(1, 255)}.${randomInt(1, 255)}`,
|
|
},
|
|
});
|
|
const email = `cli-reset-${randomUUID().slice(0, 8)}@example.com`;
|
|
const expiresAt = source === 'dotenv' ? new Date(Date.now() + 604800_000) : undefined;
|
|
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lc-reset-'));
|
|
const redisUri = process.env.REDIS_URI ?? 'redis://127.0.0.1:6379';
|
|
const prefix = `cli-reset-${randomUUID()}`;
|
|
const adapter = new KeyvRedis(redisUri, { throwOnErrors: true, connectionTimeout: 5000 });
|
|
// Match standardCache's namespace layering without initializing app singletons in this worker.
|
|
const cache = new Keyv(adapter, { namespace: CacheKeys.AUTH_USER_DOC });
|
|
adapter.namespace = prefix;
|
|
adapter.keyPrefixSeparator = '::';
|
|
const keys: string[] = [];
|
|
try {
|
|
const register = await request.post('/api/auth/register', {
|
|
data: { email, name: 'CLI Reset', password: PASSWORD, confirm_password: PASSWORD },
|
|
});
|
|
expect(register.ok()).toBeTruthy();
|
|
const login = await request.post('/api/auth/login', {
|
|
data: { email, password: PASSWORD },
|
|
});
|
|
expect(login.ok()).toBeTruthy();
|
|
const { token, user } = (await login.json()) as { token: string; user: { _id: string } };
|
|
const authorized = await request.get('/api/user', {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(authorized.ok()).toBeTruthy();
|
|
await seedPasskey(email, randomUUID(), 'Reset regression');
|
|
await withMongo(async (db) => {
|
|
if (expiresAt) {
|
|
await db
|
|
.collection('users')
|
|
.updateOne({ email }, { $set: { expiresAt, emailVerified: false } });
|
|
}
|
|
const resetUser = await db.collection('users').findOne({ email });
|
|
expect(await db.collection('passkeys').countDocuments({ user: resetUser!._id })).toBe(1);
|
|
expect(
|
|
await db.collection('sessions').countDocuments({ user: resetUser!._id }),
|
|
).toBeGreaterThan(0);
|
|
});
|
|
const indexKey = `${AUTH_USER_DOC_BY_ID_PREFIX}:${user._id}`;
|
|
const documentKeys = ['first', 'second'].map((suffix) => `auth-user-doc:${suffix}`);
|
|
const controlKey = 'auth-user-doc:another-user';
|
|
keys.push(indexKey, ...documentKeys, controlKey);
|
|
// Keep fixtures alive beyond the test deadline so expiry cannot masquerade as eviction.
|
|
await cache.set(indexKey, documentKeys, 120_000);
|
|
for (const key of [...documentKeys, controlKey]) {
|
|
await cache.set(key, { credentialsChangedAt: null }, 120_000);
|
|
expect(await cache.get(key)).toEqual({ credentialsChangedAt: null });
|
|
}
|
|
expect(await cache.get(indexKey)).toEqual(documentKeys);
|
|
|
|
const config = {
|
|
USE_REDIS: 'true',
|
|
USE_REDIS_CLUSTER: 'false',
|
|
REDIS_URI: redisUri,
|
|
REDIS_KEY_PREFIX: prefix,
|
|
REDIS_KEY_PREFIX_VAR: '',
|
|
AUTH_USER_CACHE_MODE: 'on',
|
|
FORCED_IN_MEMORY_CACHE_NAMESPACES: '',
|
|
};
|
|
const env = { ...process.env };
|
|
for (const key of Object.keys(config)) {
|
|
delete env[key];
|
|
}
|
|
if (source === 'dotenv') {
|
|
fs.writeFileSync(
|
|
path.join(cwd, '.env'),
|
|
Object.entries(config)
|
|
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
.join('\n'),
|
|
{ mode: 0o600 },
|
|
);
|
|
} else {
|
|
Object.assign(env, config);
|
|
}
|
|
|
|
const cli = await runResetCli(email, cwd, env);
|
|
expect(cli.code, cli.stderr.slice(-400)).toBe(0);
|
|
expect(cli.stdout, `reset CLI stderr: ${cli.stderr.slice(-400)}`).toContain(
|
|
'Password successfully reset!',
|
|
);
|
|
expect(await cache.get(indexKey)).toBeUndefined();
|
|
for (const key of documentKeys) {
|
|
expect(await cache.get(key), `stale auth cache entry: ${key}`).toBeUndefined();
|
|
}
|
|
expect(await cache.get(controlKey)).toEqual({ credentialsChangedAt: null });
|
|
await withMongo(async (db) => {
|
|
const resetUser = await db.collection('users').findOne({ email });
|
|
expect(resetUser?.credentialsChangedAt).toBeTruthy();
|
|
expect(resetUser?.expiresAt).toEqual(expiresAt);
|
|
if (expiresAt) {
|
|
expect(resetUser?.emailVerified).toBe(false);
|
|
}
|
|
expect(await db.collection('passkeys').countDocuments({ user: resetUser!._id })).toBe(0);
|
|
expect(await db.collection('sessions').countDocuments({ user: resetUser!._id })).toBe(0);
|
|
});
|
|
|
|
const rejected = await request.get('/api/user', {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(rejected.status()).toBe(401);
|
|
const oldLogin = await request.post('/api/auth/login', {
|
|
data: { email, password: PASSWORD },
|
|
});
|
|
expect(oldLogin.status()).toBe(404);
|
|
const newLogin = await request.post('/api/auth/login', {
|
|
data: { email, password: NEW_PASSWORD },
|
|
});
|
|
if (expiresAt) {
|
|
expect(newLogin.status()).toBe(422);
|
|
expect(await newLogin.json()).toEqual({ message: 'Email not verified.' });
|
|
} else {
|
|
expect(newLogin.ok()).toBeTruthy();
|
|
}
|
|
} finally {
|
|
try {
|
|
await Promise.all(keys.map((key) => cache.delete(key)));
|
|
} finally {
|
|
await cache.disconnect();
|
|
await request.dispose();
|
|
fs.rmSync(cwd, { recursive: true, force: true });
|
|
await deleteUserByEmail(email);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
test('hides pre-reset documents the eviction could not name @scenario:cli-reset-fences-stale-cache-writes', async ({
|
|
playwright,
|
|
baseURL,
|
|
}) => {
|
|
test.setTimeout(90_000);
|
|
const request = await playwright.request.newContext({
|
|
baseURL,
|
|
extraHTTPHeaders: {
|
|
'X-Forwarded-For': `127.${randomInt(1, 255)}.${randomInt(1, 255)}.${randomInt(1, 255)}`,
|
|
},
|
|
});
|
|
const email = `cli-fence-${randomUUID().slice(0, 8)}@example.com`;
|
|
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lc-reset-'));
|
|
const redisUri = process.env.REDIS_URI ?? 'redis://127.0.0.1:6379';
|
|
const prefix = `cli-fence-${randomUUID()}`;
|
|
const adapter = new KeyvRedis(redisUri, { throwOnErrors: true, connectionTimeout: 5000 });
|
|
const cache = new Keyv(adapter, { namespace: CacheKeys.AUTH_USER_DOC });
|
|
adapter.namespace = prefix;
|
|
adapter.keyPrefixSeparator = '::';
|
|
const keys: string[] = [];
|
|
try {
|
|
const register = await request.post('/api/auth/register', {
|
|
data: { email, name: 'CLI Fence', password: PASSWORD, confirm_password: PASSWORD },
|
|
});
|
|
expect(register.ok()).toBeTruthy();
|
|
const login = await request.post('/api/auth/login', { data: { email, password: PASSWORD } });
|
|
expect(login.ok()).toBeTruthy();
|
|
const { user } = (await login.json()) as { user: { _id: string } };
|
|
const otherUserId = randomUUID();
|
|
const indexKey = `${AUTH_USER_DOC_BY_ID_PREFIX}:${user._id}`;
|
|
const fenceKey = `${AUTH_USER_DOC_EVICTED_PREFIX}:${user._id}`;
|
|
/** Indexed, so the eviction deletes it; and one a concurrent index write dropped. */
|
|
const indexedKey = 'auth-user-doc:indexed';
|
|
const unindexedKey = 'auth-user-doc:unindexed';
|
|
const stale = { version: 2, cachedAt: Date.now(), user: { _id: user._id, id: user._id } };
|
|
keys.push(indexKey, fenceKey, indexedKey, unindexedKey);
|
|
await cache.set(indexKey, [indexedKey], 120_000);
|
|
await cache.set(indexedKey, stale, 120_000);
|
|
await cache.set(unindexedKey, stale, 120_000);
|
|
|
|
const cli = await runResetCli(email, cwd, {
|
|
...process.env,
|
|
USE_REDIS: 'true',
|
|
USE_REDIS_CLUSTER: 'false',
|
|
REDIS_URI: redisUri,
|
|
REDIS_KEY_PREFIX: prefix,
|
|
REDIS_KEY_PREFIX_VAR: '',
|
|
AUTH_USER_CACHE_MODE: 'on',
|
|
FORCED_IN_MEMORY_CACHE_NAMESPACES: '',
|
|
});
|
|
expect(cli.code, cli.stderr.slice(-400)).toBe(0);
|
|
expect(cli.stdout).toContain('Password successfully reset!');
|
|
/** The fence proves the eviction, so the CLI no longer waits out the cache TTL. */
|
|
expect(cli.reportDelayMs).toBeLessThan(AUTH_USER_DOC_CACHE_TTL_MS);
|
|
|
|
/** A document written after the eviction by a request that read the user before it. */
|
|
const lateKey = 'auth-user-doc:late';
|
|
keys.push(lateKey);
|
|
await cache.set(lateKey, stale, 120_000);
|
|
|
|
expect(await cache.get(indexedKey)).toBeUndefined();
|
|
expect(await cache.get(unindexedKey)).toEqual(stale);
|
|
expect(await isAuthUserDocEvictionFenced(cache, user._id)).toBe(true);
|
|
expect(await isAuthUserDocEvictionFenced(cache, otherUserId)).toBe(false);
|
|
const client = await adapter.getClient();
|
|
const fenceTtl = await client.pTTL(`${prefix}::${CacheKeys.AUTH_USER_DOC}:${fenceKey}`);
|
|
/** Still standing once a document cached before the reset has expired. */
|
|
expect(fenceTtl).toBeGreaterThan(AUTH_USER_DOC_CACHE_TTL_MS);
|
|
expect(fenceTtl).toBeLessThanOrEqual(AUTH_USER_DOC_EVICTION_FENCE_TTL_MS);
|
|
} finally {
|
|
try {
|
|
await Promise.all(keys.map((key) => cache.delete(key)));
|
|
} finally {
|
|
await cache.disconnect();
|
|
await request.dispose();
|
|
fs.rmSync(cwd, { recursive: true, force: true });
|
|
await deleteUserByEmail(email);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('reports the reset only after unevictable cached credentials expire @scenario:cli-reset-outlasts-failed-cache-eviction', async ({
|
|
playwright,
|
|
baseURL,
|
|
}) => {
|
|
test.setTimeout(90_000);
|
|
const request = await playwright.request.newContext({
|
|
baseURL,
|
|
extraHTTPHeaders: {
|
|
'X-Forwarded-For': `127.${randomInt(1, 255)}.${randomInt(1, 255)}.${randomInt(1, 255)}`,
|
|
},
|
|
});
|
|
const email = `cli-evict-${randomUUID().slice(0, 8)}@example.com`;
|
|
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lc-reset-'));
|
|
const redisUri = process.env.REDIS_URI ?? 'redis://127.0.0.1:6379';
|
|
const prefix = `cli-evict-${randomUUID()}`;
|
|
const adapter = new KeyvRedis(redisUri, { throwOnErrors: true, connectionTimeout: 5000 });
|
|
const cache = new Keyv(adapter, { namespace: CacheKeys.AUTH_USER_DOC });
|
|
adapter.namespace = prefix;
|
|
adapter.keyPrefixSeparator = '::';
|
|
const keys: string[] = [];
|
|
try {
|
|
const register = await request.post('/api/auth/register', {
|
|
data: { email, name: 'CLI Evict', password: PASSWORD, confirm_password: PASSWORD },
|
|
});
|
|
expect(register.ok()).toBeTruthy();
|
|
const login = await request.post('/api/auth/login', { data: { email, password: PASSWORD } });
|
|
expect(login.ok()).toBeTruthy();
|
|
const { token, user } = (await login.json()) as { token: string; user: { _id: string } };
|
|
await seedPasskey(email, randomUUID(), 'Eviction regression');
|
|
|
|
const indexKey = `${AUTH_USER_DOC_BY_ID_PREFIX}:${user._id}`;
|
|
const controlKey = 'auth-user-doc:another-user';
|
|
keys.push(indexKey, controlKey);
|
|
await cache.set(controlKey, { credentialsChangedAt: null }, 120_000);
|
|
/** A hash where the index string belongs makes the CLI's GET fail with WRONGTYPE. */
|
|
const client = await adapter.getClient();
|
|
await client.hSet(`${prefix}::${CacheKeys.AUTH_USER_DOC}:${indexKey}`, 'unreadable', '1');
|
|
await client.pExpire(`${prefix}::${CacheKeys.AUTH_USER_DOC}:${indexKey}`, 120_000);
|
|
|
|
const env = { ...process.env };
|
|
Object.assign(env, {
|
|
USE_REDIS: 'true',
|
|
USE_REDIS_CLUSTER: 'false',
|
|
REDIS_URI: redisUri,
|
|
REDIS_KEY_PREFIX: prefix,
|
|
REDIS_KEY_PREFIX_VAR: '',
|
|
AUTH_USER_CACHE_MODE: 'on',
|
|
FORCED_IN_MEMORY_CACHE_NAMESPACES: '',
|
|
});
|
|
|
|
const cli = await runResetCli(email, cwd, env);
|
|
expect(cli.code, cli.stderr.slice(-400)).toBe(0);
|
|
expect(cli.stdout).toContain('Password successfully reset!');
|
|
expect(cli.reportDelayMs).toBeGreaterThanOrEqual(AUTH_USER_DOC_MAX_AGE_MS);
|
|
expect(await cache.get(controlKey)).toEqual({ credentialsChangedAt: null });
|
|
await withMongo(async (db) => {
|
|
const resetUser = await db.collection('users').findOne({ email });
|
|
expect(resetUser?.credentialsChangedAt).toBeTruthy();
|
|
expect(await db.collection('passkeys').countDocuments({ user: resetUser!._id })).toBe(0);
|
|
expect(await db.collection('sessions').countDocuments({ user: resetUser!._id })).toBe(0);
|
|
});
|
|
const rejected = await request.get('/api/user', {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(rejected.status()).toBe(401);
|
|
const newLogin = await request.post('/api/auth/login', {
|
|
data: { email, password: NEW_PASSWORD },
|
|
});
|
|
expect(newLogin.ok()).toBeTruthy();
|
|
} finally {
|
|
try {
|
|
await Promise.all(keys.map((key) => cache.delete(key)));
|
|
} finally {
|
|
await cache.disconnect();
|
|
await request.dispose();
|
|
fs.rmSync(cwd, { recursive: true, force: true });
|
|
await deleteUserByEmail(email);
|
|
}
|
|
}
|
|
});
|
|
});
|