server: fix user password setting

It used to try to set all user IDs to the same, which would fail if
there is more than 1 user.
This commit is contained in:
Valentin Tolmer 2022-11-30 08:23:36 +01:00 committed by nitnelave
parent 09a0522e2d
commit 665e525f0a
3 changed files with 8 additions and 21 deletions

View File

@ -102,20 +102,14 @@ impl GroupBackendHandler for SqlBackendHandler {
async fn update_group(&self, request: UpdateGroupRequest) -> Result<()> { async fn update_group(&self, request: UpdateGroupRequest) -> Result<()> {
debug!(?request.group_id); debug!(?request.group_id);
let update_group = model::groups::ActiveModel { let update_group = model::groups::ActiveModel {
group_id: ActiveValue::Set(request.group_id),
display_name: request display_name: request
.display_name .display_name
.map(ActiveValue::Set) .map(ActiveValue::Set)
.unwrap_or_default(), .unwrap_or_default(),
..Default::default() ..Default::default()
}; };
model::Group::update_many() update_group.update(&self.sql_pool).await?;
.set(update_group)
.filter(sea_orm::ColumnTrait::eq(
&GroupColumn::GroupId,
request.group_id,
))
.exec(&self.sql_pool)
.await?;
Ok(()) Ok(())
} }

View File

@ -8,7 +8,7 @@ use super::{
}; };
use async_trait::async_trait; use async_trait::async_trait;
use lldap_auth::opaque; use lldap_auth::opaque;
use sea_orm::{ActiveValue, EntityTrait, FromQueryResult, QuerySelect}; use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, FromQueryResult, QuerySelect};
use secstr::SecUtf8; use secstr::SecUtf8;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
@ -198,10 +198,7 @@ impl OpaqueHandler for SqlOpaqueHandler {
password_hash: ActiveValue::Set(Some(password_file.serialize())), password_hash: ActiveValue::Set(Some(password_file.serialize())),
..Default::default() ..Default::default()
}; };
model::User::update_many() user_update.update(&self.sql_pool).await?;
.set(user_update)
.exec(&self.sql_pool)
.await?;
Ok(()) Ok(())
} }
} }
@ -271,10 +268,12 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_opaque_flow() -> Result<()> { async fn test_opaque_flow() -> Result<()> {
let sql_pool = get_initialized_db().await; let sql_pool = get_initialized_db().await;
crate::infra::logging::init_for_tests();
let config = get_default_config(); let config = get_default_config();
let backend_handler = SqlBackendHandler::new(config.clone(), sql_pool.clone()); let backend_handler = SqlBackendHandler::new(config.clone(), sql_pool.clone());
let opaque_handler = SqlOpaqueHandler::new(config, sql_pool); let opaque_handler = SqlOpaqueHandler::new(config, sql_pool);
insert_user_no_password(&backend_handler, "bob").await; insert_user_no_password(&backend_handler, "bob").await;
insert_user_no_password(&backend_handler, "john").await;
attempt_login(&opaque_handler, "bob", "bob00") attempt_login(&opaque_handler, "bob", "bob00")
.await .await
.unwrap_err(); .unwrap_err();

View File

@ -179,6 +179,7 @@ impl UserBackendHandler for SqlBackendHandler {
async fn update_user(&self, request: UpdateUserRequest) -> Result<()> { async fn update_user(&self, request: UpdateUserRequest) -> Result<()> {
debug!(user_id = ?request.user_id); debug!(user_id = ?request.user_id);
let update_user = model::users::ActiveModel { let update_user = model::users::ActiveModel {
user_id: ActiveValue::Set(request.user_id),
email: request.email.map(ActiveValue::Set).unwrap_or_default(), email: request.email.map(ActiveValue::Set).unwrap_or_default(),
display_name: to_value(&request.display_name), display_name: to_value(&request.display_name),
first_name: to_value(&request.first_name), first_name: to_value(&request.first_name),
@ -186,14 +187,7 @@ impl UserBackendHandler for SqlBackendHandler {
avatar: request.avatar.into_active_value(), avatar: request.avatar.into_active_value(),
..Default::default() ..Default::default()
}; };
model::User::update_many() update_user.update(&self.sql_pool).await?;
.set(update_user)
.filter(sea_orm::ColumnTrait::eq(
&UserColumn::UserId,
request.user_id,
))
.exec(&self.sql_pool)
.await?;
Ok(()) Ok(())
} }