Principal update API changes

This commit is contained in:
mdecimus
2024-02-24 20:22:34 +01:00
parent be7c4cca73
commit 044ecda98a
11 changed files with 193 additions and 2860 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
BASE_DIR="/tmp/stalwart-test"
BASE_DIR="/Users/me/Downloads/stalwart-test"
DOMAIN="example.org"
# Stores
@@ -24,7 +24,7 @@ SQL_STORE="sqlite"
rm -rf $BASE_DIR
# Create directories
mkdir -p $BASE_DIR $BASE_DIR/data $BASE_DIR/data/blobs $BASE_DIR/logs $BASE_DIR/reports $BASE_DIR/queue
mkdir -p $BASE_DIR $BASE_DIR/data $BASE_DIR/data/blobs $BASE_DIR/logs
# Copy config files
cp -r resources/config $BASE_DIR/etc
@@ -40,7 +40,7 @@ sed -i '' -e 's/disable = true//g' "$BASE_DIR/etc/store/$STORE.toml"
sed -i '' -e 's/disable = true//g' "$BASE_DIR/etc/store/$FTS_STORE.toml"
sed -i '' -e 's/disable = true//g' "$BASE_DIR/etc/store/$BLOB_STORE.toml"
sed -i '' -e "s/__FTS_STORE__/$FTS_STORE/g" \
-e "s/__BLOB_STORE__/$BLOB_STORE/g" "$BASE_DIR/etc/jmap/store.toml"
-e "s/__BLOB_STORE__/$BLOB_STORE/g" "$BASE_DIR/etc/common/store.toml"
# Replace settings
sed -i '' -e "s/__STORE__/$STORE/g" \
@@ -64,5 +64,5 @@ mkdir -p $BASE_DIR/etc/dkim
openssl genpkey -algorithm RSA -out $BASE_DIR/etc/dkim/$DOMAIN.key
# Create admin user
SET_ADMIN_USER="admin" SET_ADMIN_PASS="secret" cargo run -p mail-server --no-default-features --features "$FEATURES" -- --config=/tmp/stalwart-test/etc/config.toml
cargo run -p mail-server --no-default-features --features "$FEATURES" -- --config=/tmp/stalwart-test/etc/config.toml
SET_ADMIN_USER="admin" SET_ADMIN_PASS="secret" cargo run -p mail-server --no-default-features --features "$FEATURES" -- --config=$BASE_DIR/etc/config.toml
cargo run -p mail-server --no-default-features --features "$FEATURES" -- --config=$BASE_DIR/etc/config.toml

View File

@@ -48,7 +48,7 @@ async fn internal_directory() {
// A principal without name should fail
assert_eq!(
store.create_account(Principal::default()).await,
store.create_account(Principal::default(), vec![]).await,
Err(DirectoryError::Management(ManagementError::MissingField(
PrincipalField::Name
)))
@@ -57,12 +57,15 @@ async fn internal_directory() {
// Basic account creation
assert_eq!(
store
.create_account(Principal {
name: "john".to_string(),
description: Some("John Doe".to_string()),
secrets: vec!["secret".to_string(), "secret2".to_string()],
..Default::default()
})
.create_account(
Principal {
name: "john".to_string(),
description: Some("John Doe".to_string()),
secrets: vec!["secret".to_string(), "secret2".to_string()],
..Default::default()
},
vec![]
)
.await,
Ok(0)
);
@@ -70,10 +73,13 @@ async fn internal_directory() {
// Two accounts with the same name should fail
assert_eq!(
store
.create_account(Principal {
name: "john".to_string(),
..Default::default()
})
.create_account(
Principal {
name: "john".to_string(),
..Default::default()
},
vec![]
)
.await,
Err(DirectoryError::Management(ManagementError::AlreadyExists {
field: PrincipalField::Name,
@@ -84,11 +90,14 @@ async fn internal_directory() {
// An account using a non-existent domain should fail
assert_eq!(
store
.create_account(Principal {
name: "jane".to_string(),
emails: vec!["jane@example.org".to_string()],
..Default::default()
})
.create_account(
Principal {
name: "jane".to_string(),
emails: vec!["jane@example.org".to_string()],
..Default::default()
},
vec![]
)
.await,
Err(DirectoryError::Management(ManagementError::NotFound(
"example.org".to_string()
@@ -138,14 +147,17 @@ async fn internal_directory() {
// Create an account with an email address
assert_eq!(
store
.create_account(Principal {
name: "jane".to_string(),
description: Some("Jane Doe".to_string()),
secrets: vec!["my_secret".to_string(), "my_secret2".to_string()],
emails: vec!["jane@example.org".to_string()],
quota: 123,
..Default::default()
})
.create_account(
Principal {
name: "jane".to_string(),
description: Some("Jane Doe".to_string()),
secrets: vec!["my_secret".to_string(), "my_secret2".to_string()],
emails: vec!["jane@example.org".to_string()],
quota: 123,
..Default::default()
},
vec![]
)
.await,
Ok(1)
);
@@ -194,12 +206,15 @@ async fn internal_directory() {
// Duplicate email address should fail
assert_eq!(
store
.create_account(Principal {
name: "janeth".to_string(),
description: Some("Janeth Doe".to_string()),
emails: vec!["jane@example.org".to_string()],
..Default::default()
})
.create_account(
Principal {
name: "janeth".to_string(),
description: Some("Janeth Doe".to_string()),
emails: vec!["jane@example.org".to_string()],
..Default::default()
},
vec![]
)
.await,
Err(DirectoryError::Management(ManagementError::AlreadyExists {
field: PrincipalField::Emails,
@@ -210,12 +225,15 @@ async fn internal_directory() {
// Create a mailing list
assert_eq!(
store
.create_account(Principal {
name: "list".to_string(),
typ: Type::List,
emails: vec!["list@example.org".to_string()],
..Default::default()
})
.create_account(
Principal {
name: "list".to_string(),
typ: Type::List,
emails: vec!["list@example.org".to_string()],
..Default::default()
},
vec![]
)
.await,
Ok(2)
);
@@ -258,23 +276,29 @@ async fn internal_directory() {
// Create groups
assert_eq!(
store
.create_account(Principal {
name: "sales".to_string(),
description: Some("Sales Team".to_string()),
typ: Type::Group,
..Default::default()
})
.create_account(
Principal {
name: "sales".to_string(),
description: Some("Sales Team".to_string()),
typ: Type::Group,
..Default::default()
},
vec![]
)
.await,
Ok(3)
);
assert_eq!(
store
.create_account(Principal {
name: "support".to_string(),
description: Some("Support Team".to_string()),
typ: Type::Group,
..Default::default()
})
.create_account(
Principal {
name: "support".to_string(),
description: Some("Support Team".to_string()),
typ: Type::Group,
..Default::default()
},
vec![]
)
.await,
Ok(4)
);