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).
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
use mongodb::{
|
|
bson::{doc, oid::ObjectId, DateTime},
|
|
Collection,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Profile {
|
|
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
|
|
pub id: Option<ObjectId>,
|
|
#[serde(rename = "profileId")]
|
|
pub profile_id: String,
|
|
#[serde(rename = "userId")]
|
|
pub user_id: String,
|
|
#[serde(rename = "familyId")]
|
|
pub family_id: Option<String>,
|
|
#[serde(rename = "name")]
|
|
pub name: String,
|
|
#[serde(rename = "nameIv")]
|
|
pub name_iv: String,
|
|
#[serde(rename = "nameAuthTag")]
|
|
pub name_auth_tag: String,
|
|
#[serde(rename = "role")]
|
|
pub role: String,
|
|
#[serde(rename = "permissions")]
|
|
pub permissions: Vec<String>,
|
|
#[serde(rename = "createdAt")]
|
|
pub created_at: DateTime,
|
|
#[serde(rename = "updatedAt")]
|
|
pub updated_at: DateTime,
|
|
}
|
|
|
|
pub struct ProfileRepository {
|
|
collection: Collection<Profile>,
|
|
}
|
|
|
|
impl ProfileRepository {
|
|
pub fn new(collection: Collection<Profile>) -> Self {
|
|
Self { collection }
|
|
}
|
|
|
|
pub async fn create(&self, profile: &Profile) -> mongodb::error::Result<()> {
|
|
self.collection.insert_one(profile, None).await?;
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn find_by_profile_id(
|
|
&self,
|
|
profile_id: &str,
|
|
) -> mongodb::error::Result<Option<Profile>> {
|
|
self.collection
|
|
.find_one(doc! { "profileId": profile_id }, None)
|
|
.await
|
|
}
|
|
}
|