v0.25.1
This commit is contained in:
1 parent
87e571c170
commit
fa7abc9e53
308 files changed
+49746
-50237
No files matched your search
+1
-101
@@ -147,104 +147,4 @@ pub fn routing_path(raw: &str) -> Result<String> {
|
||||
Ok(path)
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn deny_overrides_allow_and_cidr_boundaries_hold() {
|
||||
let acl = Acl {
|
||||
default: Action::Deny,
|
||||
rules: vec![
|
||||
Rule {
|
||||
network: "10.0.0.0/8".into(),
|
||||
action: Action::Allow,
|
||||
},
|
||||
Rule {
|
||||
network: "10.2.0.0/16".into(),
|
||||
action: Action::Deny,
|
||||
},
|
||||
],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(acl.allows("10.1.0.1".parse().unwrap()));
|
||||
assert!(!acl.allows("10.2.3.4".parse().unwrap()));
|
||||
assert!(!acl.allows("11.0.0.1".parse().unwrap()));
|
||||
assert!(acl.allows("::ffff:10.1.0.1".parse().unwrap()));
|
||||
}
|
||||
#[test]
|
||||
fn ipv6_and_invalid_networks() {
|
||||
let acl = Acl {
|
||||
default: Action::Deny,
|
||||
rules: vec![Rule {
|
||||
network: "fd00::/8".into(),
|
||||
action: Action::Allow,
|
||||
}],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(acl.allows("fd00::1".parse().unwrap()));
|
||||
assert!(!acl.allows("fe00::1".parse().unwrap()));
|
||||
let bad = Acl {
|
||||
default: Action::Allow,
|
||||
rules: vec![Rule {
|
||||
network: "not-cidr".into(),
|
||||
action: Action::Allow,
|
||||
}],
|
||||
};
|
||||
assert!(bad.compile().is_err());
|
||||
}
|
||||
#[test]
|
||||
fn repeated_slashes_are_normalized_for_routing() {
|
||||
assert_eq!(
|
||||
routing_path("/static/js//events.js").unwrap(),
|
||||
"/static/js/events.js"
|
||||
);
|
||||
for path in [
|
||||
"/%2e%2e/secret",
|
||||
"/a/%2E%2E/b",
|
||||
"/a%2fb",
|
||||
"/a%5cb",
|
||||
"/bad%",
|
||||
"/bad%2",
|
||||
] {
|
||||
assert!(routing_path(path).is_err(), "{path}");
|
||||
}
|
||||
assert_eq!(routing_path("//admin///users").unwrap(), "/admin/users");
|
||||
}
|
||||
#[test]
|
||||
fn decoded_rewrite_paths_keep_encoded_spaces_but_reject_ambiguity() {
|
||||
assert!(validate_decoded_routing_path("/Ubuntu 14.04 LTS/").is_ok());
|
||||
for path in ["/a/../b", "/a%2fb", "/a;b", "/a?b", "/a\\b"] {
|
||||
assert!(validate_decoded_routing_path(path).is_err(), "{path}");
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn paths_cannot_escape_a_restricted_prefix() {
|
||||
assert_eq!(routing_path("/%61dmin/users").unwrap(), "/admin/users");
|
||||
assert_eq!(routing_path("/caf%C3%A9").unwrap(), "/caf\u{e9}");
|
||||
assert_eq!(
|
||||
routing_path("/Ubuntu%2014.04%20LTS/").unwrap(),
|
||||
"/Ubuntu 14.04 LTS/"
|
||||
);
|
||||
assert_eq!(
|
||||
routing_path("/static/js//events.js").unwrap(),
|
||||
"/static/js/events.js"
|
||||
);
|
||||
assert_eq!(routing_path("//admin///users").unwrap(), "/admin/users");
|
||||
for path in [
|
||||
"/api/../admin",
|
||||
"/api/%2e%2e/admin",
|
||||
"/%2fadmin",
|
||||
"/%5cadmin",
|
||||
"/%2561dmin",
|
||||
"/%00",
|
||||
"/%ff",
|
||||
"/%q0",
|
||||
"/a\\b",
|
||||
"/admin;session=x",
|
||||
"/admin%3buser=x",
|
||||
] {
|
||||
assert!(routing_path(path).is_err(), "{path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
include!("acl/tests.rs");
|
||||
Reference in new issue
Block a user