diff options
| -rw-r--r-- | Cargo.lock | 10 | ||||
| -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 |
6 files changed, 47 insertions, 26 deletions
@@ -1548,7 +1548,6 @@ name = "secd" version = "0.1.0" dependencies = [ "anyhow", - "async-std", "async-trait", "base64", "clap", @@ -1566,6 +1565,7 @@ dependencies = [ "strum_macros", "thiserror", "time", + "tokio", "url", "uuid", ] @@ -1731,8 +1731,6 @@ dependencies = [ [[package]] name = "sqlx" version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" dependencies = [ "sqlx-core", "sqlx-macros", @@ -1741,8 +1739,6 @@ dependencies = [ [[package]] name = "sqlx-core" version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" dependencies = [ "ahash", "atoi", @@ -1795,8 +1791,6 @@ dependencies = [ [[package]] name = "sqlx-macros" version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" dependencies = [ "dotenvy", "either", @@ -1814,8 +1808,6 @@ dependencies = [ [[package]] name = "sqlx-rt" version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" dependencies = [ "async-native-tls", "async-std", 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(()) + } +} |
