Skip to content

Commit

Permalink
feat: add VerificationState to agent_store (#36)
Browse files Browse the repository at this point in the history
* refactor: move `ApplicationState` to `agent_shared`

* feat: add `agent_verification`

* style: rename `AuthorizationRequestTestFramework` to `ConnectionTestFramework`

* refactor: remove `ApplicationState` struct and replace it for a tuple

* fix: remove `ConnectionNotificationSent`

Instead of using the `VerificationServices` for sending connection notifications
we will probably need to utilize a `Query` that will function as an
outgoing adapter.

* feat: add `VerificationState` to `ApplicationState`

* feat: add `authorization_request` and `connection` tables to `init.sql`
  • Loading branch information
nanderstabel authored Mar 22, 2024
1 parent a5b723e commit 96df010
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion agent_api_rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@ rust-version.workspace = true
[dependencies]
agent_issuance = { path = "../agent_issuance" }
agent_shared = { path = "../agent_shared" }
agent_verification = { path = "../agent_verification" }

axum.workspace = true
axum-auth = "0.7"
axum-macros = "0.4"
http-api-problem = "0.57"
hyper = { version = "1.2" }
oid4vc-core.workspace = true
oid4vci.workspace = true
serde.workspace = true
serde_json.workspace = true
siopv2.workspace = true
tower-http.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid = { version = "1.4", features = ["v4", "fast-rng", "serde"] }
uuid.workspace = true

[dev-dependencies]
agent_shared = { path = "../agent_shared", features = ["test"] }
agent_store = { path = "../agent_store" }
agent_verification = { path = "../agent_verification", features = ["test"] }

futures.workspace = true
lazy_static.workspace = true
mime = { version = "0.3" }
oid4vc-core.workspace = true
oid4vc-manager.workspace = true
serde_urlencoded = "0.7"
tokio.workspace = true
tower = { version = "0.4" }
tracing-test.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion agent_api_rest/src/issuance/credential_issuer/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod tests {
use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand All @@ -103,10 +104,11 @@ mod tests {
#[tracing_test::traced_test]
async fn test_credential_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

credentials(&mut app).await;
let pre_authorized_code = offers(&mut app).await;
Expand Down
4 changes: 3 additions & 1 deletion agent_api_rest/src/issuance/credential_issuer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub mod tests {
use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand Down Expand Up @@ -102,10 +103,11 @@ pub mod tests {
#[tokio::test]
async fn test_token_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

credentials(&mut app).await;
let pre_authorized_code = offers(&mut app).await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod tests {
use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand Down Expand Up @@ -69,10 +70,11 @@ mod tests {
#[tokio::test]
async fn test_oauth_authorization_server_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

let _authorization_server_metadata = oauth_authorization_server(&mut app).await;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod tests {
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_shared::{config, UrlAppendHelpers};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand Down Expand Up @@ -105,10 +106,11 @@ mod tests {
#[tokio::test]
async fn test_oauth_authorization_server_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

let _credential_issuer_metadata = openid_credential_issuer(&mut app).await;
}
Expand Down
16 changes: 4 additions & 12 deletions agent_api_rest/src/issuance/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub mod tests {
};
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand Down Expand Up @@ -178,17 +179,7 @@ pub mod tests {
.method(http::Method::GET)
.uri(get_credentials_endpoint)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.body(Body::from(
serde_json::to_vec(&json!({
"subjectId": SUBJECT_ID,
"credential": {
"credentialSubject": {
"first_name": "Ferris",
"last_name": "Rustacean"
}},
}))
.unwrap(),
))
.body(Body::empty())
.unwrap(),
)
.await
Expand All @@ -204,10 +195,11 @@ pub mod tests {
#[tokio::test]
async fn test_credentials_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

credentials(&mut app).await;
}
Expand Down
4 changes: 3 additions & 1 deletion agent_api_rest/src/issuance/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub mod tests {
use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
body::Body,
http::{self, Request},
Expand Down Expand Up @@ -117,10 +118,11 @@ pub mod tests {
#[tokio::test]
async fn test_offers_endpoint() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

let mut app = app((issuance_state, ()));
let mut app = app((issuance_state, verification_state));

credentials(&mut app).await;
let _pre_authorized_code = offers(&mut app).await;
Expand Down
7 changes: 5 additions & 2 deletions agent_api_rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod issuance;

use agent_issuance::state::IssuanceState;
use agent_shared::{config, ConfigError};
use agent_verification::state::VerificationState;
use axum::{
body::Bytes,
extract::MatchedPath,
Expand All @@ -22,7 +23,7 @@ use issuance::offers::offers;
use tower_http::trace::TraceLayer;
use tracing::{info_span, Span};

pub type ApplicationState = (IssuanceState, ());
pub type ApplicationState = (IssuanceState, VerificationState);

pub fn app(state: ApplicationState) -> Router {
let base_path = get_base_path();
Expand Down Expand Up @@ -96,6 +97,7 @@ fn get_base_path() -> Result<String, ConfigError> {
#[cfg(test)]
mod tests {
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::routing::post;
use oid4vci::credential_issuer::{
credential_issuer_metadata::CredentialIssuerMetadata, credentials_supported::CredentialsSupportedObject,
Expand Down Expand Up @@ -145,9 +147,10 @@ mod tests {
#[should_panic]
async fn test_base_path_routes() {
let issuance_state = in_memory::issuance_state().await;
let verification_state = in_memory::verification_state(test_verification_services()).await;

std::env::set_var("AGENT_APPLICATION_BASE_PATH", "unicore");
let router = app((issuance_state, ()));
let router = app((issuance_state, verification_state));

let _ = router.route("/auth/token", post(handler));
}
Expand Down
1 change: 1 addition & 0 deletions agent_application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ agent_issuance = { path = "../agent_issuance" }
agent_api_rest = { path = "../agent_api_rest" }
agent_shared = { path = "../agent_shared" }
agent_store = { path = "../agent_store" }
agent_verification = { path = "../agent_verification" }

axum.workspace = true
lazy_static.workspace = true
Expand Down
15 changes: 15 additions & 0 deletions agent_application/docker/db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ CREATE TABLE server_config
PRIMARY KEY (view_id)
);

CREATE TABLE authorization_request
(
view_id text NOT NULL,
version bigint CHECK (version >= 0) NOT NULL,
payload json NOT NULL,
PRIMARY KEY (view_id)
);

CREATE TABLE connection
(
view_id text NOT NULL,
version bigint CHECK (version >= 0) NOT NULL,
payload json NOT NULL,
PRIMARY KEY (view_id)
);

CREATE USER demo_user WITH ENCRYPTED PASSWORD 'demo_pass';
GRANT ALL PRIVILEGES ON DATABASE postgres TO demo_user;
22 changes: 17 additions & 5 deletions agent_application/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::sync::Arc;

use agent_api_rest::app;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_shared::config;
use agent_shared::{config, secret_manager::secret_manager};
use agent_store::{in_memory, postgres};
use agent_verification::services::VerificationServices;
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

Expand All @@ -18,9 +21,16 @@ async fn main() {
_ => tracing_subscriber.with(tracing_subscriber::fmt::layer()).init(),
}

let issuance_state = match config!("event_store").unwrap().as_str() {
"postgres" => postgres::issuance_state().await,
_ => in_memory::issuance_state().await,
let verification_services = Arc::new(VerificationServices::new(Arc::new(secret_manager().await)));
let (issuance_state, verification_state) = match config!("event_store").unwrap().as_str() {
"postgres" => (
postgres::issuance_state().await,
postgres::verification_state(verification_services).await,
),
_ => (
in_memory::issuance_state().await,
in_memory::verification_state(verification_services).await,
),
};

let url = config!("url").expect("AGENT_APPLICATION_URL is not set");
Expand All @@ -35,5 +45,7 @@ async fn main() {

let listener = tokio::net::TcpListener::bind("0.0.0.0:3033").await.unwrap();
info!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app((issuance_state, ()))).await.unwrap();
axum::serve(listener, app((issuance_state, verification_state)))
.await
.unwrap();
}
2 changes: 1 addition & 1 deletion agent_issuance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async-trait.workspace = true
axum.workspace = true
cqrs-es.workspace = true
derivative = "2.2"
futures = "0.3"
futures.workspace = true
jsonschema = "0.17"
jsonwebtoken = "8.2"
oid4vci.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion agent_secret_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ anyhow = "1.0"
async-trait = "0.1"
cqrs-es = "0.4.2"
did_manager.workspace = true
futures = "0.3"
futures.workspace = true
log = "0.4"
oid4vc-core.workspace = true
serde.workspace = true
Expand Down
4 changes: 1 addition & 3 deletions agent_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ pub mod application_state;
pub mod config;
pub mod generic_query;
pub mod handlers;
pub mod url_utils;

#[cfg(feature = "test")]
pub mod secret_manager;
pub mod url_utils;

pub use ::config::ConfigError;
use rand::Rng;
Expand Down
3 changes: 2 additions & 1 deletion agent_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ rust-version.workspace = true
[dependencies]
agent_issuance = { path = "../agent_issuance" }
agent_shared = { path = "../agent_shared" }
agent_verification = { path = "../agent_verification" }

cqrs-es = "0.4.2"
cqrs-es.workspace = true
postgres-es = "0.4.10"

async-trait = "0.1"
Expand Down
Loading

0 comments on commit 96df010

Please sign in to comment.