Something went wrong. Try again.
A lexicon-driven AppView for ATProto.
Something went wrong. Try again.
Rust
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128mod common;
use axum::body::Body;use axum::http::{Request, StatusCode, header};use http_body_util::BodyExt;use serial_test::serial;use tower::ServiceExt;
#[tokio::test]#[serial]async fn health_at_root_when_base_path_set() { common::require_db!(); let app = common::app::TestApp::new_with_base_path("/hv").await;
let resp = app .router .clone() .oneshot( Request::builder() .uri("/health") .body(Body::empty()) .unwrap(), ) .await .unwrap();
assert_eq!(resp.status(), StatusCode::OK); let body = resp.into_body().collect().await.unwrap().to_bytes(); assert_eq!(&body[..], b"ok");}
#[tokio::test]#[serial]async fn health_not_nested_under_base_path() { common::require_db!(); let app = common::app::TestApp::new_with_base_path("/hv").await;
let resp = app .router .clone() .oneshot( Request::builder() .uri("/hv/health") .body(Body::empty()) .unwrap(), ) .await .unwrap();
assert_ne!(resp.status(), StatusCode::OK);}
#[tokio::test]#[serial]async fn config_accessible_under_base_path() { common::require_db!(); let app = common::app::TestApp::new_with_base_path("/hv").await;
let resp = app .router .clone() .oneshot( Request::builder() .uri("/hv/config") .header("host", "127.0.0.1") .body(Body::empty()) .unwrap(), ) .await .unwrap();
assert_eq!(resp.status(), StatusCode::OK);}
#[tokio::test]#[serial]async fn config_not_at_root_when_base_path_set() { common::require_db!(); let app = common::app::TestApp::new_with_base_path("/hv").await;
let resp = app .router .clone() .oneshot( Request::builder() .uri("/config") .header("host", "127.0.0.1") .body(Body::empty()) .unwrap(), ) .await .unwrap();
assert_ne!(resp.status(), StatusCode::OK);}
#[tokio::test]#[serial]async fn redirect_includes_base_path_prefix() { common::require_db!(); let app = common::app::TestApp::new_with_base_path("/hv").await;
let resp = app .router .clone() .oneshot( Request::builder() .uri("/hv/login") .body(Body::empty()) .unwrap(), ) .await .unwrap();
if resp.status().is_redirection() { let location = resp .headers() .get(header::LOCATION) .expect("redirect should have Location header") .to_str() .unwrap(); assert!( location.starts_with("/hv"), "redirect Location should include base path, got: {location}" ); }}