Skip to content

test: Inline unit tests for server.rs, alert.rs, auth.rs, config.rs (0 inline tests) #297

Description

@ajianaz

What

Add inline unit tests for trapfalld/src/server.rs (1045 LOC) and related handler files that currently have zero inline tests.

Why

BMAD COO finding: TrapFall has 231 tests total, but they're concentrated in trapfall-db (81) and integration-level tests/ directories. The HTTP handler layer — server.rs (1045 LOC), alert.rs (266 LOC), auth.rs (312 LOC), config.rs (281 LOC) — has zero inline #[test] functions.

This means handler-level edge cases (malformed requests, auth edge cases, rate limiting behavior) are only caught by E2E tests, which are slower and less precise.

Changes

  1. server.rs: Unit tests for:
    • Request routing (each endpoint returns correct status for valid/invalid input)
    • Error response shapes
    • Authentication middleware (valid token, expired token, missing token, malformed token)
    • Rate limiting behavior
  2. alert.rs: Unit tests for:
    • Rule matching logic (condition evaluation)
    • Cooldown tracking
    • Webhook dispatch (mock HTTP)
  3. auth.rs: Unit tests for:
    • JWT generation and validation
    • Argon2 password hashing/verification
    • DSN validation against registered projects
  4. config.rs: Unit tests for:
    • Default values
    • Environment variable parsing
    • Invalid config handling

Testing

This IS the testing task. Success = cargo test --workspace count increases by 30-50 tests, with handler-level coverage significantly improved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions