From e44213599cb64547a01a28953da58a232cc1e967 Mon Sep 17 00:00:00 2001 From: Adnan Zahir Date: Mon, 16 Nov 2026 21:41:51 +0700 Subject: [PATCH] style: rustfmt after merging the release branches Co-Authored-By: Claude Sonnet 5.5 --- crates/tessera-hub/src/api/auth_contract.rs | 30 +++-- crates/tessera-hub/src/api/routes.rs | 119 +++++++++++++------- crates/tessera-hub/src/api/session.rs | 14 ++- crates/tessera-hub/src/db/audit.rs | 5 +- crates/tessera-hub/src/scheduler.rs | 10 +- crates/tessera-providers/src/postgres.rs | 3 +- crates/tessera-store/src/vault.rs | 4 +- 7 files changed, 122 insertions(+), 63 deletions(-) diff --git a/crates/tessera-hub/src/api/auth_contract.rs b/crates/tessera-hub/src/api/auth_contract.rs index 7231afd..84c9017 100644 --- a/crates/tessera-hub/src/api/auth_contract.rs +++ b/crates/tessera-hub/src/api/auth_contract.rs @@ -33,10 +33,12 @@ fn every_registered_path_has_an_authorization_contract() { #[tokio::test] async fn human_read_endpoints_reject_anonymous_and_outpost_tokens() { let dir = tempfile::tempdir().unwrap(); - let mut state = - crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = crate::state::HubState::bootstrap( + dir.path().to_str().unwrap(), + "synthetic-vault-passphrase", + ) + .await + .unwrap(); state.sessions = crate::admin::SessionGate::fixture(state.db.clone()); state.admin.token = Some("synthetic-admin".into()); let outpost = uuid::Uuid::new_v4(); @@ -54,9 +56,13 @@ async fn human_read_endpoints_reject_anonymous_and_outpost_tokens() { let path = fields[1].replace(":id", "00000000-0000-0000-0000-000000000001"); for token in [None, Some("synthetic-outpost")] { source += 1; - let mut request = Request::builder().uri(&path).extension(ConnectInfo( - SocketAddr::from(([10, 0, (source >> 8) as u8, source as u8], 9000)), - )); + let mut request = + Request::builder() + .uri(&path) + .extension(ConnectInfo(SocketAddr::from(( + [10, 0, (source >> 8) as u8, source as u8], + 9000, + )))); if let Some(token) = token { request = request .header(header::AUTHORIZATION, format!("Bearer {token}")) @@ -79,10 +85,12 @@ async fn human_read_endpoints_reject_anonymous_and_outpost_tokens() { #[tokio::test] async fn local_proxy_never_enables_auth_when_credentials_are_absent() { let dir = tempfile::tempdir().unwrap(); - let mut state = - crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = crate::state::HubState::bootstrap( + dir.path().to_str().unwrap(), + "synthetic-vault-passphrase", + ) + .await + .unwrap(); state.admin = crate::admin::AdminGate { token: None, local_development: false, diff --git a/crates/tessera-hub/src/api/routes.rs b/crates/tessera-hub/src/api/routes.rs index e7d156f..a6ae0ea 100644 --- a/crates/tessera-hub/src/api/routes.rs +++ b/crates/tessera-hub/src/api/routes.rs @@ -422,10 +422,7 @@ pub fn router(state: HubState) -> Router { .route("/api-doc/openapi.json", get(openapi_document)) .with_state(state); - let hsts = matches!( - std::env::var("TESSERA_HSTS").as_deref(), - Ok("1" | "true") - ); + let hsts = matches!(std::env::var("TESSERA_HSTS").as_deref(), Ok("1" | "true")); api.fallback(spa_fallback) .layer(TraceLayer::new_for_http().make_span_with(request_span)) .layer(axum::middleware::from_fn(move |request, next| { @@ -460,7 +457,10 @@ async fn security_headers( header::X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff"), ); - headers.insert(header::REFERRER_POLICY, HeaderValue::from_static("no-referrer")); + headers.insert( + header::REFERRER_POLICY, + HeaderValue::from_static("no-referrer"), + ); headers.insert(header::X_FRAME_OPTIONS, HeaderValue::from_static("DENY")); if hsts { headers.insert( @@ -1635,23 +1635,30 @@ mod tests { #[tokio::test] async fn unauthenticated_floods_write_one_denial_row_per_source() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.admin.token = Some("synthetic-admin-token-of-32-chars!".into()); let app = router(state); let human = |ip: &str| { Request::get("/api/v1/orbits") - .extension(ConnectInfo(format!("{ip}:9000").parse::().unwrap())) + .extension(ConnectInfo( + format!("{ip}:9000").parse::().unwrap(), + )) .body(Body::empty()) .unwrap() }; let outpost = |ip: &str| { Request::post("/api/v1/wormhole/upload/init") - .extension(ConnectInfo(format!("{ip}:9000").parse::().unwrap())) + .extension(ConnectInfo( + format!("{ip}:9000").parse::().unwrap(), + )) .header(header::CONTENT_TYPE, "application/json") .header("x-tessera-upload-token", "wrong") - .body(Body::from(r#"{"orbit_id":"00000000-0000-0000-0000-000000000000","total_bytes":1}"#)) + .body(Body::from( + r#"{"orbit_id":"00000000-0000-0000-0000-000000000000","total_bytes":1}"#, + )) .unwrap() }; for _ in 0..25 { @@ -1674,21 +1681,28 @@ mod tests { #[tokio::test] async fn wrong_admin_tokens_are_throttled_per_source() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.admin.token = Some("synthetic-admin-token-of-32-chars!".into()); let app = router(state); let req = |ip: &str, token: &str| { Request::get("/api/v1/orbits") - .extension(ConnectInfo(format!("{ip}:9000").parse::().unwrap())) + .extension(ConnectInfo( + format!("{ip}:9000").parse::().unwrap(), + )) .header("x-tessera-admin-token", token) .body(Body::empty()) .unwrap() }; let mut limited = false; for _ in 0..20 { - let r = app.clone().oneshot(req("203.0.113.20", "wrong")).await.unwrap(); + let r = app + .clone() + .oneshot(req("203.0.113.20", "wrong")) + .await + .unwrap(); limited |= r.status() == StatusCode::TOO_MANY_REQUESTS; } assert!(limited); @@ -1699,18 +1713,25 @@ mod tests { #[tokio::test] async fn reconstitute_targets_stay_inside_the_exports_directory_for_every_caller() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.admin.token = Some("synthetic-admin-token-of-32-chars!".into()); let app = router(state); let attempt = |path: &str| { Request::post("/api/v1/reconstitute") - .extension(ConnectInfo("203.0.113.30:9000".parse::().unwrap())) - .header(header::AUTHORIZATION, "Bearer synthetic-admin-token-of-32-chars!") + .extension(ConnectInfo( + "203.0.113.30:9000".parse::().unwrap(), + )) + .header( + header::AUTHORIZATION, + "Bearer synthetic-admin-token-of-32-chars!", + ) .header(header::CONTENT_TYPE, "application/json") .body(Body::from( - serde_json::json!({"snapshot_id": Uuid::new_v4(), "target_path": path}).to_string(), + serde_json::json!({"snapshot_id": Uuid::new_v4(), "target_path": path}) + .to_string(), )) .unwrap() }; @@ -1749,14 +1770,18 @@ mod tests { let sink = Sink::default(); let subscriber = tracing_subscriber::fmt().with_writer(sink.clone()).finish(); tracing::subscriber::with_default(subscriber, || { - let request = Request::get("/api/v1/auth/oidc/callback?code=secret-code&state=secret-state") - .body(Body::empty()) - .unwrap(); + let request = + Request::get("/api/v1/auth/oidc/callback?code=secret-code&state=secret-state") + .body(Body::empty()) + .unwrap(); request_span(&request).in_scope(|| tracing::info!("handled")); }); let logged = String::from_utf8(sink.0.lock().unwrap().clone()).unwrap(); assert!(logged.contains("/api/v1/auth/oidc/callback"), "{logged}"); - assert!(!logged.contains("secret-code") && !logged.contains("secret-state"), "{logged}"); + assert!( + !logged.contains("secret-code") && !logged.contains("secret-state"), + "{logged}" + ); } #[test] @@ -1774,14 +1799,16 @@ mod tests { #[tokio::test] async fn the_api_description_is_not_served_to_anonymous_callers() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.admin.token = Some("synthetic-admin-token-of-32-chars!".into()); let app = router(state); let request = |token: Option<&str>| { - let mut r = Request::get("/api-doc/openapi.json") - .extension(ConnectInfo("203.0.113.50:9000".parse::().unwrap())); + let mut r = Request::get("/api-doc/openapi.json").extension(ConnectInfo( + "203.0.113.50:9000".parse::().unwrap(), + )); if let Some(token) = token { r = r.header(header::AUTHORIZATION, format!("Bearer {token}")); } @@ -1805,7 +1832,9 @@ mod tests { let app = router(state); let get = |uri: &str| { Request::get(uri) - .extension(ConnectInfo("203.0.113.40:9000".parse::().unwrap())) + .extension(ConnectInfo( + "203.0.113.40:9000".parse::().unwrap(), + )) .body(Body::empty()) .unwrap() }; @@ -1834,9 +1863,10 @@ mod tests { #[tokio::test] async fn a_failed_denial_audit_write_still_answers_401() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.admin.token = Some("synthetic-admin-token-of-32-chars!".into()); let app = router(state); rusqlite::Connection::open(dir.path().join("tessera.db")) @@ -1844,7 +1874,9 @@ mod tests { .execute_batch("DROP TABLE audit_events") .unwrap(); let human = Request::get("/api/v1/orbits") - .extension(ConnectInfo("203.0.113.9:9000".parse::().unwrap())) + .extension(ConnectInfo( + "203.0.113.9:9000".parse::().unwrap(), + )) .body(Body::empty()) .unwrap(); assert_eq!( @@ -1852,10 +1884,14 @@ mod tests { StatusCode::UNAUTHORIZED ); let outpost = Request::post("/api/v1/wormhole/upload/init") - .extension(ConnectInfo("203.0.113.10:9000".parse::().unwrap())) + .extension(ConnectInfo( + "203.0.113.10:9000".parse::().unwrap(), + )) .header(header::CONTENT_TYPE, "application/json") .header("x-tessera-upload-token", "wrong") - .body(Body::from(r#"{"orbit_id":"00000000-0000-0000-0000-000000000000","total_bytes":1}"#)) + .body(Body::from( + r#"{"orbit_id":"00000000-0000-0000-0000-000000000000","total_bytes":1}"#, + )) .unwrap(); assert_eq!( app.oneshot(outpost).await.unwrap().status(), @@ -1866,9 +1902,10 @@ mod tests { #[tokio::test] async fn legacy_uploads_are_owned_by_the_assigned_outpost() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase") + .await + .unwrap(); state.accept_plain_upload = true; state.admin.token = Some("synthetic-admin".into()); let a = Uuid::new_v4(); diff --git a/crates/tessera-hub/src/api/session.rs b/crates/tessera-hub/src/api/session.rs index 17adefc..0d22364 100644 --- a/crates/tessera-hub/src/api/session.rs +++ b/crates/tessera-hub/src/api/session.rs @@ -369,9 +369,10 @@ mod tests { #[tokio::test] async fn operator_session_requires_csrf_and_expires_without_disabling_cli() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase") + .await + .unwrap(); state.sessions = SessionGate::fixture(state.db.clone()); state.admin.token = Some("fixture-api-token".into()); let app = crate::api::router(state.clone()); @@ -507,9 +508,10 @@ mod tests { #[tokio::test] async fn me_reports_the_caller_and_rejects_anonymous() { let dir = tempfile::tempdir().unwrap(); - let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase") - .await - .unwrap(); + let mut state = + HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase") + .await + .unwrap(); state.sessions = SessionGate::fixture(state.db.clone()); let app = crate::api::router(state); let peer = || ConnectInfo("127.0.0.1:1234".parse::().unwrap()); diff --git a/crates/tessera-hub/src/db/audit.rs b/crates/tessera-hub/src/db/audit.rs index 3817f58..ac2a3cb 100644 --- a/crates/tessera-hub/src/db/audit.rs +++ b/crates/tessera-hub/src/db/audit.rs @@ -86,7 +86,10 @@ mod tests { db.conn .lock() .unwrap() - .execute("UPDATE audit_events SET at = ?1 WHERE id <= 2", params![now - 100 * 86_400]) + .execute( + "UPDATE audit_events SET at = ?1 WHERE id <= 2", + params![now - 100 * 86_400], + ) .unwrap(); assert_eq!(db.prune_audit_events(now - 90 * 86_400).unwrap(), 2); let left: i64 = db diff --git a/crates/tessera-hub/src/scheduler.rs b/crates/tessera-hub/src/scheduler.rs index d35ef6f..d53a769 100644 --- a/crates/tessera-hub/src/scheduler.rs +++ b/crates/tessera-hub/src/scheduler.rs @@ -37,7 +37,11 @@ const DEFAULT_AUDIT_RETENTION_DAYS: i64 = 90; /// `TESSERA_AUDIT_RETENTION_DAYS`: how long structured audit events are kept. /// Unset means 90 days; `0` keeps them forever. pub fn audit_retention_from_env() -> Result> { - parse_audit_retention(std::env::var("TESSERA_AUDIT_RETENTION_DAYS").ok().as_deref()) + parse_audit_retention( + std::env::var("TESSERA_AUDIT_RETENTION_DAYS") + .ok() + .as_deref(), + ) } fn parse_audit_retention(value: Option<&str>) -> Result> { @@ -48,7 +52,9 @@ fn parse_audit_retention(value: Option<&str>) -> Result> { .parse() .ok() .filter(|days| (0..=36_500).contains(days)) - .context("TESSERA_AUDIT_RETENTION_DAYS must be a whole number of days (0 keeps everything)")?; + .context( + "TESSERA_AUDIT_RETENTION_DAYS must be a whole number of days (0 keeps everything)", + )?; Ok((days > 0).then_some(days)) } diff --git a/crates/tessera-providers/src/postgres.rs b/crates/tessera-providers/src/postgres.rs index 4f9f26b..7903c56 100644 --- a/crates/tessera-providers/src/postgres.rs +++ b/crates/tessera-providers/src/postgres.rs @@ -409,7 +409,8 @@ mod tests { #[test] fn pg_dump_keeps_the_url_out_of_argv() { let target = - parse_postgres_url("postgres://migrator:s%3Acret@example.invalid:5433/billing").unwrap(); + parse_postgres_url("postgres://migrator:s%3Acret@example.invalid:5433/billing") + .unwrap(); assert_eq!(target.password, "s:cret"); let args = dump_args("custom").unwrap(); let pgpass = write_pgpass(&target, false).unwrap(); diff --git a/crates/tessera-store/src/vault.rs b/crates/tessera-store/src/vault.rs index f684b4f..8a50b7f 100644 --- a/crates/tessera-store/src/vault.rs +++ b/crates/tessera-store/src/vault.rs @@ -90,7 +90,9 @@ impl Vault { restrict_dir(&root.join("keys"))?; // Not refused: that would lock existing deployments out of their own backups. if passphrase == "dev-vault-key" { - tracing::warn!("this vault uses the published dev passphrase; rotate it to a private one"); + tracing::warn!( + "this vault uses the published dev passphrase; rotate it to a private one" + ); } else if passphrase.chars().count() < MIN_PASSPHRASE_CHARS { tracing::warn!( "the vault passphrase is shorter than {MIN_PASSPHRASE_CHARS} characters; a new vault would refuse it"