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<()> {
debug!(?request.group_id);
let update_group = model::groups::ActiveModel {
group_id: ActiveValue::Set(request.group_id),
display_name: request
.display_name
.map(ActiveValue::Set)
.unwrap_or_default(),
..Default::default()
};
model::Group::update_many()
.set(update_group)
.filter(sea_orm::ColumnTrait::eq(
&GroupColumn::GroupId,
request.group_id,
))
.exec(&self.sql_pool)
.await?;
update_group.update(&self.sql_pool).await?;
Ok(())
}

View File

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

View File

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