v0.31.5
This commit is contained in:
1 parent
d942c1a35d
commit
75104f87ba
103 files changed
+1344
-370
No files matched your search
@@ -0,0 +1,53 @@
|
||||
use super::*;
|
||||
use http::HeaderValue;
|
||||
|
||||
fn headers(value: Option<&str>) -> HeaderMap {
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Some(value) = value {
|
||||
headers.insert(USER_AGENT, HeaderValue::from_str(value).unwrap());
|
||||
}
|
||||
headers
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_patterns_match_case_insensitive_substrings() {
|
||||
let policy = Policy {
|
||||
enabled: true,
|
||||
patterns: vec!["BadBot".into()],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(policy.blocks(&headers(Some("Mozilla/5.0 badbot/2.1"))));
|
||||
assert!(!policy.blocks(&headers(Some("Mozilla/5.0"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wildcard_patterns_can_anchor_or_span() {
|
||||
let policy = Policy {
|
||||
enabled: true,
|
||||
patterns: vec!["curl/*".into(), "*scanner*".into()],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(policy.blocks(&headers(Some("curl/8.4.0"))));
|
||||
assert!(policy.blocks(&headers(Some("AcmeScanner/1"))));
|
||||
assert!(!policy.blocks(&headers(Some("prefix curl/8.4.0"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_or_missing_user_agent_is_allowed() {
|
||||
let disabled = Policy {
|
||||
enabled: false,
|
||||
patterns: vec!["*".into()],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(!disabled.blocks(&headers(Some("anything"))));
|
||||
let enabled = Policy {
|
||||
enabled: true,
|
||||
patterns: vec!["*".into()],
|
||||
}
|
||||
.compile()
|
||||
.unwrap();
|
||||
assert!(!enabled.blocks(&headers(None)));
|
||||
}
|
||||
Reference in new issue
Block a user