Lines
100 %
Functions
Branches
use axum::{
body::Body,
http::{Request, StatusCode, header},
};
use tower::ServiceExt;
use crate::common::create_test_app_state;
use web::route::create_admin_pages_router;
/// Registration is invite-only, so the page carrying the signup form must not
/// be served to an anonymous visitor.
///
/// It used to be: `POST /api/auth/register` was admin-gated but `GET /register`
/// was public, so a stranger was handed a form whose every submission is
/// refused with 401.
#[tokio::test]
async fn register_page_is_not_served_to_anonymous_visitors() {
let app_state = create_test_app_state().await;
let app = create_admin_pages_router(app_state.clone()).with_state(app_state.clone());
let response = app
.oneshot(
Request::builder()
.method("GET")
.uri("/register")
.body(Body::empty())
.unwrap(),
)
.await
.expect("the router must answer");
assert_eq!(
response.status(),
StatusCode::UNAUTHORIZED,
"an anonymous visitor must be refused the registration page"
);
}
/// An HTML visitor is redirected rather than shown a JSON error, which is what
/// `redirect_on_auth_error` is layered outside the auth pair to achieve.
async fn an_html_visitor_is_redirected_away_from_the_register_page() {
.header(header::ACCEPT, "text/html")
assert!(
response.status().is_redirection(),
"an HTML visitor must be redirected, got {}",
response.status()