mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
feat(pii): implement a masking strategy for UPI VPAs (#1641)
Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
@ -329,13 +329,33 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Strategy for masking UPI VPA's
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UpiVpaMaskingStrategy;
|
||||
|
||||
impl<T> Strategy<T> for UpiVpaMaskingStrategy
|
||||
where
|
||||
T: AsRef<str> + std::fmt::Debug,
|
||||
{
|
||||
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let vpa_str: &str = val.as_ref();
|
||||
if let Some((user_identifier, bank_or_psp)) = vpa_str.split_once('@') {
|
||||
let masked_user_identifier = "*".repeat(user_identifier.len());
|
||||
write!(f, "{masked_user_identifier}@{bank_or_psp}")
|
||||
} else {
|
||||
WithType::fmt(val, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod pii_masking_strategy_tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
use masking::{ExposeInterface, Secret};
|
||||
|
||||
use super::{ClientSecret, Email, IpAddress};
|
||||
use super::{ClientSecret, Email, IpAddress, UpiVpaMaskingStrategy};
|
||||
use crate::pii::{EmailStrategy, REDACTED};
|
||||
|
||||
/*
|
||||
@ -435,4 +455,16 @@ mod pii_masking_strategy_tests {
|
||||
let secret: Secret<String> = Secret::new("+40712345678".to_string());
|
||||
assert_eq!("*** alloc::string::String ***", format!("{secret:?}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_upi_vpa_masking() {
|
||||
let secret: Secret<String, UpiVpaMaskingStrategy> = Secret::new("my_name@upi".to_string());
|
||||
assert_eq!("*******@upi", format!("{secret:?}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_upi_vpa_masking() {
|
||||
let secret: Secret<String, UpiVpaMaskingStrategy> = Secret::new("my_name_upi".to_string());
|
||||
assert_eq!("*** alloc::string::String ***", format!("{secret:?}"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user