mirror of
https://github.com/katanemo/plano.git
synced 2026-05-10 16:22:42 +02:00
obfuscate auth header (#254)
This commit is contained in:
parent
88d0f99866
commit
9081eb0f7f
4 changed files with 49 additions and 3 deletions
44
crates/common/src/pii.rs
Normal file
44
crates/common/src/pii.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
pub fn obfuscate_auth_header(headers: &mut [(String, String)]) -> &[(String, String)] {
|
||||
headers.iter_mut().for_each(|(key, value)| {
|
||||
if key.to_lowercase() == "authorization" {
|
||||
if value.starts_with("Bearer ") {
|
||||
*value = "Bearer ***".to_string();
|
||||
} else {
|
||||
*value = "***".to_string();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
headers
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::pii::obfuscate_auth_header;
|
||||
|
||||
#[test]
|
||||
pub fn test_obfuscate_auth_header() {
|
||||
let mut headers = vec![("Authorization".to_string(), "Bearer 1234".to_string())];
|
||||
obfuscate_auth_header(&mut headers);
|
||||
assert_eq!(
|
||||
headers,
|
||||
vec![("Authorization".to_string(), "Bearer ***".to_string())]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_obfuscate_no_auth_header_found() {
|
||||
let mut headers = vec![
|
||||
(":path".to_string(), "/healthz".to_string()),
|
||||
(":method".to_string(), "POST".to_string()),
|
||||
];
|
||||
obfuscate_auth_header(&mut headers);
|
||||
assert_eq!(
|
||||
headers,
|
||||
vec![
|
||||
(":path".to_string(), "/healthz".to_string()),
|
||||
(":method".to_string(), "POST".to_string()),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue