aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbenj <benj@rse8.com>2022-12-21 16:23:12 -0800
committerbenj <benj@rse8.com>2022-12-21 16:23:12 -0800
commitde6339da72af1d61ca5908b780977e2b037ce014 (patch)
tree96add0e538cef4b6b5912492c28a3d5e9ed25cbe /crates
parenta734a77520a3f9f0061e44c4fac6c42801730496 (diff)
downloadsecdiam-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/iam/src/command.rs5
-rw-r--r--crates/iam/src/main.rs2
-rw-r--r--crates/secd/Cargo.toml6
-rw-r--r--crates/secd/src/command/authn.rs15
-rw-r--r--crates/secd/tests/authn_integration.rs35
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(())
+ }
+}