LibreChat/e2e/specs/mock/scenarios/admin-audit-integrations.spec.ts
Marco Beretta 9adabde72e
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 Votes / vote (full suite) (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
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
🗂️ feat: Audit MCP, Code Worker, Langfuse, Skill Credential, Passkey and Audit Log Access (#17054)
* fix: Remove Group Dependents Before Deleting the Group

* feat: Audit Code Worker Pairing and Langfuse Connection Changes

* feat: Audit Skill Sync Credential Changes

* feat: Audit Passkey Enrolment and Removal

* feat: Audit Audit Log Reads and CSV Exports

* feat: Audit Audit Log Retention Purges

* feat: Audit MCP Server Create, Update and Delete

* fix: Keep Purge Result When the Purge Audit Write Fails

* test: Cover Admin Integration Audit Scenarios

* fix: Tighten Admin Integration Audit Scope and Group Cleanup Order

* fix: Run Security Fences Before Awaiting Audit Writes

* fix: Move MCP Post-Commit Audit Ordering Into the Auditor and Audit Verify Reads

* fix: Fail Closed When Recording Audit Log Access

* fix: Audit Group Deletion Before the Cascade and Restore Dependents on Failure

* fix: Restore Only Config Overrides When Group Deletion Fails

* fix: Audit Worker Pairing and Export Before the Work and Append Failures

* fix: Record Group Deletion as Pending Without Delaying Revocation

* fix: Skip Config Restore When a Concurrent Delete Removed the Group

* fix: Restore Group Config When the Existence Recheck Fails

* fix: Keep Group Config Restricted When Delete State Is Unknown

* fix: Record Worker Pairing and Revocation as Pending Until Confirmed

* fix: Deliver the Pairing Code Before the Terminal Audit Write

* test: Assert Pairing Code Delivery Precedes the Terminal Audit Write

* fix: Send Revocation and Group Deletion Responses Before the Terminal Audit Write

* fix: Snapshot Group Config Before the Destructive Cascade Step

* refactor: Type the Group Config Snapshot Dependency Without Mongoose Shapes

* fix: Fence Shared MCP Users Before the Deletion Audit and Correlate Audit Attempts

* fix: Diff MCP Server Audits Against the Committed Config

* fix: Read the Committed MCP Config at Commit Time for the Audit Diff

* refactor: Start the Committed MCP Config Read Inside the Auditor

* fix: Audit Langfuse Patches When Activation Fails and Surface Failed Group Config Restores

* fix: Record Member Removals When Group Deletion Completes After a Failed Restore

* test: Serve the Committed Config on the MCP Update Audit Reread

* fix: Audit the Group Returned by the Compensating Deletion

* fix: Keep Member Removal Audits Fail-Open During Group Deletion

* fix: Retry ACL Cleanup After a Compensating Group Deletion

* fix: Mark Unavailable Audit Detail and Order Member Removals After the Pending Deletion

* fix: Guard Synchronous Committed-Config Read Failures in the MCP Auditor

* fix: Return the Persisted MCP Config and Audit Commits That Outlive Cache Invalidation

* style: Sort Imports in MCP Audit Files

* style: Sort Imports After Restack

* fix: Audit MCP Commits That Outlive Any Post-Write Step and Pend Audit Exports Until Complete

* test: Provide the Fail-Closed Setting in the Code Route Mock

* fix: Refresh MCP Read Caches When a Repository Step Fails After the Write

* fix: Finish Audit Exports on Response Completion and Keep Error Details Out of Messages and Logs

* fix: Watch Response Completion Before the Truncation Footer Write

* fix: Skip Audit for No-op MCP Deletes and Close Remaining Post-Failure Audit Gaps

* fix: Keep Causes Out of Structured Logs and Treat a Lost Compensating Delete as Not Found

* fix: Mark Failed MCP Post-Commit Steps and Null Langfuse Activation in Audits
2026-10-15 00:30:26 +02:00

114 lines
5.2 KiB
TypeScript

import { resolve } from 'node:path';
import { expect, test } from '@playwright/test';
import { run, repoRoot, inOneProject } from './lint.helpers';
/**
* Admin integration changes (MCP servers, Langfuse, audit log reads and
* exports, group deletion) leave an audit trail that never carries secrets or
* searched-for text, and a group is only removed once its permissions are.
* Each probe drives the real handlers from the built @librechat/api with an
* in-memory recorder and prints the result as JSON.
*/
const PREAMBLE = `
const api = require('@librechat/api');
const { Types } = require('mongoose');
const out = (value) => { process.stdout.write('RESULT' + JSON.stringify(value)); process.exit(0); };
const makeRes = () => {
const res = { statusCode: 200, body: undefined, headers: {}, chunks: [] };
res.status = (code) => { res.statusCode = code; return res; };
res.json = (body) => { res.body = body; return res; };
res.setHeader = (key, value) => { res.headers[key] = value; };
res.write = (chunk) => { res.chunks.push(String(chunk)); return true; };
res.end = () => res;
res.once = () => res;
res.on = () => res;
return res;
};
const user = { _id: new Types.ObjectId(), name: 'Admin', email: 'admin@example.com' };
`;
function probe(body: string): unknown {
const result = run(
'node',
[
'-e',
`${PREAMBLE}\n(async () => {\n${body}\n})().catch((e) => { console.error(e); process.exit(1); });`,
],
{
cwd: resolve(repoRoot, 'api'),
},
);
expect(result.status, result.output).toBe(0);
return JSON.parse(result.stdout.slice(result.stdout.indexOf('RESULT') + 'RESULT'.length));
}
test.describe('admin integration auditing', () => {
test.beforeEach(() => inOneProject());
test('an MCP server update is audited by field name without the values @scenario:mcp-server-update-audit-lists-field-names-only', () => {
const entries = probe(`
const entries = [];
const audit = api.createMCPServerAuditor({ recordAuditEntry: async (input) => { entries.push(input); } });
await audit({ user }, {
action: 'mcp_server.updated',
serverName: 'srv',
previous: { title: 'Docs', url: 'https://old.example.com', headers: { Authorization: 'Bearer old-secret' } },
next: { title: 'Docs', url: 'https://old.example.com', headers: { Authorization: 'Bearer new-secret' } },
});
out(entries);
`) as Array<{ action: string; target: { id: string }; metadata: { fields?: string } }>;
expect(entries).toHaveLength(1);
expect(entries[0].action).toBe('mcp_server.updated');
expect(entries[0].target.id).toBe('srv');
expect(entries[0].metadata.fields).toBe('headers');
expect(JSON.stringify(entries)).not.toContain('secret');
});
test('an MCP server deletion is audited as a warning @scenario:mcp-server-delete-audit-is-a-warning', () => {
const entries = probe(`
const entries = [];
const audit = api.createMCPServerAuditor({ recordAuditEntry: async (input) => { entries.push(input); } });
await audit({ user }, { action: 'mcp_server.deleted', serverName: 'gone', previous: { title: 'Gone' } });
out(entries);
`) as Array<{ action: string; severity: string }>;
expect(entries[0].action).toBe('mcp_server.deleted');
expect(entries[0].severity).toBe('warning');
});
test('an audit write failure does not turn a deleted MCP server into an error @scenario:audit-write-failure-keeps-the-completed-change', () => {
const result = probe(`
const audit = api.createMCPServerAuditor({ recordAuditEntry: async () => { throw new Error('db down'); } });
let threw = false;
try {
await audit({ user }, { action: 'mcp_server.created', serverName: 'srv', next: { title: 'Docs' } });
} catch { threw = true; }
out({ threw });
`) as { threw: boolean };
expect(result.threw).toBe(false);
});
test('a group whose cleanup fails is kept with its config restored and reports GROUP_CLEANUP_FAILED @scenario:group-delete-keeps-the-group-when-cleanup-fails', () => {
const result = probe(`
const id = new Types.ObjectId().toString();
let deleted = false;
const restored = [];
const noop = async () => undefined;
const handlers = api.createAdminGroupsHandlers({
listGroups: noop, countGroups: noop, createGroup: noop, updateGroupById: noop,
findGroupById: async () => ({ _id: new Types.ObjectId(id), name: 'G', memberIds: [] }),
deleteGroup: async () => { deleted = true; return { _id: id }; },
restoreConfig: async () => { restored.push('config'); return true; },
deleteConfig: async () => ({ principalType: 'group', principalId: id, overrides: {} }),
deleteAclEntries: async () => { throw new Error('acl store down'); },
});
const res = makeRes();
await handlers.deleteGroup({ params: { id }, query: {}, body: {}, user }, res);
out({ status: res.statusCode, code: res.body && res.body.code, deleted, restored });
`) as { status: number; code?: string; deleted: boolean; restored: string[] };
expect(result.status).toBe(500);
expect(result.code).toBe('GROUP_CLEANUP_FAILED');
expect(result.deleted).toBe(false);
expect(result.restored).toEqual(['config']);
});
});