summaryrefslogtreecommitdiff
path: root/server/src/main.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-25 14:09:09 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-11-25 14:09:09 -0500
commit2f35026022827cd86615135c6397f03b74fe1b46 (patch)
tree17c96f91330003aace047ae6b84aabd876d0ee5a /server/src/main.rs
parent9d191019757eae3bba45e8e1a021fefdc69a9fae (diff)
Hook up fake authenticator backend for testing
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs33
1 files changed, 29 insertions, 4 deletions
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<dyn Authenticator
async fn create_authenticator(db_pool: &PgPool) -> Box<dyn Authenticator + Send + Sync> {
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#"
+ <!DOCTYPE html>
+ <html lang="en">
+ <body>
+ <p>Log in as:</p>
+ <ul>
+ <li><a href="/api/login_callback?user=alice">alice</a></li>
+ </ul>
+ </body>
+ </html>
+ "#)
+}
+
async fn get_table_view(
_session: AuthenticatedSession,
extension: ContextExtension,