Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pg_stage_rs"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
description = "PostgreSQL dump anonymizer - streaming obfuscation for plain and custom formats"

Expand Down
9 changes: 6 additions & 3 deletions src/mutator/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ pub fn email(ctx: &mut MutationContext) -> Result<String> {
}

pub fn phone_number(ctx: &mut MutationContext) -> Result<String> {
let mask: &str = ctx.get_str_kwarg("mask").ok_or_else(|| {
PgStageError::MissingParameter("mask".to_string(), "phone_number".to_string())
})?;
let mask: &str = ctx
.get_str_kwarg("mask")
.or_else(|| ctx.get_str_kwarg("format"))
.ok_or_else(|| {
PgStageError::MissingParameter("mask".to_string(), "phone_number".to_string())
})?;
let unique = ctx.get_bool_kwarg("unique");
let mask_bytes = mask.as_bytes();
let mut gen = || {
Expand Down
19 changes: 19 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ fn test_plain_mutation_phone_number() {
assert_eq!(parts[1].len(), "+1 (###) ###-####".len());
}

#[test]
fn test_plain_mutation_phone_number_format_alias() {
let input = concat!(
"COMMENT ON COLUMN public.users.phone IS 'anon: [{\"mutation_name\": \"phone_number\", \"mutation_kwargs\": {\"format\": \"+1 (###) ###-####\"}}]';\n",
"COPY public.users (id, phone) FROM stdin;\n",
"1\t+1 (555) 123-4567\n",
"\\.\n",
);
let mut output = Vec::new();
let mut handler = PlainHandler::new(make_processor());
handler.process(Cursor::new(b""), &mut output, input.as_bytes()).unwrap();
let result = String::from_utf8(output).unwrap();
let lines: Vec<&str> = result.lines().collect();
let data_line = lines.iter().find(|l| l.starts_with("1\t")).unwrap();
let parts: Vec<&str> = data_line.split('\t').collect();
assert!(parts[1].starts_with("+1 ("));
assert_eq!(parts[1].len(), "+1 (###) ###-####".len());
}

#[test]
fn test_plain_mutation_uuid4() {
let input = concat!(
Expand Down
Loading