feat: Prefill server name in federation test

This commit is contained in:
Jade Ellis 2025-05-01 18:46:30 +01:00 committed by Jacob Taylor
parent 2bd84d46df
commit e98a7fb18c
5 changed files with 19 additions and 7 deletions

1
Cargo.lock generated
View file

@ -1044,6 +1044,7 @@ dependencies = [
"askama",
"axum",
"conduwuit_build_metadata",
"conduwuit_service",
"futures",
"rand 0.8.5",
"thiserror 2.0.12",

View file

@ -2,8 +2,7 @@ use std::sync::Arc;
use axum::{Router, response::IntoResponse};
use conduwuit::Error;
use conduwuit_api::router::{state, state::Guard};
use conduwuit_service::Services;
use conduwuit_service::{Services, state, state::Guard};
use http::{StatusCode, Uri};
use ruma::api::client::error::ErrorKind;
@ -11,7 +10,7 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
let router = Router::<state::State>::new();
let (state, guard) = state::create(services.clone());
let router = conduwuit_api::router::build(router, &services.server)
.merge(conduwuit_web::build::<state::State>().with_state(()))
.merge(conduwuit_web::build())
.fallback(not_found)
.with_state(state);

View file

@ -21,6 +21,7 @@ crate-type = [
[dependencies]
conduwuit-build-metadata.workspace = true
conduwuit-service.workspace = true
askama = "0.14.0"

View file

@ -1,23 +1,34 @@
use askama::Template;
use axum::{
Router,
extract::State,
http::{StatusCode, header},
response::{Html, IntoResponse, Response},
routing::get,
};
use conduwuit_build_metadata::{GIT_REMOTE_COMMIT_URL, GIT_REMOTE_WEB_URL, VERSION_EXTRA};
use conduwuit_service::state;
pub fn build<S>() -> Router<()> { Router::new().route("/", get(index_handler)) }
pub fn build() -> Router<state::State> {
let router = Router::<state::State>::new();
router.route("/", get(index_handler))
}
async fn index_handler() -> Result<impl IntoResponse, WebError> {
async fn index_handler(
State(services): State<state::State>,
) -> Result<impl IntoResponse, WebError> {
#[derive(Debug, Template)]
#[template(path = "index.html.j2")]
struct Tmpl<'a> {
nonce: &'a str,
server_name: &'a str,
}
let nonce = rand::random::<u64>().to_string();
let template = Tmpl { nonce: &nonce };
let template = Tmpl {
nonce: &nonce,
server_name: services.config.server_name.as_str(),
};
Ok((
[(header::CONTENT_SECURITY_POLICY, format!("default-src 'none' 'nonce-{nonce}';"))],
Html(template.render()?),

View file

@ -9,7 +9,7 @@
<li>Read the <a href="https://continuwuity.org/introduction">documentation</a></li>
<li>Join the <a href="https://continuwuity.org/community">community</a></li>
<li>Log in with a <a href="https://matrix.org/ecosystem/clients/">client</a></li>
<li>Ensure <a href="https://federationtester.matrix.org/">federation</a> works</li>
<li>Ensure <a href="https://federationtester.matrix.org/#{{ server_name }}">federation</a> works</li>
</ul>
</div>