From dd877369e34bdd4f8f6e04bebfe4fd5d642962eb Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 19 Sep 2026 17:03:15 -0400 Subject: [PATCH 01/13] bump: simodels --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85c6be2..8d6052c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1551,8 +1551,8 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" [[package]] name = "simodels" -version = "0.11.4" -source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.4#d6d719741945ef7719ab1db3e0ef3c617b5bb909" +version = "0.11.6" +source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.6#e6ab0bcd83fd2ab3ab47298022c885132eed9945" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index ee6f536..310d900 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ time = { version = "0.3.55", features = ["macros", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.4" } +simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.6" } sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.1" } [dev-dependencies] -- 2.47.3 From 9b4d0b7b32fd468c94598e5865c90357590f8f43 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 19 Sep 2026 18:14:01 -0400 Subject: [PATCH 02/13] Get back here later --- src/callers/login.rs | 93 ++++++++++++++++++++++++++++++++++++++++++++ src/callers/mod.rs | 1 + src/repo/mod.rs | 22 +++++++++++ 3 files changed, 116 insertions(+) diff --git a/src/callers/login.rs b/src/callers/login.rs index c583d97..4f271b8 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -20,6 +20,25 @@ pub mod request { pub access_token: String, } } + + pub mod update_password { + use serde::{Deserialize, Serialize}; + + #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] + pub struct Request { + pub user_id: uuid::Uuid, + pub username: String, + pub current_password: String, + pub updated_password: String, + pub confirmed_password: String, + } + + impl Request { + pub fn is_valid(&self) -> bool { + !self.user_id.is_nil() || !self.username.is_empty() || !self.current_password.is_empty() || !self.updated_password.is_empty() || !self.confirmed_password.is_empty() + } + } + } } pub mod response { @@ -46,6 +65,16 @@ pub mod response { pub data: Vec, } } + + pub mod update_password { + use serde::{Deserialize, Serialize}; + + #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } } /// Module for login endpoints @@ -261,4 +290,68 @@ pub mod endpoint { (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } + + #[utoipa::path( + patch, + path = super::super::endpoints::UPDATE_PASSWORD, + request_body( + content = super::request::update_password::Request, + description = "Update user password", + content_type = "application/json" + ), + responses( + (status = 200, description = "Password updated successfully", body = super::response::update_password::Response), + (status = 400, description = "Failure", body = super::response::update_password::Response) + ) + )] + pub async fn update_password( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = super::response::update_password::Response::default(); + + if !payload.is_valid() { + response.message = "Invalid request".to_string(); + return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)); + } + + match repo::user::get(&pool, &payload.username).await { + Ok(user) => { + if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() { + match repo::salt::get(&pool, &user.salt_id).await { + Ok(salt) => { + // Left off here + let updated_hashed_password = hashing::hash_password(&payload.updated_password, &salt).unwrap(); + + match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + Ok(_) => { + response.message = "Successful".to_string(); + response.data.push(user.id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + Err(err) => { + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + + } else { + // invalid + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } } diff --git a/src/callers/mod.rs b/src/callers/mod.rs index f280a4f..512f720 100644 --- a/src/callers/mod.rs +++ b/src/callers/mod.rs @@ -7,6 +7,7 @@ pub mod endpoints { pub const REGISTER: &str = "/api/v2/register"; pub const DBTEST: &str = "/api/v2/test/db"; pub const LOGIN: &str = "/api/v2/login"; + pub const UPDATE_PASSWORD: &str = "/api/v2/user/password"; pub const SERVICE_LOGIN: &str = "/api/v2/service/login"; pub const REFRESH_TOKEN: &str = "/api/v2/token/refresh"; } diff --git a/src/repo/mod.rs b/src/repo/mod.rs index b127180..df5ac09 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -44,6 +44,28 @@ pub mod user { } } + pub async fn update_password(pool: &sqlx::PgPool, user: &simodels::user::User, password: &str) -> Result { + match sqlx::query( + r#" + UPDATE "user" SET password = $1 WHERE id = $2 + "# + ) + .bind(password) + .bind(user.id) + .execute(pool) + // .fetch_optional(pool) + .await { + Ok(r) => { + return if r.rows_affected() > 0 { + Ok(true) + } else { + Ok(false) + } + } + Err(err) => Err(err) + } + } + pub async fn update_last_login( pool: &sqlx::PgPool, user: &simodels::user::User, -- 2.47.3 From 53ed0060c80e696aefd7ee29a2e2cca5ef4c8fba Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:32:26 -0400 Subject: [PATCH 03/13] Fix synxtax --- src/callers/login.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 4f271b8..4ce54d0 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -324,7 +324,11 @@ pub mod endpoint { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { // Left off here - let updated_hashed_password = hashing::hash_password(&payload.updated_password, &salt).unwrap(); + let updated_salt_string = hashing::generate_salt().unwrap(); + let mut updated_salt = simodels::user::salt::Salt::default(); + updated_salt.salt = updated_salt_string.to_string(); + updated_salt.id = salt.id.clone(); + let updated_hashed_password = hashing::hash_password(&payload.updated_password, &updated_salt_string).unwrap(); match repo::user::update_password(&pool, &user, &updated_hashed_password).await { Ok(_) => { -- 2.47.3 From 1a885274a81ee006d6f62bb24d2bddb68300322d Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:40:45 -0400 Subject: [PATCH 04/13] More code --- src/callers/login.rs | 30 +++++++++++++++++++----------- src/repo/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 4ce54d0..1494cff 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -323,32 +323,40 @@ pub mod endpoint { if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { - // Left off here let updated_salt_string = hashing::generate_salt().unwrap(); let mut updated_salt = simodels::user::salt::Salt::default(); updated_salt.salt = updated_salt_string.to_string(); updated_salt.id = salt.id.clone(); let updated_hashed_password = hashing::hash_password(&payload.updated_password, &updated_salt_string).unwrap(); - match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + match repo::salt::update_salt(&pool, &salt, &updated_salt.salt).await { Ok(_) => { - response.message = "Successful".to_string(); - response.data.push(user.id); - (axum::http::StatusCode::OK, axum::Json(response)) + match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + Ok(_) => { + response.message = "Successful".to_string(); + response.data.push(user.id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } } Err(err) => { response.message = err.to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } - } - Err(err) => { - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } } else { - // invalid + response.message = "Invalid".to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } diff --git a/src/repo/mod.rs b/src/repo/mod.rs index df5ac09..bd6b397 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -218,4 +218,27 @@ pub mod salt { Err(sqlx::Error::RowNotFound) } } + + pub async fn update_salt(pool: &sqlx::PgPool, salt: &simodels::user::salt::Salt, updated_salt: &str) -> Result { + match sqlx::query( + r#" + UPDATE "salt" SET salt = $1 WHERE id = $2 + "#, + ) + .bind(updated_salt) + .bind(salt.id) + .execute(pool) + .await { + Ok(row) => { + let result = if row.rows_affected() > 0 { + true + } else { + false + }; + + Ok(result) + }, + Err(err) => Err(err), + } + } } -- 2.47.3 From 4cc42697cb5bd15bfaaeee45b30201d7d8dacc80 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:41:02 -0400 Subject: [PATCH 05/13] cargo fmt --- src/callers/login.rs | 42 ++++++++++++++++++++++++++++++------------ src/repo/mod.rs | 32 +++++++++++++++++++------------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 1494cff..9e2f43f 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -35,7 +35,11 @@ pub mod request { impl Request { pub fn is_valid(&self) -> bool { - !self.user_id.is_nil() || !self.username.is_empty() || !self.current_password.is_empty() || !self.updated_password.is_empty() || !self.confirmed_password.is_empty() + !self.user_id.is_nil() + || !self.username.is_empty() + || !self.current_password.is_empty() + || !self.updated_password.is_empty() + || !self.confirmed_password.is_empty() } } } @@ -320,18 +324,30 @@ pub mod endpoint { match repo::user::get(&pool, &payload.username).await { Ok(user) => { - if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() { + if hashing::verify_password(&payload.current_password, user.password.clone()) + .unwrap() + { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { let updated_salt_string = hashing::generate_salt().unwrap(); let mut updated_salt = simodels::user::salt::Salt::default(); updated_salt.salt = updated_salt_string.to_string(); updated_salt.id = salt.id.clone(); - let updated_hashed_password = hashing::hash_password(&payload.updated_password, &updated_salt_string).unwrap(); + let updated_hashed_password = hashing::hash_password( + &payload.updated_password, + &updated_salt_string, + ) + .unwrap(); match repo::salt::update_salt(&pool, &salt, &updated_salt.salt).await { Ok(_) => { - match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + match repo::user::update_password( + &pool, + &user, + &updated_hashed_password, + ) + .await + { Ok(_) => { response.message = "Successful".to_string(); response.data.push(user.id); @@ -339,13 +355,10 @@ pub mod endpoint { } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + ( + axum::http::StatusCode::BAD_REQUEST, + axum::Json(response), + ) } } } @@ -354,7 +367,12 @@ pub mod endpoint { (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } - + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } } else { response.message = "Invalid".to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) diff --git a/src/repo/mod.rs b/src/repo/mod.rs index bd6b397..a5ed496 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -44,25 +44,30 @@ pub mod user { } } - pub async fn update_password(pool: &sqlx::PgPool, user: &simodels::user::User, password: &str) -> Result { + pub async fn update_password( + pool: &sqlx::PgPool, + user: &simodels::user::User, + password: &str, + ) -> Result { match sqlx::query( r#" UPDATE "user" SET password = $1 WHERE id = $2 - "# + "#, ) .bind(password) .bind(user.id) .execute(pool) // .fetch_optional(pool) - .await { + .await + { Ok(r) => { return if r.rows_affected() > 0 { Ok(true) } else { Ok(false) - } + }; } - Err(err) => Err(err) + Err(err) => Err(err), } } @@ -219,7 +224,11 @@ pub mod salt { } } - pub async fn update_salt(pool: &sqlx::PgPool, salt: &simodels::user::salt::Salt, updated_salt: &str) -> Result { + pub async fn update_salt( + pool: &sqlx::PgPool, + salt: &simodels::user::salt::Salt, + updated_salt: &str, + ) -> Result { match sqlx::query( r#" UPDATE "salt" SET salt = $1 WHERE id = $2 @@ -228,16 +237,13 @@ pub mod salt { .bind(updated_salt) .bind(salt.id) .execute(pool) - .await { + .await + { Ok(row) => { - let result = if row.rows_affected() > 0 { - true - } else { - false - }; + let result = if row.rows_affected() > 0 { true } else { false }; Ok(result) - }, + } Err(err) => Err(err), } } -- 2.47.3 From 476b25fecf0d1e31130536a74bc040f0a7be3181 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:41:14 -0400 Subject: [PATCH 06/13] bump: soaricarus_auth --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d6052c..c6d9c1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1580,7 +1580,7 @@ dependencies = [ [[package]] name = "soaricarus_auth" -version = "0.8.2" +version = "0.8.3" dependencies = [ "argon2", "axum", diff --git a/Cargo.toml b/Cargo.toml index 310d900..f138004 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soaricarus_auth" -version = "0.8.2" +version = "0.8.3" edition = "2024" rust-version = "1.95" license = "MIT" -- 2.47.3 From e2cd7a52cf4ab2e7d3cc7590b3b8b932c3e0d736 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:50:03 -0400 Subject: [PATCH 07/13] More stuff --- src/callers/login.rs | 5 +++-- src/main.rs | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 9e2f43f..199082b 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -305,7 +305,8 @@ pub mod endpoint { ), responses( (status = 200, description = "Password updated successfully", body = super::response::update_password::Response), - (status = 400, description = "Failure", body = super::response::update_password::Response) + (status = 400, description = "Invalid", body = super::response::update_password::Response), + (status = 500, description = "Failure", body = super::response::update_password::Response) ) )] pub async fn update_password( @@ -356,7 +357,7 @@ pub mod endpoint { Err(err) => { response.message = err.to_string(); ( - axum::http::StatusCode::BAD_REQUEST, + axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), ) } diff --git a/src/main.rs b/src/main.rs index 71ef3ba..3627802 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,11 +38,11 @@ mod init { paths( common_callers::endpoint::db_ping, common_callers::endpoint::root, register_caller::register_user, - login_endpoints::login, login_endpoints::service_login, login_endpoints::refresh_token + login_endpoints::login, login_endpoints::update_password, login_endpoints::service_login, login_endpoints::refresh_token ), components(schemas(common_callers::response::TestResult, register_responses::Response, - login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)), + login_responses::Response, login_responses::service_login::Response, login_responses::update_password::Response, login_responses::refresh_token::Response)), tags( (name = "soaricarus Auth API", description = "Auth API for soaricarus API") ) @@ -51,20 +51,20 @@ mod init { mod cors { pub async fn configure_cors() -> tower_http::cors::CorsLayer { - // Start building the CORS layer with common settings let cors = tower_http::cors::CorsLayer::new() .allow_methods([ axum::http::Method::GET, + axum::http::Method::PATCH, axum::http::Method::POST, axum::http::Method::PUT, axum::http::Method::DELETE, - ]) // Specify allowed methods:cite[2] + ]) .allow_headers([ axum::http::header::CONTENT_TYPE, axum::http::header::AUTHORIZATION, - ]) // Specify allowed headers:cite[2] - .allow_credentials(true) // If you need to send cookies or authentication headers:cite[2] - .max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2] + ]) + .allow_credentials(true) + .max_age(std::time::Duration::from_secs(3600)); // Dynamically set the allowed origin based on the environment match std::env::var(sienvy::keys::APP_ENV).as_deref() { @@ -116,6 +116,10 @@ mod init { callers::endpoints::LOGIN, post(callers::login::endpoint::login), ) + .route( + callers::endpoints::UPDATE_PASSWORD, + post(callers::login::endpoint::update_password), + ) .route( callers::endpoints::SERVICE_LOGIN, post(callers::login::endpoint::service_login), @@ -553,4 +557,28 @@ mod tests { let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } + + #[tokio::test] + async fn test_update_password() { + let tm_pool = db_mgr::get_pool().await.unwrap(); + + let db_name = db_mgr::generate_db_name().await; + + match db_mgr::create_database(&tm_pool, &db_name).await { + Ok(_) => { + println!("Success"); + } + Err(e) => { + assert!(false, "Error: {:?}", e.to_string()); + } + } + + let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); + + db::init::migrations(&pool).await; + + let app = init::routes().await.layer(axum::Extension(pool)); + + let _ = db_mgr::drop_database(&tm_pool, &db_name).await; + } } -- 2.47.3 From 69a1cb42d93f2444ee868a8c1b635e38b9129bbc Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 21 Sep 2026 12:53:25 -0400 Subject: [PATCH 08/13] Test tweaks --- src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- src/repo/mod.rs | 9 +++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3627802..2cd1dd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,6 +251,13 @@ mod tests { }) } + fn get_test_login_payload(usr: &callers::login::request::Request) -> serde_json::Value { + json!({ + "username": &usr.username, + "password": &usr.password, + }) + } + pub mod requests { use tower::ServiceExt; // for `call`, `oneshot`, and `ready` @@ -268,6 +275,21 @@ mod tests { app.clone().oneshot(req).await } + + pub async fn login( + app: &axum::Router, + usr: &super::callers::login::request::Request, + ) -> Result { + let payload = super::get_test_login_payload(&usr); + let req = axum::http::Request::builder() + .method(axum::http::Method::POST) + .uri(crate::callers::endpoints::LOGIN) + .header(axum::http::header::CONTENT_TYPE, "application/json") + .body(axum::body::Body::from(payload.to_string())) + .unwrap(); + + app.clone().oneshot(req).await + } } #[tokio::test] @@ -398,11 +420,18 @@ mod tests { ); assert!(returned_usr.date_created.is_some(), "Date Created is empty"); + /* let login_payload = json!({ "username": &usr.username, "password": &usr.password, }); + */ + let mut n_usr = callers::login::request::Request::default(); + n_usr.username = usr.username.clone(); + n_usr.password = usr.password.clone(); + + /* match app .oneshot( Request::builder() @@ -413,7 +442,8 @@ mod tests { .unwrap(), ) .await - { + */ + match requests::login(&app, &n_usr).await { Ok(resp) => { assert_eq!(StatusCode::OK, resp.status(), "Status is not right"); let body = axum::body::to_bytes(resp.into_body(), usize::MAX) @@ -577,7 +607,9 @@ mod tests { db::init::migrations(&pool).await; - let app = init::routes().await.layer(axum::Extension(pool)); + let _app = init::routes().await.layer(axum::Extension(pool)); + + let _usr = get_test_register_request(); let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } diff --git a/src/repo/mod.rs b/src/repo/mod.rs index a5ed496..c0e52c4 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -57,7 +57,6 @@ pub mod user { .bind(password) .bind(user.id) .execute(pool) - // .fetch_optional(pool) .await { Ok(r) => { @@ -240,9 +239,11 @@ pub mod salt { .await { Ok(row) => { - let result = if row.rows_affected() > 0 { true } else { false }; - - Ok(result) + if row.rows_affected() > 0 { + Ok(true) + } else { + Ok(false) + } } Err(err) => Err(err), } -- 2.47.3 From d126bc7e0a92930d38bec1b0a985e4786449e409 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 21 Sep 2026 12:56:48 -0400 Subject: [PATCH 09/13] Warning fixes --- src/callers/login.rs | 7 ++++--- src/repo/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 199082b..65dc6ca 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -331,9 +331,10 @@ pub mod endpoint { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { let updated_salt_string = hashing::generate_salt().unwrap(); - let mut updated_salt = simodels::user::salt::Salt::default(); - updated_salt.salt = updated_salt_string.to_string(); - updated_salt.id = salt.id.clone(); + let updated_salt = simodels::user::salt::Salt { + salt: updated_salt_string.to_string(), + id: salt.id, + }; let updated_hashed_password = hashing::hash_password( &payload.updated_password, &updated_salt_string, diff --git a/src/repo/mod.rs b/src/repo/mod.rs index c0e52c4..3346e6c 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -60,11 +60,11 @@ pub mod user { .await { Ok(r) => { - return if r.rows_affected() > 0 { + if r.rows_affected() > 0 { Ok(true) } else { Ok(false) - }; + } } Err(err) => Err(err), } -- 2.47.3 From 2f6093fcd12748f23c86a61539bf8e5f3a1eaff4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 22 Sep 2026 12:32:22 -0400 Subject: [PATCH 10/13] Test changes --- src/main.rs | 118 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2cd1dd8..0244fed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -258,6 +258,20 @@ mod tests { }) } + pub mod test_data { + use serde_json::json; + + pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value { + json!({ + "username": "somethingsss", + "user_id": user_id, + "current_password": "Raindown!", + "updated_password": "SpeakWithUrChest22!", + "confirmed_password": "SpeakWithUrChest22!" + }) + } + } + pub mod requests { use tower::ServiceExt; // for `call`, `oneshot`, and `ready` @@ -290,6 +304,21 @@ mod tests { app.clone().oneshot(req).await } + + pub async fn update_password( + app: &axum::Router, + user_id: &uuid::Uuid, + ) -> Result { + let payload = super::test_data::get_updated_password(user_id); + let req = axum::http::Request::builder() + .method(axum::http::Method::PATCH) + .uri(crate::callers::endpoints::LOGIN) + .header(axum::http::header::CONTENT_TYPE, "application/json") + .body(axum::body::Body::from(payload.to_string())) + .unwrap(); + + app.clone().oneshot(req).await + } } #[tokio::test] @@ -420,29 +449,10 @@ mod tests { ); assert!(returned_usr.date_created.is_some(), "Date Created is empty"); - /* - let login_payload = json!({ - "username": &usr.username, - "password": &usr.password, - }); - */ - let mut n_usr = callers::login::request::Request::default(); n_usr.username = usr.username.clone(); n_usr.password = usr.password.clone(); - /* - match app - .oneshot( - Request::builder() - .method(axum::http::Method::POST) - .uri(callers::endpoints::LOGIN) - .header(axum::http::header::CONTENT_TYPE, "application/json") - .body(Body::from(login_payload.to_string())) - .unwrap(), - ) - .await - */ match requests::login(&app, &n_usr).await { Ok(resp) => { assert_eq!(StatusCode::OK, resp.status(), "Status is not right"); @@ -607,9 +617,75 @@ mod tests { db::init::migrations(&pool).await; - let _app = init::routes().await.layer(axum::Extension(pool)); + let app = init::routes().await.layer(axum::Extension(pool)); - let _usr = get_test_register_request(); + let usr = get_test_register_request(); + + match requests::register(&app, &usr).await { + Ok(resp) => { + assert_eq!( + resp.status(), + StatusCode::CREATED, + "Message: {:?} {:?}", + resp, + usr.username + ); + let body = axum::body::to_bytes(resp.into_body(), usize::MAX) + .await + .unwrap(); + let parsed_body: callers::register::response::Response = + serde_json::from_slice(&body).unwrap(); + let returned_usr = &parsed_body.data[0]; + + assert_eq!(false, returned_usr.id.is_nil(), "Id is not populated"); + + assert_eq!( + usr.username, returned_usr.username, + "Usernames do not match" + ); + assert!(returned_usr.date_created.is_some(), "Date Created is empty"); + + let mut n_usr = callers::login::request::Request::default(); + n_usr.username = usr.username.clone(); + n_usr.password = usr.password.clone(); + + match requests::login(&app, &n_usr).await { + Ok(resp) => { + assert_eq!(StatusCode::OK, resp.status(), "Status is not right"); + let body = axum::body::to_bytes(resp.into_body(), usize::MAX) + .await + .unwrap(); + let parsed_body: callers::login::response::Response = + serde_json::from_slice(&body).unwrap(); + let login_result = &parsed_body.data[0]; + assert!(!login_result.id.is_nil(), "Id is nil"); + + match requests::update_password(&app, &login_result.id).await { + Ok(resp) => { + assert_eq!(StatusCode::OK, resp.status(), "Status is not right"); + let body = axum::body::to_bytes(resp.into_body(), usize::MAX) + .await + .unwrap(); + let parsed_body: callers::login::response::update_password::Response = + serde_json::from_slice(&body).unwrap(); + let id = parsed_body.data[0]; + + assert_eq!(id, login_result.id, "Ids do not match"); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err.to_string()); + } + } + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } -- 2.47.3 From e0cbfda25285be1cc3d7171e7025b19e661c4428 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 22 Sep 2026 12:36:51 -0400 Subject: [PATCH 11/13] Test is not passing --- src/callers/login.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/callers/login.rs b/src/callers/login.rs index 65dc6ca..f84a1ac 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -320,9 +320,11 @@ pub mod endpoint { if !payload.is_valid() { response.message = "Invalid request".to_string(); + println!("Invalid request"); return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)); } + println!("Get User"); match repo::user::get(&pool, &payload.username).await { Ok(user) => { if hashing::verify_password(&payload.current_password, user.password.clone()) -- 2.47.3 From 8db762f11bbb093dad4affca1dd94fe372cfc132 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 22 Sep 2026 12:41:40 -0400 Subject: [PATCH 12/13] Changed allowable me --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0244fed..c5363b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ async fn main() { mod init { use axum::{ Router, - routing::{get, post}, + routing::{get, patch, post}, }; use utoipa::OpenApi; @@ -118,7 +118,7 @@ mod init { ) .route( callers::endpoints::UPDATE_PASSWORD, - post(callers::login::endpoint::update_password), + patch(callers::login::endpoint::update_password), ) .route( callers::endpoints::SERVICE_LOGIN, -- 2.47.3 From b45127394b8a6eadb550ade44a3f557f063231bb Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 22 Sep 2026 12:45:21 -0400 Subject: [PATCH 13/13] Please? --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c5363b3..c0e947c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -312,7 +312,7 @@ mod tests { let payload = super::test_data::get_updated_password(user_id); let req = axum::http::Request::builder() .method(axum::http::Method::PATCH) - .uri(crate::callers::endpoints::LOGIN) + .uri(crate::callers::endpoints::UPDATE_PASSWORD) .header(axum::http::header::CONTENT_TYPE, "application/json") .body(axum::body::Body::from(payload.to_string())) .unwrap(); -- 2.47.3