This commit is contained in:
Mateusz Gruszczyński committed 2026-10-04 11:15:58 +02:00
1 parent 87e571c170
commit fa7abc9e53
308 files changed
+49746 -50237

No files matched your search

+1 -106
View File
@@ -485,109 +485,4 @@ fn join_paths(base: &str, suffix: &str) -> String {
}
#[cfg(test)]
mod tests {
use super::*;
fn rule() -> Rule {
Rule {
target: "https://new.example/base?fixed=1#section".into(),
..Rule::default()
}
}
#[test]
fn redirect_location_supports_path_and_query_modes() {
let host = Host {
id: "legacy".into(),
name: "Legacy".into(),
enabled: true,
http2_enabled: true,
http3_enabled: true,
frontend: crate::vhost::Frontend {
hosts: vec!["old.example".into()],
listener_ids: vec!["http".into()],
},
certificate_id: None,
rules: vec![rule()],
};
let listeners =
crate::settings::Listeners::from_startup("127.0.0.1:8080".parse().unwrap(), None);
let compiled = compile(&host, &listeners).unwrap();
let uri: Uri = "/products/1?src=old".parse().unwrap();
assert_eq!(
compiled.rules[0]
.location("old.example", false, &uri)
.unwrap(),
"https://new.example/base/products/1?fixed=1&src=old#section"
);
}
#[test]
fn strip_prefix_and_host_target_are_deterministic() {
let mut value = rule();
value.path_prefix = "/old".into();
value.target_type = TargetType::Host;
value.target = "app.example:8443".into();
value.target_scheme = TargetScheme::Https;
value.path_mode = PathMode::StripPrefix;
value.query_mode = QueryMode::Drop;
let host = Host {
id: "legacy".into(),
name: "Legacy".into(),
enabled: true,
http2_enabled: true,
http3_enabled: true,
frontend: crate::vhost::Frontend {
hosts: vec!["old.example".into()],
listener_ids: vec!["http".into()],
},
certificate_id: None,
rules: vec![value],
};
let listeners =
crate::settings::Listeners::from_startup("127.0.0.1:8080".parse().unwrap(), None);
let compiled = compile(&host, &listeners).unwrap();
let uri: Uri = "/old/path?x=1".parse().unwrap();
assert_eq!(
compiled.rules[0]
.location("old.example", false, &uri)
.unwrap(),
"https://app.example:8443/path"
);
}
#[test]
fn validation_rejects_overlaps_and_unconditional_path_loop() {
let mut host = Host {
id: "legacy".into(),
name: "Legacy".into(),
enabled: true,
http2_enabled: true,
http3_enabled: true,
frontend: crate::vhost::Frontend {
hosts: vec!["OLD.EXAMPLE.".into()],
listener_ids: vec!["http".into()],
},
certificate_id: None,
rules: vec![Rule {
target_type: TargetType::Path,
target: "/".into(),
path_mode: PathMode::Replace,
..Rule::default()
}],
};
assert!(host.validate().is_err());
host.rules = vec![
Rule {
target: "https://new.example/".into(),
..Rule::default()
},
Rule {
id: "other".into(),
target: "https://other.example/".into(),
..Rule::default()
},
];
assert!(host.validate().is_err());
}
}
include!("redirect/tests.rs");