CLI account management + Directory refactoring
This commit is contained in:
@@ -22,8 +22,11 @@
|
||||
*/
|
||||
|
||||
use directory::{
|
||||
backend::internal::{manage::ManageDirectory, PrincipalField, PrincipalUpdate, PrincipalValue},
|
||||
Directory, DirectoryError, ManagementError, Principal, QueryBy, Type,
|
||||
backend::internal::{
|
||||
lookup::DirectoryStore, manage::ManageDirectory, PrincipalField, PrincipalUpdate,
|
||||
PrincipalValue,
|
||||
},
|
||||
DirectoryError, ManagementError, Principal, QueryBy, Type,
|
||||
};
|
||||
use jmap_proto::types::collection::Collection;
|
||||
use mail_send::Credentials;
|
||||
@@ -72,9 +75,10 @@ async fn internal_directory() {
|
||||
..Default::default()
|
||||
})
|
||||
.await,
|
||||
Err(DirectoryError::Management(ManagementError::NotUniqueField(
|
||||
PrincipalField::Name
|
||||
)))
|
||||
Err(DirectoryError::Management(ManagementError::AlreadyExists {
|
||||
field: PrincipalField::Name,
|
||||
value: "john".to_string()
|
||||
}))
|
||||
);
|
||||
|
||||
// An account using a non-existent domain should fail
|
||||
@@ -190,9 +194,10 @@ async fn internal_directory() {
|
||||
..Default::default()
|
||||
})
|
||||
.await,
|
||||
Err(DirectoryError::Management(ManagementError::NotUniqueField(
|
||||
PrincipalField::Emails
|
||||
)))
|
||||
Err(DirectoryError::Management(ManagementError::AlreadyExists {
|
||||
field: PrincipalField::Emails,
|
||||
value: "jane@example.org".to_string()
|
||||
}))
|
||||
);
|
||||
|
||||
// Create a mailing list
|
||||
@@ -458,9 +463,10 @@ async fn internal_directory() {
|
||||
),],
|
||||
)
|
||||
.await,
|
||||
Err(DirectoryError::Management(ManagementError::NotUniqueField(
|
||||
PrincipalField::Name
|
||||
)))
|
||||
Err(DirectoryError::Management(ManagementError::AlreadyExists {
|
||||
field: PrincipalField::Name,
|
||||
value: "jane".to_string()
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
@@ -472,20 +478,42 @@ async fn internal_directory() {
|
||||
),],
|
||||
)
|
||||
.await,
|
||||
Err(DirectoryError::Management(ManagementError::NotUniqueField(
|
||||
PrincipalField::Emails
|
||||
)))
|
||||
Err(DirectoryError::Management(ManagementError::AlreadyExists {
|
||||
field: PrincipalField::Emails,
|
||||
value: "jane@example.org".to_string()
|
||||
}))
|
||||
);
|
||||
|
||||
// List accounts
|
||||
assert_eq!(
|
||||
store.list_accounts(None, 0).await.unwrap(),
|
||||
store.list_accounts(None, None, 0).await.unwrap(),
|
||||
vec!["jane", "john.doe", "list", "sales", "support"]
|
||||
);
|
||||
assert_eq!(
|
||||
store.list_accounts("john".into(), 2).await.unwrap(),
|
||||
store.list_accounts("john".into(), None, 2).await.unwrap(),
|
||||
vec!["john.doe", "list"]
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.list_accounts(None, Type::Individual.into(), 0)
|
||||
.await
|
||||
.unwrap(),
|
||||
vec!["jane", "john.doe"]
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.list_accounts(None, Type::Group.into(), 0)
|
||||
.await
|
||||
.unwrap(),
|
||||
vec!["sales", "support"]
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.list_accounts(None, Type::List.into(), 0)
|
||||
.await
|
||||
.unwrap(),
|
||||
vec!["list"]
|
||||
);
|
||||
|
||||
// Write records on John's and Jane's accounts
|
||||
for account_id in [0, 1] {
|
||||
@@ -527,7 +555,7 @@ async fn internal_directory() {
|
||||
);
|
||||
assert!(!store.rcpt("john.doe@example.org").await.unwrap());
|
||||
assert_eq!(
|
||||
store.list_accounts(None, 0).await.unwrap(),
|
||||
store.list_accounts(None, None, 0).await.unwrap(),
|
||||
vec!["jane", "list", "sales", "support"]
|
||||
);
|
||||
assert_eq!(
|
||||
|
||||
@@ -29,7 +29,7 @@ pub mod sql;
|
||||
|
||||
use ::smtp::core::Lookup;
|
||||
use directory::{
|
||||
backend::internal::manage::ManageDirectory, config::ConfigDirectory, AddressMapping,
|
||||
backend::internal::manage::ManageDirectory, core::config::ConfigDirectory, AddressMapping,
|
||||
Directories, Principal,
|
||||
};
|
||||
use mail_send::Credentials;
|
||||
@@ -59,6 +59,13 @@ email = "address"
|
||||
quota = "quota"
|
||||
type = "type"
|
||||
|
||||
[store."rocksdb"]
|
||||
type = "rocksdb"
|
||||
path = "{TMP}/rocksdb"
|
||||
|
||||
[store."foundationdb"]
|
||||
type = "foundationdb"
|
||||
|
||||
[store."sqlite"]
|
||||
type = "sqlite"
|
||||
path = "{TMP}/auth.db"
|
||||
@@ -153,7 +160,7 @@ base-dn = "dc=example,dc=org"
|
||||
dn = "cn=serviceuser,ou=svcaccts,dc=example,dc=org"
|
||||
secret = "mysecret"
|
||||
|
||||
[directory."ldap".auth-bind]
|
||||
[directory."ldap".bind.auth]
|
||||
enable = false
|
||||
dn = "cn=?,ou=svcaccts,dc=example,dc=org"
|
||||
|
||||
@@ -278,7 +285,11 @@ pub struct DirectoryTest {
|
||||
impl DirectoryTest {
|
||||
pub async fn new(id_store: Option<&str>) -> DirectoryTest {
|
||||
let temp_dir = TempDir::new("directory_tests", true);
|
||||
let config_file = CONFIG.replace("{TMP}", &temp_dir.path.to_string_lossy());
|
||||
let mut config_file = CONFIG.replace("{TMP}", &temp_dir.path.to_string_lossy());
|
||||
if id_store.is_some() {
|
||||
// Disable foundationdb store for SQL tests (the fdb select api version can only be run once per process)
|
||||
config_file = config_file.replace("foundationdb", "ignore");
|
||||
}
|
||||
let config = utils::config::Config::new(&config_file).unwrap();
|
||||
let stores = config.parse_stores().await.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user