Fix Directory: Update local groups only when the external directory includes a group attribute

This commit is contained in:
Maurus Decimus
2026-07-12 15:34:04 +02:00
parent e8192d1920
commit 8d54d0b44c
10 changed files with 116 additions and 74 deletions

View File

@@ -29,7 +29,7 @@ pub async fn test() {
email: "john.doe@example.org".into(),
email_aliases: vec!["john@example.org".into()],
secret: Some("$app$8958830913002348890$".into()),
groups: vec!["sales@example.org".into()],
groups: Some(vec!["sales@example.org".into()]),
description: Some("John Doe".into()),
}
);
@@ -45,7 +45,7 @@ pub async fn test() {
email: "jane.smith@example.org".into(),
email_aliases: vec![],
secret: Some("$app$4096614298472586996$".into()),
groups: vec!["sales@example.org".into(), "corporate@example.org".into()],
groups: Some(vec!["sales@example.org".into(), "corporate@example.org".into()]),
description: Some("Jane Smith".into()),
}
);
@@ -76,7 +76,7 @@ pub async fn test() {
email: "john.doe@example.org".into(),
email_aliases: vec!["john@example.org".into()],
secret: Some("this is John's LDAP password".into()),
groups: vec!["sales@example.org".into()],
groups: Some(vec!["sales@example.org".into()]),
description: Some("John Doe".into()),
}
);
@@ -97,7 +97,7 @@ pub async fn test() {
email: "john.doe@example.org".into(),
email_aliases: vec!["john@example.org".into()],
secret: Some("this is John's LDAP password".into()),
groups: vec!["sales@example.org".into()],
groups: Some(vec!["sales@example.org".into()]),
description: Some("John Doe".into())
})
);
@@ -107,7 +107,7 @@ pub async fn test() {
email: "jane.smith@example.org".into(),
email_aliases: vec![],
secret: Some("this is Jane's LDAP password".into()),
groups: vec!["sales@example.org".into(), "corporate@example.org".into()],
groups: Some(vec!["sales@example.org".into(), "corporate@example.org".into()]),
description: Some("Jane Smith".into())
})
);

View File

@@ -44,7 +44,7 @@ pub async fn test() {
email: "john.doe@example.org".to_string(),
email_aliases: vec![],
secret: None,
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: Some("John Doe".to_string())
}
);
@@ -66,7 +66,7 @@ pub async fn test() {
email: "john.doe@example.org".to_string(),
email_aliases: vec![],
secret: None,
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: Some("John Doe".to_string())
}
);
@@ -115,7 +115,7 @@ pub async fn test() {
email: "john.doe@example.org".to_string(),
email_aliases: vec![],
secret: None,
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: None,
}
);

View File

@@ -97,7 +97,7 @@ pub async fn test() {
email: "john@example.org".to_string(),
email_aliases: vec!["john.doe@example.org".to_string(),],
secret: Some("john secret".to_string()),
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: Some("John Doe".to_string()),
}
);
@@ -118,7 +118,7 @@ pub async fn test() {
email: "john@example.org".to_string(),
email_aliases: vec!["john.doe@example.org".to_string()],
secret: Some("john secret".to_string()),
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: Some("John Doe".to_string()),
})
);
@@ -128,7 +128,7 @@ pub async fn test() {
email: "jane@example.org".to_string(),
email_aliases: vec![],
secret: Some("jane secret".to_string()),
groups: vec!["sales@example.org".to_string()],
groups: Some(vec!["sales@example.org".to_string()]),
description: Some("Jane Doe".to_string()),
})
);

View File

@@ -29,7 +29,7 @@ pub async fn test() {
email: "john@unknown.org".to_string(),
email_aliases: vec![],
secret: "supersecret".to_string().into(),
groups: vec![],
groups: Some(vec![]),
description: "John Doe".to_string().into(),
})
.await
@@ -44,10 +44,10 @@ pub async fn test() {
"j.doe@example.org".to_string(),
],
secret: "supersecret".to_string().into(),
groups: vec![
groups: Some(vec![
"corporate@example.org".to_string(),
"sales@example.org".to_string(),
],
]),
description: "John Doe".to_string().into(),
};
let result = test
@@ -162,8 +162,9 @@ pub async fn test() {
account_in
.email_aliases
.push("johnny@example.org".to_string());
account_in.groups.pop();
account_in.groups.push("support@example.org".to_string());
let groups = account_in.groups.get_or_insert_default();
groups.pop();
groups.push("support@example.org".to_string());
account_in.secret = "evenmoresecret".to_string().into();
assert_eq!(
test.server
@@ -227,6 +228,38 @@ pub async fn test() {
4
);
account_in.groups = None;
test.server
.synchronize_account(account_in.clone())
.await
.unwrap();
let account_out = test
.server
.registry()
.object::<Account>(account_id)
.await
.unwrap()
.unwrap()
.into_user()
.unwrap();
assert_eq!(account_out.member_group_ids.len(), 2);
account_in.groups = Some(vec![]);
test.server
.synchronize_account(account_in.clone())
.await
.unwrap();
let account_out = test
.server
.registry()
.object::<Account>(account_id)
.await
.unwrap()
.unwrap()
.into_user()
.unwrap();
assert_eq!(account_out.member_group_ids.len(), 0);
// Synchronize a group
assert_eq!(
test.server