From 2f35026022827cd86615135c6397f03b74fe1b46 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 25 Nov 2022 14:09:09 -0500 Subject: Hook up fake authenticator backend for testing --- server/src/main.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'server/src/main.rs') diff --git a/server/src/main.rs b/server/src/main.rs index 39425d6..ca65d86 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -5,11 +5,12 @@ use uuid::Uuid; use auth::AuthenticatedSession; use axum::{ extract::{Extension, Path, Query}, - response::Redirect, + response::{Html, Redirect}, routing::{delete, get, post}, Json, Router, }; -use protocol::{bridge_engine::{self, TableView, Player}, Table, UserInfo}; +use protocol::{Table, UserInfo}; +use protocol::bridge_engine::{TableView, Player}; use server::ContextExtension; use tower_cookies::{Cookie, CookieManagerLayer, Cookies}; use tower_http::trace::TraceLayer; @@ -19,6 +20,7 @@ mod auth; mod error; mod play; mod server; +#[cfg(debug_assertions)] mod fake_auth; use crate::{ auth::{OauthAuthenticator, SessionId}, @@ -39,7 +41,7 @@ async fn create_default_authenticator(db_pool: &PgPool) -> Box Box { const FAKE_AUTHENTICATOR: &str = "fake"; if std::env::var("AUTHENTICATOR").unwrap_or("".to_string()) == FAKE_AUTHENTICATOR { - Box::new(fake_auth::FakeAuthenticator {}) + Box::new(fake_auth::FakeAuthenticator::new()) } else { create_default_authenticator(db_pool).await } @@ -91,7 +93,13 @@ async fn main() { db: db_pool, }); - let app = Router::new() + let app = Router::new(); + + #[cfg(debug_assertions)] + let app = app + .route("/api/fake_login", get(fake_login)); + + let app = app .route("/api/user/info", get(user_info)) .route("/api/table", post(create_table)) .route("/api/table", delete(leave_table)) @@ -109,6 +117,23 @@ async fn main() { .unwrap(); } +#[cfg(debug_assertions)] +async fn fake_login() -> Html<&'static str> { + use axum::response::Html; + + Html(r#" + + + +

Log in as:

+ + + + "#) +} + async fn get_table_view( _session: AuthenticatedSession, extension: ContextExtension, -- cgit v1.2.3