Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

W-C3: e2e for POST /admin/api/rescope-client allowedOperations:null on Postgres

garrytaned618986b01d
diff --git a/test/e2e/client-grants.test.ts b/test/e2e/client-grants.test.ts
index 4352c995bc..d2e2e859a3 100644
--- a/test/e2e/client-grants.test.ts
+++ b/test/e2e/client-grants.test.ts
@@ -104,6 +104,27 @@ suite('client capability grants — Postgres and admin HTTP', () => {
const body = await result.json() as any; expect(Object.keys(body).sort()).toEqual(['clientId', 'clientName', 'federatedRead', 'sourceId']);
});
+ test('admin allowedOperations:null clears the operation snapshot and profile; with a named profile it is refused', async () => {
+ const registration = await post('/admin/api/register-client', { name: 'ops-all-' + randomUUID(), profile: 'memory-writer', sourceId: 'default' });
+ expect(registration.status).toBe(200);
+ const created = await registration.json() as any; clients.push(created.clientId);
+ const before = await readClientGrant(engine, created.clientId);
+ expect(before.profile).toBe('memory-writer'); expect(before.allowedOperations?.length).toBeGreaterThan(0);
+ const refused = await post('/admin/api/rescope-client', { clientId: created.clientId, allowedOperations: null, profile: 'memory-writer', expectedRevision: before.revision });
+ expect(refused.status).toBe(400);
+ const unchanged = await readClientGrant(engine, created.clientId);
+ expect(unchanged.revision).toBe(before.revision); expect(unchanged.allowedOperations).toEqual(before.allowedOperations);
+ const preview = await post('/admin/api/rescope-client', { clientId: created.clientId, allowedOperations: null, expectedRevision: before.revision, dryRun: true });
+ expect(preview.status).toBe(200); expect((await readClientGrant(engine, created.clientId)).revision).toBe(before.revision);
+ const cleared = await post('/admin/api/rescope-client', { clientId: created.clientId, allowedOperations: null, expectedRevision: before.revision });
+ expect(cleared.status).toBe(200);
+ const after = await readClientGrant(engine, created.clientId);
+ expect(after.allowedOperations).toBeNull(); expect(after.profile).toBeNull(); expect(after.revision).toBe(before.revision + 1);
+ expect(after.scopes).toEqual(before.scopes);
+ const [row] = await engine.executeRaw('SELECT allowed_operations, grant_profile FROM oauth_clients WHERE client_id = $1', [created.clientId]);
+ expect(row.allowed_operations).toBeNull(); expect(row.grant_profile).toBeNull();
+ });
+
test('admin credential delivery can be recovered without another grant or secret rotation', async () => {
const name = 'delivery-admin-' + randomUUID();
const request = { name, profile: 'memory-reader', sourceId: 'default' };