normogen/backend
goose bd1b7c2925 fix(backend): P1 — handler unwrap cleanup + rewrite integration tests
P1 items #6 (JWT expiry) and #7 (refresh/logout routes) were already delivered
in the P0 pass. This commit covers the two remaining P1 items:

#9 — Replace dangerous handler-level .unwrap() calls (13 sites):
* handlers/users.rs: 5x ObjectId::parse_str(&claims.sub).unwrap() in
  get_profile/update_profile/delete_account/get_settings/update_settings now
  return 401 on a malformed subject instead of panicking (matches the guard
  already used in change_password).
* handlers/auth.rs: the login user.id.ok_or_else(..).unwrap() was a latent
  panic bug — the crafted 500 response was discarded. Now returns the clean
  500 via match.
* handlers/health_stats.rs: 6x state.health_stats_repo.as_ref().unwrap() now
  return 503 SERVICE_UNAVAILABLE if the feature is unconfigured, mirroring the
  interactions.rs pattern.
* Left untouched: 14 test/boot-time unwraps and 7 infallible ones (header
  literal parsing, infallible TryFrom). The 3 borderline model-layer
  inserted_id unwraps are flagged for later.

#8 — Rewrite the broken integration tests against a real test DB:
* Split the crate into bin+lib: new src/lib.rs + src/app.rs (build_app), with
  main.rs now a thin entrypoint. Tests build the exact production router
  in-process instead of hitting a live server on a hardcoded port.
* tests/common/mod.rs: helpers that connect to Mongo, build a fresh AppState
  against a unique per-process DB (normogen_test_<uuid>), and tear it down.
  A 1s connectivity probe makes tests skip gracefully when Mongo is absent, so
  'cargo test' stays green without Mongo — CI runs them for real.
* Rewrote tests/auth_tests.rs and tests/medication_tests.rs with the ACTUAL
  API contracts (POST /register {email,username,password}; response has token
  + refresh_token, not access_token; register returns 201). Covers register,
  login (right/wrong password), auth enforcement, refresh rotation + reuse
  detection, logout, and password-change invalidating old tokens.
* Added a 'test' CI job with a mongo:7 service container running
  cargo test --all-targets.
* Synced scripts/test-ci-locally.sh: fixed the stale -D warnings (CI is
  non-strict) and the reverted 'Docker Buildx' claims; added unit + integration
  test steps with a Mongo skip note.

Verified: cargo fmt --check clean, build + clippy --all-targets clean.
Full 'cargo test': 18 unit + 9 auth + 4 medication = 31 passed, 0 failed
(integration tests skip cleanly when MongoDB is unreachable).
2026-06-27 14:26:39 -03:00
..
config Phase 2.1: Backend project initialized with Docker configuration 2026-02-14 15:30:06 -03:00
docker feat(backend): Implement Phase 2.7 Task 1 - Medication Management System 2026-03-07 14:07:52 -03:00
docs docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
scripts chore: Clean up temporary docs and start Phase 2.4 2026-02-15 16:33:36 -03:00
src fix(backend): P1 — handler unwrap cleanup + rewrite integration tests 2026-06-27 14:26:39 -03:00
tests fix(backend): P1 — handler unwrap cleanup + rewrite integration tests 2026-06-27 14:26:39 -03:00
.dockerignore Config: Change server port to 6800 and remove Cargo.lock dependency 2026-02-15 09:48:11 -03:00
.env.example fix(backend): P0 security hardening pass 2026-06-27 13:12:19 -03:00
ADHERENCE_STATS_FIX.txt docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
API-TEST-GUIDE.md feat(api): Add API testing script and quick test guide 2026-02-15 15:28:04 -03:00
API-TEST-RESULTS.md docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
API_TESTING_REPORT.md Add database initialization module and compilation fixes 2026-02-25 11:42:39 -03:00
BUILD-STATUS.md feat(backend): Complete Phase 2.5 - Access Control Implementation 2026-02-18 10:05:34 -03:00
Cargo.lock fix(backend): P1 — handler unwrap cleanup + rewrite integration tests 2026-06-27 14:26:39 -03:00
Cargo.toml fix(backend): P1 — handler unwrap cleanup + rewrite integration tests 2026-06-27 14:26:39 -03:00
clippy.toml fix(clippy): resolve all clippy warnings 2026-03-12 09:03:38 -03:00
COMPILATION-FIXES.md docs: Add compilation fixes documentation 2026-02-15 19:02:44 -03:00
comprehensive-test-8001.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
comprehensive-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
core-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
defaults.env Phase 2.1: Backend project initialized with Docker configuration 2026-02-14 15:30:06 -03:00
deploy-and-test.sh feat: implement health statistics tracking (Phase 2.7 Task 2) 2026-03-07 16:24:18 -03:00
deploy-to-solaria-improved.sh feat(backend): Implement Phase 2.7 Task 1 - Medication Management System 2026-03-07 14:07:52 -03:00
diagnose-server.sh Add DNS error logging and server diagnostic script 2026-02-24 10:57:01 -03:00
docker-compose.dev.yml fix: correct docker environment variable name and remove unnecessary runtime deps 2026-02-28 16:55:36 -03:00
docker-compose.yml docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
Dockerfile docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
Dockerfile.improved feat(backend): Implement Phase 2.7 Task 1 - Medication Management System 2026-03-07 14:07:52 -03:00
ERROR-ANALYSIS.md docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
final-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
fixed-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
health-stats-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
MEDICATION_UPDATE_FIX.txt docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
PASSWORD-RECOVERY-COMPLETE.md docs: Add password recovery completion summary 2026-02-15 18:12:31 -03:00
PASSWORD-RECOVERY-IMPLEMENTED.md feat(backend): Implement password recovery with zero-knowledge phrases 2026-02-15 18:12:10 -03:00
PASSWORD-RECOVERY-TEST-RESULTS.md docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
PHASE-2-4-COMPLETE.md feat(backend): Complete Phase 2.4 - User Management Enhancement 2026-02-15 20:48:39 -03:00
PHASE-2-5-CREATED.txt docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
PHASE-2.4-SPEC.md docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
PHASE-2.4-TODO.md docs: Add Phase 2.4 TODO list with implementation plan 2026-02-15 16:33:36 -03:00
PHASE-2.5-SUMMARY.md feat(backend): Complete Phase 2.5 - Access Control Implementation 2026-02-18 10:05:34 -03:00
phase27-final-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
phase27-fixed-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
phase27-test.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
PHASE28_MAIN_CHANGES.md docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
PROFILE-MANAGEMENT-IMPLEMENTED.md feat(backend): Implement enhanced profile management 2026-02-15 19:33:43 -03:00
quick-test.sh docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
rustfmt.toml feat(ci): Add Forgejo CI/CD pipeline for linting and building 2026-02-15 19:57:03 -03:00
start-dev.sh Fix Docker networking and add graceful MongoDB error handling 2026-02-23 07:58:57 -03:00
stop-dev.sh Fix Docker networking and add graceful MongoDB error handling 2026-02-23 07:58:57 -03:00
test-med-v2.sh feat: implement health statistics tracking (Phase 2.7 Task 2) 2026-03-07 16:24:18 -03:00
test-medication-endpoints.sh feat: implement health statistics tracking (Phase 2.7 Task 2) 2026-03-07 16:24:18 -03:00
test-password-recovery.sh docs(phase-2.5): Complete access control implementation 2026-02-15 21:15:17 -03:00
test-phase-2-4-complete.sh feat(backend): Complete Phase 2.4 - User Management Enhancement 2026-02-15 20:48:39 -03:00
test-phase28.sh docs(ai): reorganize documentation and update product docs 2026-03-09 11:04:44 -03:00
test-profile-management.sh feat(backend): Implement enhanced profile management 2026-02-15 19:33:43 -03:00
test-solaria-v2.sh feat: implement health statistics tracking (Phase 2.7 Task 2) 2026-03-07 16:24:18 -03:00