Files
token-circles/worker/test/import-file-sheet.test.ts
KomediruzeckiandGitHub 820c8f68be fix(auth): confirming an address clears what was set up before it, and email links finish after sign-in (#610)
- Google sign-in, an emailed sign-in code and a reset link confirm an account's address. On an
  account whose address was never confirmed, each first clears what was set up on it (sessions,
  password, passkeys, two-factor, API tokens, unused links) in the same D1 batch, and the app says
  once what went.
- A new session or credential is written only while the account's token_version is still the one
  its check read.
- Confirm and change-of-address links take effect only with their own account's session. Opened
  elsewhere, they finish after signing in there. A browser that starts local-first opens the
  sign-in for them, and the reset page works there too.
- Google sign-in keeps and matches addresses in lower case. A reset link is refused once it has
  expired. An expired API token stops counting against the plan's limit. Deleting an account
  deletes its sessions.
2026-10-09 17:14:15 +02:00

50 lines
1.9 KiB
TypeScript

import { env, SELF } from 'cloudflare:test';
import { beforeEach, describe, expect, it } from 'vitest';
import { sessionCookie } from './helpers/session';
// POST /api/import/file-sheet is retired. The old Import page uploaded a workbook, got a fileId
// back, and asked for one of its sheets by that id; the workbook stayed in the server's memory,
// which a stateless Worker does not have. The page now uploads the file again with the sheet's
// name, and this route answers 410 Gone, so a page cached from before learns why instead of
// meeting a 404.
let cookie = '';
function fileSheet(session: string | null) {
return SELF.fetch('https://example.com/api/import/file-sheet', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(session === null ? {} : { Cookie: session }),
},
body: JSON.stringify({ fileId: 'upload-1', sheetName: 'March' }),
});
}
beforeEach(async () => {
for (const table of ['profiles', 'users']) {
await env.DB.prepare(`DELETE FROM ${table}`).run();
}
await env.DB.batch([
env.DB.prepare(
"INSERT INTO users (id, email, auth_provider, token_version, plan) VALUES (97, 'sheets@example.com', 'password', 1, 'basic')"
),
env.DB.prepare("INSERT INTO profiles (id, user_id, name) VALUES (970, 97, 'Main')"),
]);
cookie = (await sessionCookie(97, 'password', env)).split(';')[0];
});
describe('POST /api/import/file-sheet', () => {
it('answers 410 Gone, and says to upload the file again with the sheet named', async () => {
const res = await fileSheet(cookie);
expect(res.status).toBe(410);
expect(await res.json()).toEqual({
error: 'Re-upload via /api/import/upload with a sheetName field (stateless Worker flow).',
});
});
it('asks for a session first, like every import route', async () => {
expect((await fileSheet(null)).status).toBe(401);
});
});