#1964·SurfSense

License routes, rate limits and the Keygen client have no tests

Author: MODSetterCreated Sep 28, 2026Updated Oct 1, 2026
Labelshelp wantedtestbackendhosted

The gap

docs/architecture/license/portal.md lists this under Known gaps:

No test covers the license routes or their rate limits, and no contract test runs the Keygen client against a real Keygen.

Why it matters

The licence portal is the business the company is pivoting to, and the three routes that sell, deliver and re-deliver the product have no tests at all. The suites that once covered them were deleted on 15 Sep 2026 in commit 7f1195c76 — "drop the suites that stood on fakes" — and nothing replaced them. What is untested is not edge cases: it is /license/resend answering identically whether it found three licences or none, /license/trial refusing a second claim for the same folded address, and both buckets of the rate limiter that stand between a public unauthenticated endpoint and the mail bill.

The Keygen client is worse off. Every test of it asserts the shape of a payload against a fake, and Keygen camelCases metadata keys in filter queries while returning an empty list rather than an error for a misspelled one. A wrong spelling therefore reads as "this customer has no licence" — a silent, total failure that no fake can catch, because the fake is written to the same assumption as the code.

Where

What done looks like

  • Each route's documented answer is asserted, including the ones that are deliberately uninformative: resend's single 200 for any outcome, and its 503 when mail is off, checked before any lookup.
  • Trial's outcomes are all distinguishable from each other — 404 when disabled, 400 for a disposable domain, 409 for an address already claimed, 503 for Keygen and for a mail outage, and never the file in the response body.
  • Both rate-limit buckets are proved to bite, and a limit of zero is proved to turn its bucket off.
  • The Keygen client runs at least once against a real Keygen, opted into by an environment variable and skipped without it, so that CI without one stays green and a contributor with one gets the real answer. Metadata filter spellings are the first thing it should prove.
  • Delete the Known gaps line from docs/architecture/license/portal.md, and update the "Tests" section, which currently records what is missing.

What not to change

Do not make the code easier to test by making resend informative. Its single answer is the whole reason it is safe to expose without a login, and a test that distinguishes "found" from "not found" through the response is asserting a vulnerability. Assert it from the mailer side instead.

How to verify

Write each test failing first, and hit public seams rather than internals — the routes are the seam here, not the functions behind them. Unit tests that need no service stay under tests/unit/license/ beside test_issue.py; anything needing a live Keygen belongs in tests/integration/ behind its opt-in variable.

bash
cd surfsense_backend
uv run pytest -m unit
uv run pytest -m integration
uv run ruff check .

Before you start

Read CONTRIBUTING.md, the license portal doc and ADR 0024. The portal doc's "Keygen" section lists the three things that break a CE instance's first boot; read it before spending an evening on one. This code is under surfsense_backend/app/license/, not app/proprietary/, so it is open to contributors. Never commit a Keygen token, account id or policy id — take them from the environment and keep them out of fixtures and logs. Open your PR against dev, not main. Comment here to claim this.