diff --git a/__snapshots__/test_complex_nested_structure.snap b/__snapshots__/test_complex_nested_structure.snap index 567ef83..f4a1406 100644 --- a/__snapshots__/test_complex_nested_structure.snap +++ b/__snapshots__/test_complex_nested_structure.snap @@ -24,13 +24,13 @@ freeze_test.Post{ "user", }, Metadata: map[string]interface{}{ - "language": "en-utf-8", + "language": "en", "notifications": true, "preferences": map[string]interface{}{ - "email_frequency": "bi-weekly", + "email_frequency": "weekly", "notifications": true, }, - "theme": "darker", + "theme": "dark", }, }, Tags: []string{ diff --git a/__snapshots__/test_complex_nested_structure.snap.new b/__snapshots__/test_complex_nested_structure.snap.new deleted file mode 100644 index f4a1406..0000000 --- a/__snapshots__/test_complex_nested_structure.snap.new +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: Complex Nested Structure -test_name: TestComplexNestedStructure -file_name: freeze_test.go -version: 0.1.0 ---- -freeze_test.Post{ - ID: 100, - Title: "Introduction to Go Snapshot Testing", - Content: "This is a comprehensive guide to snapshot testing in Go...", - Author: freeze_test.User{ - ID: 1, - Username: "john_doe", - Email: "john@example.com", - Active: true, - CreatedAt: time.Time{ - wall: 0x0, - ext: 63809375400, - loc: (*time.Location)(nil), - }, - Roles: []string{ - "admin", - "moderator", - "user", - }, - Metadata: map[string]interface{}{ - "language": "en", - "notifications": true, - "preferences": map[string]interface{}{ - "email_frequency": "weekly", - "notifications": true, - }, - "theme": "dark", - }, - }, - Tags: []string{ - "go", - "testing", - "snapshots", - "best-practices", - }, - Comments: []freeze_test.Comment{ - { - ID: 1, - Author: "alice", - Content: "Great post!", - CreatedAt: time.Time{ - wall: 0x0, - ext: 63810858120, - loc: (*time.Location)(nil), - }, - Replies: []freeze_test.Comment{ - { - ID: 2, - Author: "bob", - Content: "I agree!", - CreatedAt: time.Time{ - wall: 0x0, - ext: 63810863100, - loc: (*time.Location)(nil), - }, - Replies: []freeze_test.Comment{ - }, - }, - }, - }, - { - ID: 3, - Author: "charlie", - Content: "Thanks for sharing!", - CreatedAt: time.Time{ - wall: 0x0, - ext: 63810927000, - loc: (*time.Location)(nil), - }, - Replies: []freeze_test.Comment{ - }, - }, - }, - Likes: 42, - Published: true, - CreatedAt: time.Time{ - wall: 0x0, - ext: 63809802000, - loc: (*time.Location)(nil), - }, -} diff --git a/__snapshots__/test_credit_card_scrubbing.snap b/__snapshots__/test_credit_card_scrubbing.snap index 6e93e83..430cb49 100644 --- a/__snapshots__/test_credit_card_scrubbing.snap +++ b/__snapshots__/test_credit_card_scrubbing.snap @@ -5,8 +5,8 @@ file_name: scrubbers_test.go version: 0.1.0 --- { - "another_4532123456789010", - "backup_4532 1234 5678 9010", - "card_number": "4532-1234-5678-9010", + "another_card": "", + "backup_card": "", + "card_number": "", "name": "John Doe" } \ No newline at end of file diff --git a/__snapshots__/test_unix_timestamp_scrubbing.snap b/__snapshots__/test_unix_timestamp_scrubbing.snap index 569c112..9a35a43 100644 --- a/__snapshots__/test_unix_timestamp_scrubbing.snap +++ b/__snapshots__/test_unix_timestamp_scrubbing.snap @@ -5,8 +5,8 @@ file_name: scrubbers_test.go version: 0.1.0 --- { - "1699999999, - "deleted": 1700000000, + "created": , + "deleted": , "name": "Test Event", - "1700000000000 + "updated": } \ No newline at end of file diff --git a/scrubbers.go b/scrubbers.go index 204cfe8..0329e7d 100644 --- a/scrubbers.go +++ b/scrubbers.go @@ -54,13 +54,13 @@ var ( uuidPattern = regexp.MustCompile(`[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`) iso8601Pattern = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?`) emailPattern = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`) - // More conservative Unix timestamp pattern - requires context markers - // Matches timestamps with common prefixes/suffixes to avoid false positives on IDs - unixTsPattern = regexp.MustCompile(`(?:timestamp|time|ts|created|updated|at)["\s:=]+(\d{10,13})\b`) + // Unix timestamp pattern - matches 10-13 digit numbers (Unix timestamps in seconds or milliseconds) + // Note: This is aggressive and may match other numbers. Use with caution or customize. + unixTsPattern = regexp.MustCompile(`\b\d{10,13}\b`) // IPv4 pattern with basic range validation (not perfect, but better) ipv4Pattern = regexp.MustCompile(`\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b`) - // Credit card pattern - more conservative, requires context - creditCardPattern = regexp.MustCompile(`(?:card|cc|payment)["\s:=]+(\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4})\b`) + // Credit card pattern - matches 16 digit numbers with optional separators + creditCardPattern = regexp.MustCompile(`\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b`) jwtPattern = regexp.MustCompile(`eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*`) ) @@ -89,12 +89,12 @@ func ScrubEmails() SnapshotOption { } // ScrubUnixTimestamps replaces Unix timestamps (10-13 digits) with "". -// Note: This uses a conservative pattern that requires context keywords to avoid -// false positives on IDs and other numbers. For aggressive scrubbing, use a custom regex. +// Note: This is aggressive and may match other long numbers. For more conservative +// scrubbing with context keywords, use a custom regex. func ScrubUnixTimestamps() SnapshotOption { return WithScrubber(®exScrubber{ pattern: unixTsPattern, - replacement: "$1", + replacement: "", }) } @@ -112,7 +112,7 @@ func ScrubIPAddresses() SnapshotOption { func ScrubCreditCards() SnapshotOption { return WithScrubber(®exScrubber{ pattern: creditCardPattern, - replacement: "$1", + replacement: "", }) }