From 9b2f8c8c4d27eda2ba968cb6f8bae0153d00b63e Mon Sep 17 00:00:00 2001 From: overtrue Date: Sun, 24 May 2026 05:04:38 +0800 Subject: [PATCH] test(s3): cover anonymous admin signing --- crates/s3/src/admin.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/s3/src/admin.rs b/crates/s3/src/admin.rs index 73a01ed..148e55e 100644 --- a/crates/s3/src/admin.rs +++ b/crates/s3/src/admin.rs @@ -963,12 +963,14 @@ mod tests { use std::net::{TcpListener, TcpStream}; use std::sync::mpsc; use std::thread; + use std::time::Duration; use tempfile::tempdir; #[derive(Debug)] struct CapturedAdminRequest { method: String, target: String, + headers: String, body: Vec, } @@ -1010,6 +1012,7 @@ mod tests { CapturedAdminRequest { method, target, + headers, body, } } @@ -1049,6 +1052,12 @@ mod tests { AdminClient::new(&alias).expect("admin client should build") } + fn anonymous_admin_client_for_endpoint(endpoint: &str) -> AdminClient { + let mut alias = Alias::new("test", endpoint, "", ""); + alias.anonymous = true; + AdminClient::new(&alias).expect("anonymous admin client should build") + } + fn assert_heal_options_body( body: &[u8], scan_mode: u8, @@ -1223,6 +1232,31 @@ mod tests { handle.join().expect("server thread should finish"); } + #[tokio::test] + async fn test_anonymous_admin_requests_skip_authorization_header() { + let (endpoint, receiver, handle) = + start_admin_test_server("200 OK", r#"{"bitrotStartTime":"2026-04-19T10:00:00Z"}"#); + let client = anonymous_admin_client_for_endpoint(&endpoint); + + client + .heal_status() + .await + .expect("anonymous heal status request"); + + let request = receiver + .recv_timeout(Duration::from_secs(5)) + .expect("captured request"); + assert_eq!(request.method, "POST"); + assert_eq!(request.target, "/rustfs/admin/v3/background-heal/status"); + assert!( + !request + .headers + .lines() + .any(|line| line.to_ascii_lowercase().starts_with("authorization:")) + ); + handle.join().expect("server thread should finish"); + } + #[tokio::test] async fn test_heal_start_posts_to_bucket_prefix_route_with_options_body() { let (endpoint, receiver, handle) = start_admin_test_server("200 OK", "");