diff --git a/radicle-httpd/src/api/auth.rs b/radicle-httpd/src/api/auth.rs index 74c2666e..2f2c990d 100644 --- a/radicle-httpd/src/api/auth.rs +++ b/radicle-httpd/src/api/auth.rs @@ -11,6 +11,8 @@ impl Serialize for DateTime { } } +#[derive(Clone, Serialize)] +#[serde(tag = "type", rename_all = "camelCase")] pub enum AuthState { Authorized(Session), Unauthorized { diff --git a/radicle-httpd/src/api/v1/sessions.rs b/radicle-httpd/src/api/v1/sessions.rs index 0f279845..6175f30a 100644 --- a/radicle-httpd/src/api/v1/sessions.rs +++ b/radicle-httpd/src/api/v1/sessions.rs @@ -20,7 +20,10 @@ pub const AUTHORIZED_SESSIONS_EXPIRATION: Duration = Duration::weeks(1); pub fn router(ctx: Context) -> Router { Router::new() .route("/sessions", post(session_create_handler)) - .route("/sessions/:id", put(session_signin_handler)) + .route( + "/sessions/:id", + put(session_signin_handler).get(session_handler), + ) .with_state(ctx) } @@ -53,6 +56,18 @@ async fn session_create_handler(State(ctx): State) -> impl IntoResponse )) } +/// Get a session. +/// `GET /sessions/:id` +async fn session_handler( + State(ctx): State, + Path(session_id): Path, +) -> impl IntoResponse { + let sessions = ctx.sessions.read().await; + let session = sessions.get(&session_id).ok_or(Error::NotFound)?.to_owned(); + + Ok::<_, Error>(Json(session)) +} + /// Update session. /// `PUT /sessions/:id` async fn session_signin_handler( @@ -100,7 +115,7 @@ mod routes { use axum::http::StatusCode; use radicle_cli::commands::rad_web::{self, SessionInfo}; - use crate::api::test::{self, post, put}; + use crate::api::test::{self, get, post, put}; #[tokio::test] async fn test_session() { @@ -131,5 +146,8 @@ mod routes { .await; assert_eq!(response.status(), StatusCode::OK); + + let response = get(&app, format!("/sessions/{}", session_info.session_id)).await; + assert_eq!(response.status(), StatusCode::OK); } }