diff options
| author | benj <benj@rse8.com> | 2022-12-21 16:23:12 -0800 |
|---|---|---|
| committer | benj <benj@rse8.com> | 2022-12-21 16:23:12 -0800 |
| commit | de6339da72af1d61ca5908b780977e2b037ce014 (patch) | |
| tree | 96add0e538cef4b6b5912492c28a3d5e9ed25cbe /crates/secd | |
| parent | a734a77520a3f9f0061e44c4fac6c42801730496 (diff) | |
| download | secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar.gz secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar.bz2 secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar.lz secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar.xz secdiam-de6339da72af1d61ca5908b780977e2b037ce014.tar.zst secdiam-de6339da72af1d61ca5908b780977e2b037ce014.zip | |
some cleanup
Diffstat (limited to '')
| -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 |
3 files changed, 43 insertions, 13 deletions
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(()) + } +} |
