diff options
Diffstat (limited to '')
| -rw-r--r-- | crates/iam/src/command.rs | 5 | ||||
| -rw-r--r-- | crates/iam/src/main.rs | 2 | ||||
| -rw-r--r-- | crates/secd/Cargo.toml | 6 | ||||
| -rw-r--r-- | crates/secd/src/command/authn.rs | 15 | ||||
| -rw-r--r-- | crates/secd/tests/authn_integration.rs | 35 |
5 files changed, 46 insertions, 17 deletions
diff --git a/crates/iam/src/command.rs b/crates/iam/src/command.rs index 980c4d0..379e7fb 100644 --- a/crates/iam/src/command.rs +++ b/crates/iam/src/command.rs @@ -3,12 +3,11 @@ use crate::{ util::{self, error_detail, get_config_profile, Result}, CONFIG_LOGIN_TEMPLATE, CONFIG_SIGNUP_TEMPLATE, }; -use async_std::fs; use colored::*; use rand::distributions::{Alphanumeric, DistString}; use secd::{AuthEmail, AuthStore}; use std::{ - fs::File, + fs::{self, File}, io::{self, stdin, stdout, Read, Write}, net::TcpListener, str::{self, FromStr}, @@ -23,7 +22,7 @@ const DEFAULT_SIGNUP_EMAIL: &str = "<!doctype html><html><body><h1>Welcome to Se pub async fn admin_init(is_interactive: bool) -> Result<()> { let config_dir = util::get_config_dir(); let config_profile = get_config_profile(); - fs::create_dir_all(config_dir.clone()).await?; + fs::create_dir_all(config_dir.clone()); if config_profile.try_exists()? { writeln!( diff --git a/crates/iam/src/main.rs b/crates/iam/src/main.rs index 90a14af..4f6316a 100644 --- a/crates/iam/src/main.rs +++ b/crates/iam/src/main.rs @@ -163,7 +163,7 @@ async fn create(secd: &Secd, cmd: CreateObject) -> Result<Option<String>> { } CreateObject::Validation { method, identity } => match method { ValidationMethod::Email { address } => serde_json::to_string(&Validation { - validation_id: secd.create_validation_request_email(Some(&address)).await?, + validation_id: secd.create_validation_request_email(&address).await?, note: Some("<secret code> sent to client".into()), oauth_auth_url: None, }) diff --git a/crates/secd/Cargo.toml b/crates/secd/Cargo.toml index d65bf51..069e41e 100644 --- a/crates/secd/Cargo.toml +++ b/crates/secd/Cargo.toml @@ -4,8 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -async-std = { version = "1.12.0", features = [ "attributes" ] } -async-trait = "0.1" +async-trait = "0.1.59" anyhow = "1.0" base64 = "0.13.1" clap = { version = "4.0.29", features = ["derive"] } @@ -20,8 +19,9 @@ serde = "1" serde_json = { version = "1.0", features = ["raw_value"] } strum = "0.24.1" strum_macros = "0.24" -sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls", "postgres", "uuid", "sqlite", "time" ] } +sqlx = { path = "../../../sqlx", features = [ "runtime-async-std-native-tls", "postgres", "uuid", "sqlite", "time" ] } time = { version = "0.3", features = [ "serde" ] } thiserror = "1.0" +tokio = { version = "1.23.0", feautres = ["rt", "macros"] } url = "2.3.1" uuid = { version = "1.2", features = ["v4", "serde"]}
\ No newline at end of file diff --git a/crates/secd/src/command/authn.rs b/crates/secd/src/command/authn.rs index b254614..9c2babe 100644 --- a/crates/secd/src/command/authn.rs +++ b/crates/secd/src/command/authn.rs @@ -61,19 +61,14 @@ impl Secd { /// Generate a request to validate the provided email. pub async fn create_validation_request_email( &self, - email: Option<&str>, + email: &str, ) -> Result<ValidationRequestId, SecdError> { let now = OffsetDateTime::now_utc(); - let email = match email { - Some(ea) => { - if EmailAddress::is_valid(ea) { - ea - } else { - return Err(SecdError::InvalidEmailAddress); - } - } - None => return Err(SecdError::InvalidEmailAddress), + let email = if EmailAddress::is_valid(email) { + email + } else { + return Err(SecdError::InvalidEmailAddress); }; let mut ev = EmailValidation { diff --git a/crates/secd/tests/authn_integration.rs b/crates/secd/tests/authn_integration.rs new file mode 100644 index 0000000..d823d5a --- /dev/null +++ b/crates/secd/tests/authn_integration.rs @@ -0,0 +1,35 @@ +#[cfg(test)] +mod test { + use std::error::Error; + + use secd::{AuthEmail, AuthStore, Secd}; + + #[tokio::test] + async fn email_authentication_int() -> Result<(), Box<dyn Error>> { + let secd = Secd::init(AuthStore::Sqlite, None, AuthEmail::LocalStub, None, None).await?; + let v_id = secd.create_validation_request_email("b@g.com").await?; + + // TODO: in memory mailbox backed by sqlite which just throws them in temporarily... + // and then I can grab it? + + // Things to test + // 1. after exchanging the session, I cannot get it again + // 1. a validation can only be used once + // 1. a session can be used to retrieve identity information + assert_eq!(1, 2); + Ok(()) + } + + #[tokio::test] + async fn oauth_authentication_int() -> Result<(), Box<dyn Error>> { + let secd = Secd::init(AuthStore::Sqlite, None, AuthEmail::LocalStub, None, None).await?; + + // Things to test + // 1. after exchanging the session, I cannot get it again + // 1. a validation can only be used once + // 1. a session can be used to retrieve identity information + // 1. an oauth session links with an existing emails session + assert_eq!(1, 2); + Ok(()) + } +} |
