Box large futures
This commit is contained in:
@@ -41,251 +41,244 @@ use serde_json::json;
|
||||
use std::{path::PathBuf, time::Instant};
|
||||
use utils::map::vec_map::VecMap;
|
||||
|
||||
#[test]
|
||||
fn imap_tests() {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.thread_stack_size(8 * 1024 * 1024) // 8MB stack
|
||||
.enable_all()
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
pub async fn imap_tests() {
|
||||
let mut test = TestServerBuilder::new("imap_tests")
|
||||
.await
|
||||
.with_default_listeners()
|
||||
.await
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
let mut test = TestServerBuilder::new("imap_tests")
|
||||
.await
|
||||
.with_default_listeners()
|
||||
.await
|
||||
.build()
|
||||
.await;
|
||||
.await;
|
||||
|
||||
// Create admin account
|
||||
let admin = test.create_admin_account("admin@example.com").await;
|
||||
// Create admin account
|
||||
let admin = test.create_admin_account("admin@example.com").await;
|
||||
|
||||
// Create test users
|
||||
for (name, secret, description, aliases) in [
|
||||
(
|
||||
"jdoe@example.com",
|
||||
"12345 + extra safety",
|
||||
"John Doe",
|
||||
&["john.doe@example.com"][..],
|
||||
),
|
||||
(
|
||||
"jane.smith@example.com",
|
||||
"abcde + extra safety",
|
||||
"Jane Smith",
|
||||
&["jane@example.com"][..],
|
||||
),
|
||||
(
|
||||
"foobar@example.com",
|
||||
"098765 + extra safety",
|
||||
"Bill Foobar",
|
||||
&["bill.foobar@example.com"][..],
|
||||
),
|
||||
(
|
||||
"popper@example.com",
|
||||
"a_pop3_safe_secret_with_extra_safety",
|
||||
"Karl Popper",
|
||||
&["karl.popper@example.com"][..],
|
||||
),
|
||||
(
|
||||
"sgd@example.com",
|
||||
"secret2 + extra safety",
|
||||
"Sigmund Gudmund Dudmundsson",
|
||||
&[][..],
|
||||
),
|
||||
(
|
||||
"spamtrap@example.com",
|
||||
"secret3 + extra safety",
|
||||
"Spam Trap",
|
||||
&[][..],
|
||||
),
|
||||
] {
|
||||
let account = admin
|
||||
.create_user_account(
|
||||
name,
|
||||
secret,
|
||||
description,
|
||||
aliases,
|
||||
vec![Permission::UnlimitedRequests, Permission::UnlimitedUploads],
|
||||
// Create test users
|
||||
for (name, secret, description, aliases) in [
|
||||
(
|
||||
"jdoe@example.com",
|
||||
"12345 + extra safety",
|
||||
"John Doe",
|
||||
&["john.doe@example.com"][..],
|
||||
),
|
||||
(
|
||||
"jane.smith@example.com",
|
||||
"abcde + extra safety",
|
||||
"Jane Smith",
|
||||
&["jane@example.com"][..],
|
||||
),
|
||||
(
|
||||
"foobar@example.com",
|
||||
"098765 + extra safety",
|
||||
"Bill Foobar",
|
||||
&["bill.foobar@example.com"][..],
|
||||
),
|
||||
(
|
||||
"popper@example.com",
|
||||
"a_pop3_safe_secret_with_extra_safety",
|
||||
"Karl Popper",
|
||||
&["karl.popper@example.com"][..],
|
||||
),
|
||||
(
|
||||
"sgd@example.com",
|
||||
"secret2 + extra safety",
|
||||
"Sigmund Gudmund Dudmundsson",
|
||||
&[][..],
|
||||
),
|
||||
(
|
||||
"spamtrap@example.com",
|
||||
"secret3 + extra safety",
|
||||
"Spam Trap",
|
||||
&[][..],
|
||||
),
|
||||
] {
|
||||
let account = admin
|
||||
.create_user_account(
|
||||
name,
|
||||
secret,
|
||||
description,
|
||||
aliases,
|
||||
vec![Permission::UnlimitedRequests, Permission::UnlimitedUploads],
|
||||
)
|
||||
.await;
|
||||
test.insert_account(account);
|
||||
}
|
||||
|
||||
// Create test group
|
||||
test.insert_account(
|
||||
admin
|
||||
.create_group_account("support@example.com", "Support Group", &[])
|
||||
.await,
|
||||
);
|
||||
|
||||
// Add Jane to the Support group
|
||||
let support_id = test.account("support@example.com").id();
|
||||
admin
|
||||
.registry_update_object(
|
||||
ObjectType::Account,
|
||||
test.account("jane.smith@example.com").id(),
|
||||
json!({
|
||||
"memberGroupIds": { support_id: true },
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
// Add test settings
|
||||
admin
|
||||
.registry_create_object(Imap {
|
||||
allow_plain_text_auth: true,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MtaStageAuth {
|
||||
require: Expression {
|
||||
else_: "false".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamClassifier {
|
||||
min_ham_samples: 10,
|
||||
min_spam_samples: 10,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(Email {
|
||||
default_folders: VecMap::from_iter(
|
||||
[
|
||||
(SpecialUse::Inbox, "Inbox"),
|
||||
(SpecialUse::Sent, "Sent Items"),
|
||||
(SpecialUse::Trash, "Deleted Items"),
|
||||
(SpecialUse::Junk, "Junk Mail"),
|
||||
(SpecialUse::Drafts, "Drafts"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(use_, name)| {
|
||||
(
|
||||
use_,
|
||||
EmailFolder {
|
||||
name: name.into(),
|
||||
subscribe: false,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await;
|
||||
test.insert_account(account);
|
||||
}
|
||||
}),
|
||||
),
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MtaStageData {
|
||||
add_delivered_to_header: false,
|
||||
enable_spam_filter: Expression {
|
||||
else_: "recipients[0] != 'popper@example.com'".into(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(10.0),
|
||||
tag: "PROB_SPAM_LOW".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(10.0),
|
||||
tag: "PROB_SPAM_HIGH".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(100.0),
|
||||
tag: "SPAM_TRAP".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MemoryLookupKey {
|
||||
is_glob_pattern: true,
|
||||
key: "spamtrap@*".into(),
|
||||
namespace: "spam-traps".into(),
|
||||
})
|
||||
.await;
|
||||
admin.reload_settings().await;
|
||||
admin.reload_lookup_stores().await;
|
||||
|
||||
// Create test group
|
||||
test.insert_account(
|
||||
admin
|
||||
.create_group_account("support@example.com", "Support Group", &[])
|
||||
.await,
|
||||
);
|
||||
test.insert_account(admin);
|
||||
|
||||
// Add Jane to the Support group
|
||||
let support_id = test.account("support@example.com").id();
|
||||
admin
|
||||
.registry_update_object(
|
||||
ObjectType::Account,
|
||||
test.account("jane.smith@example.com").id(),
|
||||
json!({
|
||||
"memberGroupIds": { support_id: true },
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
let start_time = Instant::now();
|
||||
|
||||
// Add test settings
|
||||
admin
|
||||
.registry_create_object(Imap {
|
||||
allow_plain_text_auth: true,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MtaStageAuth {
|
||||
require: Expression {
|
||||
else_: "false".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamClassifier {
|
||||
min_ham_samples: 10,
|
||||
min_spam_samples: 10,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(Email {
|
||||
default_folders: VecMap::from_iter(
|
||||
[
|
||||
(SpecialUse::Inbox, "Inbox"),
|
||||
(SpecialUse::Sent, "Sent Items"),
|
||||
(SpecialUse::Trash, "Deleted Items"),
|
||||
(SpecialUse::Junk, "Junk Mail"),
|
||||
(SpecialUse::Drafts, "Drafts"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(use_, name)| {
|
||||
(
|
||||
use_,
|
||||
EmailFolder {
|
||||
name: name.into(),
|
||||
subscribe: false,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
}),
|
||||
),
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MtaStageData {
|
||||
add_delivered_to_header: false,
|
||||
enable_spam_filter: Expression {
|
||||
else_: "recipients[0] != 'popper@example.com'".into(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(10.0),
|
||||
tag: "PROB_SPAM_LOW".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(10.0),
|
||||
tag: "PROB_SPAM_HIGH".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(SpamTag::Score(SpamTagScore {
|
||||
score: Float::new(100.0),
|
||||
tag: "SPAM_TRAP".into(),
|
||||
}))
|
||||
.await;
|
||||
admin
|
||||
.registry_create_object(MemoryLookupKey {
|
||||
is_glob_pattern: true,
|
||||
key: "spamtrap@*".into(),
|
||||
namespace: "spam-traps".into(),
|
||||
})
|
||||
.await;
|
||||
admin.reload_settings().await;
|
||||
admin.reload_lookup_stores().await;
|
||||
// Body structure tests
|
||||
body_structure::test();
|
||||
|
||||
test.insert_account(admin);
|
||||
// Connect to IMAP server
|
||||
let mut imap_check = ImapConnection::connect(b"_y ").await;
|
||||
let mut imap = ImapConnection::connect(b"_x ").await;
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.assert_read(Type::Untagged, ResponseType::Ok).await;
|
||||
}
|
||||
|
||||
let start_time = Instant::now();
|
||||
// Unauthenticated tests
|
||||
basic::test(&mut imap, &mut imap_check).await;
|
||||
|
||||
// Body structure tests
|
||||
body_structure::test();
|
||||
// Login
|
||||
let account = test.account("jdoe@example.com");
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.authenticate(account.name(), account.secret()).await;
|
||||
}
|
||||
|
||||
// Connect to IMAP server
|
||||
let mut imap_check = ImapConnection::connect(b"_y ").await;
|
||||
let mut imap = ImapConnection::connect(b"_x ").await;
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.assert_read(Type::Untagged, ResponseType::Ok).await;
|
||||
}
|
||||
// Delete folders
|
||||
for mailbox in ["Drafts", "Junk Mail", "Sent Items"] {
|
||||
imap.send(&format!("DELETE \"{}\"", mailbox)).await;
|
||||
imap.assert_read(Type::Tagged, ResponseType::Ok).await;
|
||||
}
|
||||
|
||||
// Unauthenticated tests
|
||||
basic::test(&mut imap, &mut imap_check).await;
|
||||
mailbox::test(&mut imap, &mut imap_check, &test).await;
|
||||
append::test(&mut imap, &mut imap_check, &test).await;
|
||||
search::test(&mut imap, &mut imap_check, &test).await;
|
||||
fetch::test(&mut imap, &mut imap_check).await;
|
||||
store::test(&mut imap, &mut imap_check, &test).await;
|
||||
copy_move::test(&mut imap, &mut imap_check).await;
|
||||
thread::test(&mut imap, &mut imap_check, &test).await;
|
||||
idle::test(&mut imap, &mut imap_check, false).await;
|
||||
condstore::test(&mut imap, &mut imap_check).await;
|
||||
acl::test(&mut imap, &mut imap_check, &test).await;
|
||||
|
||||
// Login
|
||||
let account = test.account("jdoe@example.com");
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.authenticate(account.name(), account.secret()).await;
|
||||
}
|
||||
// Logout
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.send("UNAUTHENTICATE").await;
|
||||
imap.assert_read(Type::Tagged, ResponseType::Ok).await;
|
||||
|
||||
// Delete folders
|
||||
for mailbox in ["Drafts", "Junk Mail", "Sent Items"] {
|
||||
imap.send(&format!("DELETE \"{}\"", mailbox)).await;
|
||||
imap.assert_read(Type::Tagged, ResponseType::Ok).await;
|
||||
}
|
||||
imap.send("LOGOUT").await;
|
||||
imap.assert_read(Type::Untagged, ResponseType::Bye).await;
|
||||
}
|
||||
|
||||
mailbox::test(&mut imap, &mut imap_check, &test).await;
|
||||
append::test(&mut imap, &mut imap_check, &test).await;
|
||||
search::test(&mut imap, &mut imap_check, &test).await;
|
||||
fetch::test(&mut imap, &mut imap_check).await;
|
||||
store::test(&mut imap, &mut imap_check, &test).await;
|
||||
copy_move::test(&mut imap, &mut imap_check).await;
|
||||
thread::test(&mut imap, &mut imap_check, &test).await;
|
||||
idle::test(&mut imap, &mut imap_check, false).await;
|
||||
condstore::test(&mut imap, &mut imap_check).await;
|
||||
acl::test(&mut imap, &mut imap_check, &test).await;
|
||||
// Antispam training
|
||||
antispam::test(&test).await;
|
||||
|
||||
// Logout
|
||||
for imap in [&mut imap, &mut imap_check] {
|
||||
imap.send("UNAUTHENTICATE").await;
|
||||
imap.assert_read(Type::Tagged, ResponseType::Ok).await;
|
||||
// Run ManageSieve tests
|
||||
managesieve::test(&test).await;
|
||||
|
||||
imap.send("LOGOUT").await;
|
||||
imap.assert_read(Type::Untagged, ResponseType::Bye).await;
|
||||
}
|
||||
// Run POP3 tests
|
||||
pop::test(&test).await;
|
||||
|
||||
// Antispam training
|
||||
antispam::test(&test).await;
|
||||
// Print elapsed time
|
||||
let elapsed = start_time.elapsed();
|
||||
println!(
|
||||
"Elapsed: {}.{:03}s",
|
||||
elapsed.as_secs(),
|
||||
elapsed.subsec_millis()
|
||||
);
|
||||
|
||||
// Run ManageSieve tests
|
||||
managesieve::test(&test).await;
|
||||
|
||||
// Run POP3 tests
|
||||
pop::test(&test).await;
|
||||
|
||||
// Print elapsed time
|
||||
let elapsed = start_time.elapsed();
|
||||
println!(
|
||||
"Elapsed: {}.{:03}s",
|
||||
elapsed.as_secs(),
|
||||
elapsed.subsec_millis()
|
||||
);
|
||||
|
||||
// Remove test data
|
||||
if test.is_reset() {
|
||||
test.temp_dir.delete();
|
||||
}
|
||||
});
|
||||
// Remove test data
|
||||
if test.is_reset() {
|
||||
test.temp_dir.delete();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expand_uid_list(list: &str) -> AHashSet<u32> {
|
||||
|
||||
Reference in New Issue
Block a user