fix(backend): refresh-token jti + code cleanup (#15,#28,#29,#30)

Refresh-token rotation bug (found via Solaria smoke test):
* RefreshClaims now carries a unique random jti (UUID v4). Without it, two
  refresh tokens issued in the same second (e.g. on rotation) were byte-identical
  — breaking rotation, colliding on the tokenHash unique index, and making a
  stolen old token indistinguishable from the new one. Every refresh token is
  now unique regardless of issue time. Added a unit test asserting consecutive
  tokens differ.

Code cleanup (review items):
* #15: removed unused deps tower_governor, slog, thiserror (zero refs in src/).
* #30: deleted leftover src/main.rs.restore (a stale git-error-message backup).
* #28: removed the 9 single-line-comment stub files under src/db/ (appointment,
  family, health_data, lab_result, medication, profile, permission, share, user)
  and their mod declarations; nothing referenced them, real logic lives in
  mongodb_impl.rs/init.rs.
* #29: stripped 61 broad module-level #![allow(...)] suppressions across src/.
  Fixed the surfaced warnings instead: 4 unused 'claims' extractor bindings ->
  _claims; removed dead OpenFDAService.client/base_url fields + the never-called
  query_drug_events method + unused HashMap/reqwest imports; applied clippy's
  mechanical fixes (Ok(?) -> ?, Copy ObjectId clone, redundant closures,
  useless conversions); rewrote 'if let Ok(_) = x' -> 'if x.is_ok()'. Result:
  cargo build + clippy --all-targets are warning-free with no blanket allows.

Verified: fmt clean, build clean, clippy 0 warnings, 19 unit tests pass
(was 18; +1 jti-uniqueness test).
This commit is contained in:
goose 2026-06-27 20:57:24 -03:00
parent e9f524671f
commit cf6fcd4ef2
45 changed files with 54 additions and 297 deletions

View file

@ -1,4 +1,3 @@
#![allow(clippy::needless_question_mark)]
use anyhow::Result;
use mongodb::bson::oid::ObjectId;
use mongodb::{bson::doc, options::ClientOptions, Client, Collection, Database};
@ -286,10 +285,9 @@ impl MongoDb {
pub async fn get_medication(&self, id: &str) -> Result<Option<Medication>> {
let object_id = ObjectId::parse_str(id)?;
let repo = MedicationRepository::new(self.medications.clone());
Ok(repo
.find_by_id(&object_id)
repo.find_by_id(&object_id)
.await
.map_err(|e| anyhow::anyhow!("Failed to get medication: {}", e))?)
.map_err(|e| anyhow::anyhow!("Failed to get medication: {}", e))
}
pub async fn list_medications(
@ -318,19 +316,17 @@ impl MongoDb {
) -> Result<Option<Medication>> {
let object_id = ObjectId::parse_str(id)?;
let repo = MedicationRepository::new(self.medications.clone());
Ok(repo
.update(&object_id, updates)
repo.update(&object_id, updates)
.await
.map_err(|e| anyhow::anyhow!("Failed to update medication: {}", e))?)
.map_err(|e| anyhow::anyhow!("Failed to update medication: {}", e))
}
pub async fn delete_medication(&self, id: &str) -> Result<bool> {
let object_id = ObjectId::parse_str(id)?;
let repo = MedicationRepository::new(self.medications.clone());
Ok(repo
.delete(&object_id)
repo.delete(&object_id)
.await
.map_err(|e| anyhow::anyhow!("Failed to delete medication: {}", e))?)
.map_err(|e| anyhow::anyhow!("Failed to delete medication: {}", e))
}
pub async fn log_medication_dose(&self, dose: &MedicationDose) -> Result<Option<ObjectId>> {
@ -349,9 +345,8 @@ impl MongoDb {
days: i64,
) -> Result<crate::models::medication::AdherenceStats> {
let repo = MedicationRepository::new(self.medications.clone());
Ok(repo
.calculate_adherence(medication_id, days)
repo.calculate_adherence(medication_id, days)
.await
.map_err(|e| anyhow::anyhow!("Failed to calculate adherence: {}", e))?)
.map_err(|e| anyhow::anyhow!("Failed to calculate adherence: {}", e))
}
}