From dcfbc2612a9539b22846ef0b662627851aea4ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Fri, 1 May 2026 10:48:20 +0800 Subject: [PATCH] test(admin): cover site replication scheme normalization (#2757) --- rustfs/src/admin/site_replication_identity.rs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/rustfs/src/admin/site_replication_identity.rs b/rustfs/src/admin/site_replication_identity.rs index 6992f88bd..1fbc4b3dc 100644 --- a/rustfs/src/admin/site_replication_identity.rs +++ b/rustfs/src/admin/site_replication_identity.rs @@ -17,9 +17,16 @@ use std::collections::{BTreeMap, hash_map::DefaultHasher}; use std::hash::{Hash, Hasher}; use url::Url; +fn has_http_scheme(endpoint: &str) -> bool { + endpoint.get(..7).is_some_and(|prefix| prefix.eq_ignore_ascii_case("http://")) + || endpoint + .get(..8) + .is_some_and(|prefix| prefix.eq_ignore_ascii_case("https://")) +} + pub fn canonical_endpoint(endpoint: &str) -> String { let trimmed = endpoint.trim().trim_end_matches('/'); - let candidate = if trimmed.starts_with("http://") || trimmed.starts_with("https://") { + let candidate = if has_http_scheme(trimmed) { trimmed.to_string() } else { format!("http://{trimmed}") @@ -41,7 +48,7 @@ pub fn canonical_endpoint(endpoint: &str) -> String { pub fn site_identity_key(endpoint: &str) -> String { let trimmed = endpoint.trim().trim_end_matches('/'); - let candidate = if trimmed.starts_with("http://") || trimmed.starts_with("https://") { + let candidate = if has_http_scheme(trimmed) { trimmed.to_string() } else { format!("http://{trimmed}") @@ -138,3 +145,25 @@ where normalized } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn canonical_endpoint_accepts_case_insensitive_scheme() { + assert_eq!( + canonical_endpoint(" HTTPS://Node-A.Example.Com:9000/ "), + "https://node-a.example.com:9000" + ); + } + + #[test] + fn site_identity_key_accepts_case_insensitive_scheme() { + assert_eq!(site_identity_key("HTTPS://Node-A.Example.Com:9000/"), "node-a.example.com:9000"); + assert!(same_identity_endpoint( + "HTTPS://Node-A.Example.Com:9000/", + "http://node-a.example.com:9000" + )); + } +}