diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 98ec964b..462624a5 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -1,5 +1,4 @@ -#[cfg(test)] -pub mod test; +pub mod auth; use std::collections::HashMap; use std::sync::Arc; @@ -21,7 +20,6 @@ use radicle::identity::Id; use radicle::storage::{ReadRepository, ReadStorage}; use radicle::Profile; -mod auth; mod axum_extra; mod error; mod json; @@ -70,6 +68,11 @@ impl Context { pub fn profile(&self) -> &Arc { &self.profile } + + #[cfg(test)] + pub fn sessions(&self) -> &Arc>> { + &self.sessions + } } pub fn router(ctx: Context) -> Router { diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index 01138768..52fa5ca5 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -74,7 +74,7 @@ mod routes { use axum::http::StatusCode; use serde_json::json; - use crate::api::test::{self, get, HEAD}; + use crate::test::{self, get, HEAD}; #[tokio::test] async fn test_delegates_projects() { diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 68fcaffb..d768a3e4 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -562,7 +562,7 @@ mod routes { use pretty_assertions::assert_eq; use serde_json::json; - use crate::api::test::{self, get, patch, post, HEAD, HEAD_1, ISSUE_ID, PATCH_ID}; + use crate::test::{self, get, patch, post, HEAD, HEAD_1, ISSUE_ID, PATCH_ID}; const CREATED_ISSUE_ID: &str = "b56febfba1e7dd20f4aea43ca2fe9dcf1fd448ba"; diff --git a/radicle-httpd/src/api/v1/sessions.rs b/radicle-httpd/src/api/v1/sessions.rs index f2cdcc53..c1e2146b 100644 --- a/radicle-httpd/src/api/v1/sessions.rs +++ b/radicle-httpd/src/api/v1/sessions.rs @@ -125,10 +125,8 @@ mod routes { use axum::http::StatusCode; use radicle_cli::commands::rad_web::{self, SessionInfo}; - use crate::api::{ - auth::{AuthState, Session}, - test::{self, get, post, put}, - }; + use crate::api::auth::{AuthState, Session}; + use crate::test::{self, get, post, put}; #[tokio::test] async fn test_session() { diff --git a/radicle-httpd/src/api/v1/stats.rs b/radicle-httpd/src/api/v1/stats.rs index 873c06e7..c8b1f633 100644 --- a/radicle-httpd/src/api/v1/stats.rs +++ b/radicle-httpd/src/api/v1/stats.rs @@ -29,7 +29,7 @@ mod routes { use axum::http::StatusCode; use serde_json::json; - use crate::api::test::{self, get}; + use crate::test::{self, get}; #[tokio::test] async fn test_stats() { diff --git a/radicle-httpd/src/git.rs b/radicle-httpd/src/git.rs index ddc49dd2..e7aab600 100644 --- a/radicle-httpd/src/git.rs +++ b/radicle-httpd/src/git.rs @@ -203,7 +203,7 @@ mod routes { use axum::http::{Method, StatusCode}; use tower::ServiceExt; - use crate::api::test; + use crate::test; #[tokio::test] async fn test_invalid_route_returns_404() { diff --git a/radicle-httpd/src/lib.rs b/radicle-httpd/src/lib.rs index 6110d14d..29dd01ad 100644 --- a/radicle-httpd/src/lib.rs +++ b/radicle-httpd/src/lib.rs @@ -17,6 +17,8 @@ use tracing::Span; mod api; mod git; +#[cfg(test)] +mod test; #[derive(Debug, Clone)] pub struct Options { @@ -30,9 +32,11 @@ pub async fn run(options: Options) -> anyhow::Result<()> { .output() .context("'git' command must be available")? .stdout; + tracing::info!("{}", str::from_utf8(&git_version)?.trim()); let profile = Arc::new(radicle::Profile::load()?); + tracing::info!("using radicle home at {}", profile.home().display()); let ctx = api::Context::new(profile.clone()); diff --git a/radicle-httpd/src/api/test.rs b/radicle-httpd/src/test.rs similarity index 97% rename from radicle-httpd/src/api/test.rs rename to radicle-httpd/src/test.rs index 6feae697..283ac818 100644 --- a/radicle-httpd/src/api/test.rs +++ b/radicle-httpd/src/test.rs @@ -136,21 +136,18 @@ pub fn seed(dir: &Path) -> Context { ) .unwrap(); - Context { - profile: Arc::new(profile), - sessions: Default::default(), - } + Context::new(Arc::new(profile)) } /// Adds an authorized session to the Context::sessions HashMap. pub async fn create_session(ctx: Context) { let issued_at = OffsetDateTime::now_utc(); - let mut sessions = ctx.sessions.write().await; + let mut sessions = ctx.sessions().write().await; sessions.insert( String::from("u9MGAkkfkMOv0uDDB2WeUHBT7HbsO2Dy"), auth::Session { status: auth::AuthState::Authorized, - public_key: ctx.profile.public_key, + public_key: ctx.profile().public_key, issued_at, expires_at: issued_at .checked_add(auth::AUTHORIZED_SESSIONS_EXPIRATION)