Skip to content

Commit

Permalink
test: Add test for header sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Jan 18, 2024
1 parent af39718 commit 4527c9b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions trino-lb-core/src/sanitization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,32 @@ impl Sanitize for http::HeaderMap {
sanitized
}
}

#[cfg(test)]
mod tests {
use http::{
header::{CONTENT_LENGTH, HOST},
HeaderMap, HeaderValue,
};

use super::*;

#[test]
fn test_sanitize() {
let mut headers = HeaderMap::new();
headers.insert(HOST, "example.com".parse().unwrap());
headers.insert(CONTENT_LENGTH, "123".parse().unwrap());

let sanitized = headers.sanitize();
assert_eq!(sanitized, headers);

headers.insert("Authorization", HeaderValue::from_static("secure"));
let sanitized = headers.sanitize();
assert_eq!(sanitized.get("Authorization").unwrap(), "<redacted>");

// Also test lowercase variant
headers.insert("authorization", HeaderValue::from_static("secure"));
let sanitized = headers.sanitize();
assert_eq!(sanitized.get("authorization").unwrap(), "<redacted>");
}
}

0 comments on commit 4527c9b

Please sign in to comment.