v0.34.6
This commit is contained in:
1 parent
e037190c14
commit
5cb3b37627
37 files changed
+1031
-138
No files matched your search
@@ -82,6 +82,58 @@ mod default_listener_tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_type_policy_defaults_off_and_normalizes_exact_and_wildcard_types() {
|
||||
let old: ContentTypePolicy = serde_json::from_value(json!({})).unwrap();
|
||||
assert!(!old.enabled);
|
||||
assert!(!old.blocks(&http::HeaderMap::new()));
|
||||
|
||||
let mut policy: ContentTypePolicy = serde_json::from_value(json!({
|
||||
"enabled": true, "blocked": [" Multipart/Form-Data ", "IMAGE/*", "application/problem+json"]
|
||||
})).unwrap();
|
||||
policy.validate().unwrap();
|
||||
assert_eq!(policy.blocked, vec!["multipart/form-data", "image/*", "application/problem+json"]);
|
||||
let header = |value: &'static str| {
|
||||
let mut map = http::HeaderMap::new();
|
||||
map.insert(http::header::CONTENT_TYPE, http::HeaderValue::from_static(value));
|
||||
map
|
||||
};
|
||||
assert!(policy.blocks(&header("MULTIPART/FORM-DATA; boundary=abc123")));
|
||||
assert!(policy.blocks(&header("multipart/form-data;charset=utf-8")));
|
||||
assert!(policy.blocks(&header("multipart/form-data; boundary=\"a,b\"")));
|
||||
assert!(policy.blocks(&header("image/png")));
|
||||
assert!(policy.blocks(&header("application/problem+json")));
|
||||
assert!(!policy.blocks(&header("application/json; charset=utf-8")));
|
||||
assert!(!policy.blocks(&header("application/json; profile=\"a,b\"")));
|
||||
assert!(policy.blocks(&header("application/json; profile=unquoted,second")));
|
||||
assert!(policy.blocks(&header("application/json; profile=\"unterminated")));
|
||||
assert!(!policy.blocks(&header("text/plain")));
|
||||
assert!(!policy.blocks(&http::HeaderMap::new()));
|
||||
let mut double = header("application/json");
|
||||
double.append(http::header::CONTENT_TYPE, http::HeaderValue::from_static("multipart/form-data"));
|
||||
assert!(policy.blocks(&double));
|
||||
assert!(policy.blocks(&header("application/json, multipart/form-data")));
|
||||
assert!(policy.blocks(&header("application/json / text")));
|
||||
|
||||
policy.enabled = false;
|
||||
assert!(!policy.blocks(&header("multipart/form-data")));
|
||||
assert!(!policy.blocks(&double));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_type_policy_rejects_invalid_entries_and_empty_enabled_policy() {
|
||||
for entry in ["multipart", "*/form-data", "image/p*", "text/plain; charset=utf-8", "a/", "a//b", "image /png"] {
|
||||
let mut policy = ContentTypePolicy { enabled: true, blocked: vec![entry.into()] };
|
||||
assert!(policy.validate().is_err(), "accepted invalid pattern {entry}");
|
||||
}
|
||||
let mut empty = ContentTypePolicy { enabled: true, blocked: vec![] };
|
||||
assert!(empty.validate().is_err());
|
||||
let mut duplicate = ContentTypePolicy { enabled: true, blocked: vec!["TEXT/PLAIN".into(), " text/plain ".into()] };
|
||||
assert!(duplicate.validate().is_err());
|
||||
let mut many = ContentTypePolicy { enabled: true, blocked: vec!["text/plain".into(); 65] };
|
||||
assert!(many.validate().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn method_policy_normalizes_and_enforces_allow_and_block_modes() {
|
||||
let mut allow: MethodPolicy = serde_json::from_value(json!({
|
||||
|
||||
Reference in new issue
Block a user