T-4: M0.4b — Close sb-research.* holdout leak: 403 on dataset /export and ungranted project GETs

This commit is contained in:
Studio 2026-11-27 01:16:52 -05:00
parent 13eb8352f3
commit 420e77f837
17 changed files with 788 additions and 1123 deletions

View file

@ -282,14 +282,16 @@ describe('validated canonical dataset export', () => {
).rejects.toThrow('cancelled after query');
});
test('read, admin, service, browser and research credentials export; anonymous and revoked credentials do not', async () => {
test('read, admin, service and browser credentials export; research, anonymous and revoked credentials do not', async () => {
const f = fixture();
expect((await f.request(baseline.manifest.hash, {})).status).toBe(401);
expect(f.query).not.toHaveBeenCalled();
for (const token of [tokens.read, tokens.admin, tokens.service, tokens.research]) {
expect(
(await f.request(baseline.manifest.hash, { Authorization: `Bearer ${token}` })).status
).toBe(200);
for (const token of [tokens.read, tokens.admin, tokens.service]) {
const response = await f.request(baseline.manifest.hash, {
Authorization: `Bearer ${token}`,
});
expect(response.status).toBe(200);
expect(await response.json()).toEqual(baseline);
}
for (const token of [tokens.read, tokens.admin]) {
const login = await f.app.request('/api/auth/session', {
@ -300,19 +302,31 @@ describe('validated canonical dataset export', () => {
expect(login.status).toBe(200);
const cookie = login.headers.get('Set-Cookie')?.split(';')[0];
expect(cookie).toBeDefined();
expect((await f.request(baseline.manifest.hash, { Cookie: cookie! })).status).toBe(200);
const response = await f.request(baseline.manifest.hash, { Cookie: cookie! });
expect(response.status).toBe(200);
expect(await response.json()).toEqual(baseline);
}
const before = f.payloadRead.mock.calls.length;
const beforeResearch = f.payloadRead.mock.calls.length;
for (const method of ['GET', 'HEAD']) {
const forbidden = await f.app.request(path(baseline.manifest.hash), {
method,
headers: { Authorization: `Bearer ${tokens.research}` },
});
expect(forbidden.status).toBe(403);
expect(forbidden.headers.get('Cache-Control')).toBe('no-store');
expect(forbidden.headers.get('Content-Disposition')).toBeNull();
}
expect(f.payloadRead).toHaveBeenCalledTimes(beforeResearch);
f.revokeResearch();
const denied = await f.request(baseline.manifest.hash, {
Authorization: `Bearer ${tokens.research}`,
});
expect(denied.status).toBe(401);
expect(denied.headers.get('Content-Disposition')).toBeNull();
expect(f.payloadRead).toHaveBeenCalledTimes(before);
expect(f.payloadRead).toHaveBeenCalledTimes(beforeResearch);
expect(
f.query.mock.calls.filter(call => call[0].includes('FROM research_agents'))
).toHaveLength(2);
).toHaveLength(3);
expect(f.sourceRead).not.toHaveBeenCalled();
});
});