#[cfg(any(feature = "redb_store", feature = "redis_store"))]
const SECRET: &[u8] = b"SUPER_SECRET_PAYLOAD_0xDEADBEEF";
#[cfg(feature = "redb_store")]
#[test]
fn redb_cache_deserialization_debug_redacts_cached_value() {
use cached::RedbCacheError;
let decode_err = rmp_serde::from_slice::<u32>(&[0xc1]).unwrap_err();
let err = RedbCacheError::CacheDeserialization {
source: Box::new(decode_err),
cached_value: SECRET.to_vec(),
};
let dbg = format!("{err:?}");
assert!(
!dbg.contains("SUPER_SECRET_PAYLOAD"),
"Debug must not contain the raw cached_value bytes: {dbg}"
);
assert!(
dbg.contains(&format!("<{} bytes redacted>", SECRET.len())),
"Debug must show the redaction marker: {dbg}"
);
}
#[cfg(feature = "redis_store")]
#[test]
fn redis_cache_deserialization_debug_redacts_cached_value() {
use cached::RedisCacheError;
let decode_err = rmp_serde::from_slice::<u32>(&[0xc1]).unwrap_err();
let err = RedisCacheError::CacheDeserialization {
source: Box::new(decode_err),
cached_value: SECRET.to_vec(),
};
let dbg = format!("{err:?}");
assert!(
!dbg.contains("SUPER_SECRET_PAYLOAD"),
"Debug must not contain the raw cached_value bytes: {dbg}"
);
assert!(
dbg.contains(&format!("<{} bytes redacted>", SECRET.len())),
"Debug must show the redaction marker: {dbg}"
);
}