aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-12-27 18:33:06 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-12-27 18:33:06 +0100
commitccc9b6abb66ebda0b91b4e21f8ec2fb2e87390f7 (patch)
tree985f9d136a981ec7cc43984c976c60e9295340d5
parent7744625c18aff5990a792bb13a44b60d8c4d4fc5 (diff)
downloadaerogramme-ccc9b6abb66ebda0b91b4e21f8ec2fb2e87390f7.tar.gz
aerogramme-ccc9b6abb66ebda0b91b4e21f8ec2fb2e87390f7.zip
add a --dev mode
-rw-r--r--src/config.rs1
-rw-r--r--src/login/demo_provider.rs48
-rw-r--r--src/login/mod.rs1
-rw-r--r--src/main.rs26
-rw-r--r--src/server.rs3
-rw-r--r--tests/instrumentation/README.md (renamed from tests/README.md)0
-rw-r--r--tests/instrumentation/docker-compose.yml (renamed from tests/docker-compose.yml)0
-rw-r--r--tests/instrumentation/docker/cyrus/Dockerfile (renamed from tests/docker/cyrus/Dockerfile)0
-rwxr-xr-xtests/instrumentation/docker/cyrus/entrypoint.sh (renamed from tests/docker/cyrus/entrypoint.sh)0
-rw-r--r--tests/instrumentation/docker/maddy/Dockerfile (renamed from tests/docker/maddy/Dockerfile)0
-rwxr-xr-xtests/instrumentation/docker/maddy/entrypoint.sh (renamed from tests/docker/maddy/entrypoint.sh)0
-rwxr-xr-xtests/instrumentation/inject_emails.sh (renamed from tests/inject_emails.sh)0
-rw-r--r--tests/instrumentation/rm-mail-parser-expected-struct.py (renamed from tests/rm-mail-parser-expected-struct.py)0
-rw-r--r--tests/instrumentation/send-to-imap.py (renamed from tests/send-to-imap.py)0
-rwxr-xr-xtests/instrumentation/unix2dos.py (renamed from tests/unix2dos.py)0
15 files changed, 75 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs
index 1438910..b9c1f09 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -26,6 +26,7 @@ pub struct ProviderConfig {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "user_driver")]
pub enum UserManagement {
+ Demo,
Static(LoginStaticConfig),
Ldap(LoginLdapConfig),
}
diff --git a/src/login/demo_provider.rs b/src/login/demo_provider.rs
new file mode 100644
index 0000000..0efb37c
--- /dev/null
+++ b/src/login/demo_provider.rs
@@ -0,0 +1,48 @@
+use crate::login::*;
+use crate::storage::*;
+
+pub struct DemoLoginProvider{
+ keys: CryptoKeys,
+ in_memory_store: in_memory::MemDb,
+}
+
+impl DemoLoginProvider {
+ pub fn new() -> Self {
+ Self {
+ keys: CryptoKeys::init(),
+ in_memory_store: in_memory::MemDb::new(),
+ }
+ }
+}
+
+#[async_trait]
+impl LoginProvider for DemoLoginProvider {
+ async fn login(&self, username: &str, password: &str) -> Result<Credentials> {
+ tracing::debug!(user=%username, "login");
+
+ if username != "alice" {
+ bail!("user does not exist");
+ }
+
+ if password != "hunter2" {
+ bail!("wrong password");
+ }
+
+ let storage = self.in_memory_store.builder("alice").await;
+ let keys = self.keys.clone();
+
+ Ok(Credentials { storage, keys })
+ }
+
+ async fn public_login(&self, email: &str) -> Result<PublicCredentials> {
+ tracing::debug!(user=%email, "public_login");
+ if email != "alice@example.tld" {
+ bail!("invalid email address");
+ }
+
+ let storage = self.in_memory_store.builder("alice").await;
+ let public_key = self.keys.public.clone();
+
+ Ok(PublicCredentials { storage, public_key })
+ }
+}
diff --git a/src/login/mod.rs b/src/login/mod.rs
index 2926738..6f2ca31 100644
--- a/src/login/mod.rs
+++ b/src/login/mod.rs
@@ -1,5 +1,6 @@
pub mod ldap_provider;
pub mod static_provider;
+pub mod demo_provider;
use base64::Engine;
use std::sync::Arc;
diff --git a/src/main.rs b/src/main.rs
index 3221c2e..3baa8e2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,7 +29,12 @@ struct Args {
#[clap(subcommand)]
command: Command,
+ /// A special mode dedicated to developers, NOT INTENDED FOR PRODUCTION
+ #[clap(long)]
+ dev: bool,
+
#[clap(short, long, env = "CONFIG_FILE", default_value = "aerogramme.toml")]
+ /// Path to the main Aerogramme configuration file
config_file: PathBuf,
}
@@ -158,7 +163,22 @@ async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let args = Args::parse();
- let any_config = read_config(args.config_file)?;
+ let any_config = if args.dev {
+ use std::net::*;
+ AnyConfig::Provider(ProviderConfig {
+ pid: None,
+ imap: ImapConfig {
+ bind_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 1143),
+ },
+ lmtp: LmtpConfig {
+ bind_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 1025),
+ hostname: "example.tld".to_string(),
+ },
+ users: UserManagement::Demo,
+ })
+ } else {
+ read_config(args.config_file)?
+ };
match (&args.command, any_config) {
(Command::Companion(subcommand), AnyConfig::Companion(config)) => match subcommand {
@@ -184,8 +204,8 @@ async fn main() -> Result<()> {
ProviderCommand::Account(cmd) => {
let user_file = match config.users {
UserManagement::Static(conf) => conf.user_list,
- UserManagement::Ldap(_) => {
- panic!("LDAP account management is not supported from Aerogramme.")
+ _ => {
+ panic!("Only static account management is supported from Aerogramme.")
}
};
account_management(&args.command, cmd, user_file)?;
diff --git a/src/server.rs b/src/server.rs
index 28e0b27..1b8677b 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -11,7 +11,7 @@ use crate::config::*;
use crate::imap;
use crate::lmtp::*;
use crate::login::ArcLoginProvider;
-use crate::login::{ldap_provider::*, static_provider::*};
+use crate::login::{ldap_provider::*, static_provider::*, demo_provider::*};
pub struct Server {
lmtp_server: Option<Arc<LmtpServer>>,
@@ -36,6 +36,7 @@ impl Server {
pub async fn from_provider_config(config: ProviderConfig) -> Result<Self> {
tracing::info!("Init as provider");
let login: ArcLoginProvider = match config.users {
+ UserManagement::Demo => Arc::new(DemoLoginProvider::new()),
UserManagement::Static(x) => Arc::new(StaticLoginProvider::new(x).await?),
UserManagement::Ldap(x) => Arc::new(LdapLoginProvider::new(x)?),
};
diff --git a/tests/README.md b/tests/instrumentation/README.md
index b479cf4..b479cf4 100644
--- a/tests/README.md
+++ b/tests/instrumentation/README.md
diff --git a/tests/docker-compose.yml b/tests/instrumentation/docker-compose.yml
index 6a112bb..6a112bb 100644
--- a/tests/docker-compose.yml
+++ b/tests/instrumentation/docker-compose.yml
diff --git a/tests/docker/cyrus/Dockerfile b/tests/instrumentation/docker/cyrus/Dockerfile
index 67b4e11..67b4e11 100644
--- a/tests/docker/cyrus/Dockerfile
+++ b/tests/instrumentation/docker/cyrus/Dockerfile
diff --git a/tests/docker/cyrus/entrypoint.sh b/tests/instrumentation/docker/cyrus/entrypoint.sh
index c410e9d..c410e9d 100755
--- a/tests/docker/cyrus/entrypoint.sh
+++ b/tests/instrumentation/docker/cyrus/entrypoint.sh
diff --git a/tests/docker/maddy/Dockerfile b/tests/instrumentation/docker/maddy/Dockerfile
index 341e398..341e398 100644
--- a/tests/docker/maddy/Dockerfile
+++ b/tests/instrumentation/docker/maddy/Dockerfile
diff --git a/tests/docker/maddy/entrypoint.sh b/tests/instrumentation/docker/maddy/entrypoint.sh
index f875624..f875624 100755
--- a/tests/docker/maddy/entrypoint.sh
+++ b/tests/instrumentation/docker/maddy/entrypoint.sh
diff --git a/tests/inject_emails.sh b/tests/instrumentation/inject_emails.sh
index a021170..a021170 100755
--- a/tests/inject_emails.sh
+++ b/tests/instrumentation/inject_emails.sh
diff --git a/tests/rm-mail-parser-expected-struct.py b/tests/instrumentation/rm-mail-parser-expected-struct.py
index 3dbc56e..3dbc56e 100644
--- a/tests/rm-mail-parser-expected-struct.py
+++ b/tests/instrumentation/rm-mail-parser-expected-struct.py
diff --git a/tests/send-to-imap.py b/tests/instrumentation/send-to-imap.py
index df49076..df49076 100644
--- a/tests/send-to-imap.py
+++ b/tests/instrumentation/send-to-imap.py
diff --git a/tests/unix2dos.py b/tests/instrumentation/unix2dos.py
index 4e6c9cf..4e6c9cf 100755
--- a/tests/unix2dos.py
+++ b/tests/instrumentation/unix2dos.py