Skip to content

tests: NIP-42 and NIP-98 have no unit tests, nostreamd has none, and LMDB recovery is untested #1215

Todo

Description

@chappie-daemon

Measured on rewrite/main at ff045445. The security-relevant paths with no test at all:

  • crates/nostream-core/src/nip42.rs is 377 lines with zero test attributes and no mod tests. NIP-42 is the authentication path; the relay's handler tests cover the seven outcomes over the wire, but the module's own parsing and validation has no unit test, so a change that keeps the wire tests green while breaking an edge case in the module has nothing to fail.
  • crates/nostream-core/src/nip98.rs is 30 lines and has no direct test anywhere. verify is reached only through callers that exercise other behaviour.
  • crates/nostreamd/src has zero test attributes. The composition root — the place this repository has already been wrong once about which backend is wired — is untested by construction.
  • LMDB has no corruption, torn-write or crash-recovery test, and its rollback path is untested, so the failure mode that matters most for an embedded store is asserted only by the code's shape.
  • NIP-50 ranking has no dedicated test on either backend; the store's search tests assert membership and order on recorded rows, not the ranking itself against a fresh index.

Acceptance:

  • nip42.rs and nip98.rs each carry unit tests with inversions: a signature that verifies under one tag and not another, a replay outside the window, a NIP-98 token with the wrong u or a stale created_at.
  • nostreamd has a test that asserts the wired backend, so the "resolves the name then discards it" defect cannot recur silently.
  • An LMDB test opens a store, kills the process mid-write, and asserts the reopened environment is consistent — or documents why the guarantee comes from LMDB's own design and pins that with a test of the recovery path the code actually has.
  • NIP-50 ranking is asserted against a freshly built index on both backends, by rank position rather than membership.

Activity

  1. added
    rewrite
    rust
    on Nov 21, 2026
  2. Ansh-699 commented on Nov 29, 2026

    @Ansh-699

    Hi @cameri, I'd like to work on this one. While reading rewrite/main (1514e7f) I noticed nip98::verify is still the Phase 1 stub: it returns NotImplemented and nothing calls it, so it needs the port from src/utils/nip98.ts before there's anything to test. The nostreamd item also looks covered already by tests/store_wiring.rs from the #1206 fix.

    I'd split the rest into two PRs. First, unit tests for nip42::authenticate, one per AuthFailure variant with inversions: a signature that verifies under one tag but not another, created_at just inside and just outside the 600 s window, relay host matching. The NIP-98 port goes in the same PR, tested with a wrong u, wrong method, stale created_at and the payload hash.

    Second, LMDB: kill a writer process mid-write and check the reopened store, test the transaction.abort() rollback path, and assert NIP-50 ranking by position on a fresh index for both backends.

    Should the NIP-98 port go in here, or is it still planned as job 005?

  3. cameri commented on Nov 29, 2026

    @cameri
    Owner

    @Ansh-699 assigned to you

  4. chappie-daemon commented on Nov 29, 2026

    @chappie-daemon
    CollaboratorAuthor

    A few facts that will save you a wasted push, since the issue is the map rather than the route:

    • Branch from rewrite/main, not main — the measurements in this issue are against rewrite/main (ff045445), and main is the TypeScript tree. A PR opened against main will not see these files.
    • Smallest first, and separate PRs are better than one large one. nip98.rs is 30 lines with a single verify; take it, then nip42.rs parsing/validation, then the nostreamd wired-backend assertion, then NIP-50 ranking.
    • The LMDB box is deliberately open. "A test that kills the process mid-write" may not be reachable in CI; the acceptance line allows a documented argument plus a test of the recovery path the code actually has. If you conclude that, say so and pin the part that is real — that is a pass, not a dodge.
    • CI wants a changeset. Changeset Required runs pnpm exec changeset status --since origin/rewrite/main; a short .changeset/<name>.md satisfies it (.changeset/prometheus-metrics.md is a good shape to copy).
    • If any box turns out to need a design decision rather than a test, write that here instead of guessing — a wrong test is worse than a missing one.

    No need to take all five. Land one well and claim the next.

  5. Ansh-699 commented on Dec 2, 2026

    @Ansh-699

    First piece is up: Ansh-699#2 (one commit, d9d1966, on rewrite/main ead3997). Could you cherry-pick it?

    nip98::verify was still the Phase 1 stub, so this ports verifyNip98Auth from src/utils/nip98.ts with the same check order and reasons (new CoreError::InvalidNip98), plus 24 unit tests including a wrong u, a wrong method, a stale created_at and the payload hash. The new arguments come from the TS input: an optional body, the payload policy and now. The header length limit stays at the 2048 default since no caller passes it. Replay stays with the admin job (ADR 0010), and the admin gate is untouched (ADR 0014 D6). Once this lands I'll take the nip42.rs tests.

  6. chappie-daemon commented on Dec 3, 2026

    @chappie-daemon
    CollaboratorAuthor

    Ansh-699's nip98::verify is in as #1355 (cherry-picked -x from their fork commit d9d1966): fmt, clippy and cargo test -p nostream-core green, 24 new unit tests. Screening found nothing: no workflow, dependency or install-time change, no hidden characters. The nip42.rs tests remain open.

  7. cameri commented on Dec 3, 2026

    @cameri
    Owner

    Thank you @Ansh-699

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

rewriterust

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions