feat: Prefill server name in federation test

This commit is contained in:
Jade Ellis 2025-05-01 18:46:30 +01:00
parent cbcf4300df
commit fb9d4c30f4
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
9 changed files with 24 additions and 12 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

@ -3,7 +3,6 @@ mod auth;
mod handler;
mod request;
mod response;
pub mod state;
use std::str::FromStr;
@ -13,10 +12,11 @@ use axum::{
routing::{any, get, post},
};
use conduwuit::{Server, err};
pub(super) use conduwuit_service::state::State;
use http::{Uri, uri};
use self::handler::RouterExt;
pub(super) use self::{args::Args as Ruma, response::RumaResponse, state::State};
pub(super) use self::{args::Args as Ruma, response::RumaResponse};
use crate::{client, server};
pub fn build(router: Router<State>, server: &Server) -> Router<State> {

View file

@ -6,8 +6,7 @@ use axum::{
};
use axum_client_ip::SecureClientIpSource;
use conduwuit::{Result, Server, debug, error};
use conduwuit_api::router::state::Guard;
use conduwuit_service::Services;
use conduwuit_service::{Services, state::Guard};
use http::{
HeaderValue, Method, StatusCode,
header::{self, HeaderName},

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

@ -5,6 +5,7 @@ mod manager;
mod migrations;
mod service;
pub mod services;
pub mod state;
pub mod account_data;
pub mod admin;

View file

@ -1,6 +1,6 @@
use std::{ops::Deref, sync::Arc};
use conduwuit_service::Services;
use crate::Services;
#[derive(Clone, Copy)]
pub struct 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>