Skip to content

Commit 4527c9b

Browse files
committed
test: Add test for header sanitization
1 parent af39718 commit 4527c9b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

trino-lb-core/src/sanitization.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,32 @@ impl Sanitize for http::HeaderMap {
1111
sanitized
1212
}
1313
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use http::{
18+
header::{CONTENT_LENGTH, HOST},
19+
HeaderMap, HeaderValue,
20+
};
21+
22+
use super::*;
23+
24+
#[test]
25+
fn test_sanitize() {
26+
let mut headers = HeaderMap::new();
27+
headers.insert(HOST, "example.com".parse().unwrap());
28+
headers.insert(CONTENT_LENGTH, "123".parse().unwrap());
29+
30+
let sanitized = headers.sanitize();
31+
assert_eq!(sanitized, headers);
32+
33+
headers.insert("Authorization", HeaderValue::from_static("secure"));
34+
let sanitized = headers.sanitize();
35+
assert_eq!(sanitized.get("Authorization").unwrap(), "<redacted>");
36+
37+
// Also test lowercase variant
38+
headers.insert("authorization", HeaderValue::from_static("secure"));
39+
let sanitized = headers.sanitize();
40+
assert_eq!(sanitized.get("authorization").unwrap(), "<redacted>");
41+
}
42+
}

0 commit comments

Comments
 (0)