Test fixes - part 2

This commit is contained in:
mdecimus
2024-09-17 19:33:31 +02:00
parent 1e08e56672
commit 6b7dac0fcb
19 changed files with 423 additions and 129 deletions

View File

@@ -449,6 +449,7 @@ async fn internal_directory() {
quota: 1024,
typ: Type::Individual,
member_of: vec!["list".to_string(), "sales".to_string()],
..Default::default()
}
);
assert_eq!(store.get_principal_id("john").await.unwrap(), None);
@@ -530,7 +531,14 @@ async fn internal_directory() {
// List accounts
assert_eq!(
store
.list_principals(None, None, &[], &[], 0, 0)
.list_principals(
None,
None,
&[Type::Individual, Type::Group, Type::List],
&[],
0,
0
)
.await
.unwrap()
.items
@@ -633,7 +641,14 @@ async fn internal_directory() {
assert!(!store.rcpt("john.doe@example.org").await.unwrap());
assert_eq!(
store
.list_principals(None, None, &[], &[], 0, 0)
.list_principals(
None,
None,
&[Type::Individual, Type::Group, Type::List],
&[],
0,
0
)
.await
.unwrap()
.items

View File

@@ -6,7 +6,7 @@
use std::fmt::Debug;
use directory::{backend::internal::manage::ManageDirectory, QueryBy, Type};
use directory::{backend::internal::manage::ManageDirectory, QueryBy, Type, ROLE_USER};
use mail_send::Credentials;
use crate::directory::{map_account_ids, DirectoryTest, IntoTestPrincipal, TestPrincipal};
@@ -57,6 +57,7 @@ async fn ldap_directory() {
"john@example.org".to_string(),
"john.doe@example.org".to_string()
],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
.into_sorted()
@@ -85,6 +86,7 @@ async fn ldap_directory() {
typ: Type::Individual,
quota: 500000,
emails: vec!["bill@example.org".to_string(),],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
.into_sorted()
@@ -122,6 +124,7 @@ async fn ldap_directory() {
.map(|v| v.to_string())
.collect(),
emails: vec!["jane@example.org".to_string(),],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
.into_sorted()
@@ -140,6 +143,7 @@ async fn ldap_directory() {
name: "sales".to_string(),
description: "sales".to_string().into(),
typ: Type::Group,
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
);

View File

@@ -266,6 +266,7 @@ pub struct TestPrincipal {
pub secrets: Vec<String>,
pub emails: Vec<String>,
pub member_of: Vec<String>,
pub roles: Vec<String>,
pub description: Option<String>,
}
@@ -457,10 +458,9 @@ impl From<Principal> for TestPrincipal {
member_of: value
.take_str_array(PrincipalField::MemberOf)
.unwrap_or_default(),
/*member_of: value
.iter_int(PrincipalField::MemberOf)
.map(|v| v as u32)
.collect(),*/
roles: value
.take_str_array(PrincipalField::Roles)
.unwrap_or_default(),
description: value.take_str(PrincipalField::Description),
}
}

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use directory::{backend::internal::manage::ManageDirectory, QueryBy, Type};
use directory::{backend::internal::manage::ManageDirectory, QueryBy, Type, ROLE_ADMIN, ROLE_USER};
use mail_send::Credentials;
use store::{LookupStore, Store};
@@ -39,6 +39,9 @@ async fn sql_directory() {
store.create_test_directory().await;
// Create test users
store
.create_test_user("admin", "very_secret", "Administrator")
.await;
store.create_test_user("john", "12345", "John Doe").await;
store.create_test_user("jane", "abcde", "Jane Doe").await;
store
@@ -128,6 +131,7 @@ async fn sql_directory() {
"jdoe@example.org".to_string(),
"john.doe@example.org".to_string()
],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
);
@@ -154,6 +158,30 @@ async fn sql_directory() {
typ: Type::Individual,
quota: 500000,
emails: vec!["bill@example.org".to_string(),],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
);
assert_eq!(
handle
.query(
QueryBy::Credentials(&Credentials::Plain {
username: "admin".to_string(),
secret: "very_secret".to_string()
}),
true
)
.await
.unwrap()
.unwrap()
.into_test(),
TestPrincipal {
id: base_store.get_principal_id("admin").await.unwrap().unwrap(),
name: "admin".to_string(),
description: "Administrator".to_string().into(),
secrets: vec!["very_secret".to_string()],
typ: Type::Individual,
roles: vec![ROLE_ADMIN.to_string()],
..Default::default()
}
);
@@ -189,6 +217,7 @@ async fn sql_directory() {
.map(|v| v.to_string())
.collect(),
emails: vec!["jane@example.org".to_string(),],
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
);
@@ -206,6 +235,7 @@ async fn sql_directory() {
name: "sales".to_string(),
description: "Sales Team".to_string().into(),
typ: Type::Group,
roles: vec![ROLE_USER.to_string()],
..Default::default()
}
);