commit16
This commit is contained in:
@@ -148,7 +148,7 @@ await test('browser writes preserve the CSRF cookie header', async (t) => {
|
||||
const previous = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: { cookie: 'other=x; XSRF-TOKEN=qa%2Ftoken' },
|
||||
value: { cookie: 'other=x;XSRF-TOKEN=qa%2Ftoken' },
|
||||
});
|
||||
try {
|
||||
t.mock.method(globalThis, 'fetch', async (_url, options) => {
|
||||
@@ -201,3 +201,41 @@ await test('invalid JSON and network errors remain failures', async (t) => {
|
||||
});
|
||||
await assert.rejects(portalRequest('/api/v1/home'), TypeError);
|
||||
});
|
||||
|
||||
await test('malformed CSRF cookie prevents writes with a readable session error but permits reads', async (t) => {
|
||||
const previous = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: { cookie: 'XSRF-TOKEN=%broken' },
|
||||
});
|
||||
let calls = 0;
|
||||
t.mock.method(globalThis, 'fetch', async () => {
|
||||
calls++;
|
||||
return new Response('{"success":true}');
|
||||
});
|
||||
try {
|
||||
await assert.rejects(
|
||||
portalRequest('/synthetic', { method: 'POST' }),
|
||||
(error) =>
|
||||
error instanceof PortalApiError && /sessão/.test(error.message),
|
||||
);
|
||||
assert.equal(calls, 0);
|
||||
await portalRequest('/synthetic');
|
||||
assert.equal(calls, 1);
|
||||
} finally {
|
||||
if (previous) Object.defineProperty(globalThis, 'document', previous);
|
||||
else delete globalThis.document;
|
||||
}
|
||||
});
|
||||
|
||||
await test('nullable validation errors never crash field rendering', async (t) => {
|
||||
t.mock.method(
|
||||
globalThis,
|
||||
'fetch',
|
||||
async () => new Response('{"errors":null}', { status: 422 }),
|
||||
);
|
||||
await assert.rejects(portalRequest('/synthetic'), (error) => {
|
||||
assert.deepEqual(fieldErrors(error), {});
|
||||
return error instanceof PortalApiError;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user