diff --git a/Cargo.lock b/Cargo.lock index e6fff7b..29a0199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -472,17 +472,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -695,26 +684,24 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "4.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3" dependencies = [ - "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", + "is-terminal", "once_cell", "strsim", "termcolor", - "textwrap 0.16.0", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck 0.4.1", "proc-macro-error", @@ -725,9 +712,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" dependencies = [ "os_str_bytes", ] @@ -1125,10 +1112,10 @@ dependencies = [ ] [[package]] -name = "difference" -version = "2.0.0" +name = "difflib" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" [[package]] name = "digest" @@ -1200,9 +1187,9 @@ checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" [[package]] name = "downcast" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d" +checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "either" @@ -1235,6 +1222,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -1313,9 +1321,9 @@ dependencies = [ [[package]] name = "float-cmp" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" dependencies = [ "num-traits", ] @@ -1347,15 +1355,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fragile" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7464c5c4a3f014d9b2ec4073650e5c06596f385060af740fc45ad5a19f959e8" -dependencies = [ - "fragile 2.0.0", -] - [[package]] name = "fragile" version = "2.0.0" @@ -1755,15 +1754,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.2.6" @@ -1773,6 +1763,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -2001,12 +1997,34 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "ipnet" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -2265,6 +2283,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lldap" version = "0.4.2-alpha" @@ -2504,13 +2528,13 @@ dependencies = [ [[package]] name = "mockall" -version = "0.9.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d614ad23f9bb59119b8b5670a85c7ba92c5e9adf4385c81ea00c51c8be33d5" +checksum = "50e4a1c770583dac7ab5e2f6c139153b783a53a1bbee9729613f193e59828326" dependencies = [ "cfg-if", "downcast", - "fragile 1.2.2", + "fragile", "lazy_static", "mockall_derive", "predicates", @@ -2519,9 +2543,9 @@ dependencies = [ [[package]] name = "mockall_derive" -version = "0.9.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd4234635bca06fc96c7368d038061e0aae1b00a764dc817e900dc974e3deea" +checksum = "832663583d5fa284ca8810bf7015e46c9fff9622d3cf34bd1eea5003fec06dd0" dependencies = [ "cfg-if", "proc-macro2", @@ -2943,12 +2967,13 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "predicates" -version = "1.0.8" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ - "difference", + "difflib", "float-cmp", + "itertools", "normalize-line-endings", "predicates-core", "regex", @@ -3177,7 +3202,7 @@ dependencies = [ "bitflags", "crossterm", "once_cell", - "textwrap 0.15.2", + "textwrap", "unicode-segmentation", ] @@ -3291,6 +3316,20 @@ dependencies = [ "nom 7.1.3", ] +[[package]] +name = "rustix" +version = "0.36.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "rustls" version = "0.20.8" @@ -3836,9 +3875,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.108" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56e159d99e6c2b93995d171050271edb50ecc5288fbc7cc17de8fdce4e58c14" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -3897,12 +3936,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.38" diff --git a/server/Cargo.toml b/server/Cargo.toml index 94ee525..309a4a7 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -54,7 +54,7 @@ version = "*" [dependencies.clap] features = ["std", "color", "suggestions", "derive", "env"] -version = "3.1.15" +version = "4" [dependencies.figment] features = ["env", "toml"] @@ -115,4 +115,4 @@ default-features = false features = ["rustls-tls-webpki-roots"] [dev-dependencies] -mockall = "0.9.1" +mockall = "0.11" diff --git a/server/src/infra/cli.rs b/server/src/infra/cli.rs index ab1ba42..0b373a7 100644 --- a/server/src/infra/cli.rs +++ b/server/src/infra/cli.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{builder::EnumValueParser, Parser}; use lettre::message::Mailbox; use serde::{Deserialize, Serialize}; @@ -95,7 +95,7 @@ pub struct TestEmailOpts { } #[derive(Debug, Parser, Clone)] -#[clap(next_help_heading = Some("LDAPS"), setting = clap::AppSettings::DeriveDisplayOrder)] +#[clap(next_help_heading = Some("LDAPS"))] pub struct LdapsOpts { /// Enable LDAPS. Default: false. #[clap(long, env = "LLDAP_LDAPS_OPTIONS__ENABLED")] @@ -114,17 +114,16 @@ pub struct LdapsOpts { pub ldaps_key_file: Option, } -clap::arg_enum! { -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize, clap::ValueEnum)] +#[serde(rename_all = "UPPERCASE")] pub enum SmtpEncryption { - NONE, - TLS, - STARTTLS, -} + None, + Tls, + StartTls, } #[derive(Debug, Parser, Clone)] -#[clap(next_help_heading = Some("SMTP"), setting = clap::AppSettings::DeriveDisplayOrder)] +#[clap(next_help_heading = Some("SMTP"))] pub struct SmtpOpts { /// Sender email address. #[clap(long, env = "LLDAP_SMTP_OPTIONS__FROM")] @@ -151,10 +150,10 @@ pub struct SmtpOpts { pub smtp_password: Option, /// Whether TLS should be used to connect to SMTP. - #[clap(long, env = "LLDAP_SMTP_OPTIONS__TLS_REQUIRED", setting=clap::ArgSettings::Hidden)] + #[clap(long, env = "LLDAP_SMTP_OPTIONS__TLS_REQUIRED", hide = true)] pub smtp_tls_required: Option, - #[clap(long, env = "LLDAP_SMTP_OPTIONS__ENCRYPTION", possible_values = SmtpEncryption::variants(), case_insensitive = true)] + #[clap(long, env = "LLDAP_SMTP_OPTIONS__ENCRYPTION", value_parser = EnumValueParser::::new(), ignore_case = true)] pub smtp_encryption: Option, } diff --git a/server/src/infra/configuration.rs b/server/src/infra/configuration.rs index 11e517c..f5e805a 100644 --- a/server/src/infra/configuration.rs +++ b/server/src/infra/configuration.rs @@ -29,7 +29,7 @@ pub struct MailOptions { pub user: String, #[builder(default = r#"SecUtf8::from("")"#)] pub password: SecUtf8, - #[builder(default = "SmtpEncryption::TLS")] + #[builder(default = "SmtpEncryption::Tls")] pub smtp_encryption: SmtpEncryption, /// Deprecated. #[builder(default = "None")] diff --git a/server/src/infra/mail.rs b/server/src/infra/mail.rs index e446f58..d71760e 100644 --- a/server/src/infra/mail.rs +++ b/server/src/infra/mail.rs @@ -27,11 +27,11 @@ async fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOpti .body(body), )?; let mut mailer = match options.smtp_encryption { - SmtpEncryption::NONE => { + SmtpEncryption::None => { AsyncSmtpTransport::::builder_dangerous(&options.server) } - SmtpEncryption::TLS => AsyncSmtpTransport::::relay(&options.server)?, - SmtpEncryption::STARTTLS => { + SmtpEncryption::Tls => AsyncSmtpTransport::::relay(&options.server)?, + SmtpEncryption::StartTls => { AsyncSmtpTransport::::starttls_relay(&options.server)? } }; diff --git a/server/src/infra/tcp_backend_handler.rs b/server/src/infra/tcp_backend_handler.rs index c153a96..e01e531 100644 --- a/server/src/infra/tcp_backend_handler.rs +++ b/server/src/infra/tcp_backend_handler.rs @@ -20,44 +20,3 @@ pub trait TcpBackendHandler: Sync { async fn delete_password_reset_token(&self, token: &str) -> Result<()>; } - -#[cfg(test)] -use crate::domain::{handler::*, types::*}; -#[cfg(test)] -mockall::mock! { - pub TestTcpBackendHandler{} - impl Clone for TestTcpBackendHandler { - fn clone(&self) -> Self; - } - #[async_trait] - impl LoginHandler for TestTcpBackendHandler { - async fn bind(&self, request: BindRequest) -> Result<()>; - } - #[async_trait] - impl GroupListerBackendHandler for TestTcpBackendHandler { - async fn list_groups(&self, filters: Option) -> Result>; - } - #[async_trait] - impl GroupBackendHandler for TestTcpBackendHandler { - async fn get_group_details(&self, group_id: GroupId) -> Result; - async fn update_group(&self, request: UpdateGroupRequest) -> Result<()>; - async fn create_group(&self, group_name: &str) -> Result; - async fn delete_group(&self, group_id: GroupId) -> Result<()>; - } - #[async_trait] - impl UserListerBackendHandler for TestBackendHandler { - async fn list_users(&self, filters: Option, get_groups: bool) -> Result>; - } - #[async_trait] - impl UserBackendHandler for TestBackendHandler { - async fn get_user_details(&self, user_id: &UserId) -> Result; - async fn create_user(&self, request: CreateUserRequest) -> Result<()>; - async fn update_user(&self, request: UpdateUserRequest) -> Result<()>; - async fn delete_user(&self, user_id: &UserId) -> Result<()>; - async fn get_user_groups(&self, user_id: &UserId) -> Result>; - async fn add_user_to_group(&self, user_id: &UserId, group_id: GroupId) -> Result<()>; - async fn remove_user_from_group(&self, user_id: &UserId, group_id: GroupId) -> Result<()>; - } - #[async_trait] - impl BackendHandler for TestTcpBackendHandler {} -}