pdf-quiz-generator/backend/tests
Daniel 25a9a8aca4 feat: sign in with a code sent by email
A password is a thing to remember and a thing to lose. Somebody who can read
their own mail can now sign in without one: ask, receive six characters, type
them into the page that is already open.

A code rather than a link, and the difference is not cosmetic. The token in a
link was 256 bits, unguessable however long it lived, so its length, its expiry
and its rate limit were three independent decisions. Six characters is 2^30,
and the three stop being independent — so they are argued together:

  * six characters of the invite alphabet, imported rather than copied, because
    there should be one answer to which characters a person may be asked to
    retype and that one already drops O/0 and I/1;
  * a code answers five guesses and is then retired, not slowed — whoever is
    typing has lost the mail or does not own it, and both are one click from a
    new one;
  * one code live per person, since several would mean one guess tested against
    all of them;
  * ten verify attempts per address per fifteen minutes, so nobody buys five
    fresh guesses at a time by asking again.

Tens of guesses an hour against a billion, and the victim gets a mail for every
code burned. Eight characters would buy a thousandfold against an attack the
guess budget has already ended, and cost every person two more characters.

The attempt count lives in the row, not the cache. The Redis limiter fails open
when Redis is down, which is right for what it usually guards and wrong for the
only thing standing between a patient stranger and six characters.

Verifying is scoped to the address. A short code looked up on its own would be
tried against every code live on the site at once — the short code's one real
weakness, closed by knowing whose code it should be before comparing.

Fifteen minutes, because a first mail between strangers is routinely greylisted
five to ten and a code that expires before it arrives is not a sign-in method.
Shortening it buys nothing: one code is live and it answers five guesses
however long it sits there.

Nothing distinguishes an address with an account from one without — same
message, same status, same duration, and both rate limits counted before the
account is looked up, so a 429 cannot become the tell. Redis keys are
fingerprints, and the table holds a fingerprint rather than the code.

SSO stays first where it is configured, and a password is still one click away
for anybody who has one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TqXevQJhxFrM7jJg82cgZN
2026-09-12 17:29:28 +02:00
..
__init__.py
test_access.py feat: access as one tree — branches, libraries, and an honest "everything" 2026-09-11 12:53:56 +02:00
test_ai_mode.py fix: WebP figures, the openai SDK removed, and a voice a site can add to 2026-09-12 17:13:05 +02:00
test_ai_mode_matching.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_ai_practice.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_article_ai.py fix: WebP figures, the openai SDK removed, and a voice a site can add to 2026-09-12 17:13:05 +02:00
test_article_search_index.py feat: three answers, chosen by a number rather than by the model 2026-09-12 16:15:05 +02:00
test_articles_cards.py feat: link a question to its reading from either end, and a player that reads like a Qbank 2026-09-12 15:17:04 +02:00
test_articles_migration.py
test_bank_cleanup.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_blueprint_plans.py feat: study plans built to the board's content outline 2026-09-11 21:40:17 +02:00
test_captcha.py feat: Cap replaces hCaptcha, self-hosted beside the app 2026-09-12 06:14:14 +02:00
test_category_grants.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_category_migration.py feat: retire the tags, and stop settings from hiding from the page that 2026-09-12 05:06:58 +02:00
test_collections.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_draft_questions.py fix: the other registration form, our own transcriber first, and a rail 2026-09-12 04:41:27 +02:00
test_exam_admin.py feat: exams are a group you can build, with the board's own blueprint 2026-09-11 20:27:48 +02:00
test_exam_blueprint.py feat: adaptive weighs the paper as well as the learner, and Session 2026-09-12 05:54:09 +02:00
test_exam_scoped_tags.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_exams.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_feedback.py feat: feedback replaces comments; Qbank is a landing page; one question page 2026-09-11 18:50:57 +02:00
test_global_search.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_hybrid_search.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_invites_and_flags.py feat: the tutor is an administrator's to allow, and a handbook explains the rest 2026-09-11 21:13:38 +02:00
test_login_codes.py feat: sign in with a code sent by email 2026-09-12 17:29:28 +02:00
test_login_without_captcha.py feat: Cap replaces hCaptcha, self-hosted beside the app 2026-09-12 06:14:14 +02:00
test_media_library.py feat: real organ systems, symptoms grouped by system, and admin taxonomy CRUD 2026-09-10 10:44:39 +02:00
test_multi_category.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_option_explanations.py
test_prepared_session.py feat: a session prepared for you, and a model that can see when the one on the job cannot 2026-09-12 15:46:04 +02:00
test_question_trash.py feat: questions are soft-deleted, and the trash holds them 2026-09-11 20:12:58 +02:00
test_question_versions.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_quiz_builder.py feat: a session prepared for you, and a model that can see when the one on the job cannot 2026-09-12 15:46:04 +02:00
test_quiz_sessions.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_related_privacy.py fix: WebP figures, the openai SDK removed, and a voice a site can add to 2026-09-12 17:13:05 +02:00
test_session_lifecycle.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_share_public.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_shared_category.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_study_plan_editing.py feat: study plans you can open, work through, and edit 2026-09-10 12:10:39 +02:00
test_study_plan_sessions.py feat: study-plan blocks as modules, sessions that know their block 2026-09-11 04:31:21 +02:00
test_study_tools.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_study_tools_migration.py
test_tag_hierarchy.py refactor: remove per-question sharing 2026-09-12 08:42:51 +02:00
test_thumbnails.py feat: thumbnails for uploaded images, at two widths and no others 2026-09-12 08:49:20 +02:00
test_vision_fallback.py fix: WebP figures, the openai SDK removed, and a voice a site can add to 2026-09-12 17:13:05 +02:00