Skip to content

Commit

Permalink
Address review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RouganStriker authored and junkert committed Dec 4, 2023
1 parent e16dbca commit f1d3435
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ Below is a list of fake data creators and scramblers. This table may not be up t
| Processor Name | Use |
| -------------- |:----|
| AlphaNumericScrambler | Scrambles strings. If a number is in the string it will replace it with another random number
| UniqueAlphaNumericScrambler | Similar to AlphaNumericScrambler but that all scrambled strings in the table column will be unique.
| EmptyJson | Replaces a JSON with an empty one (`{}`)
| FakeStreetAddress | Used to replace a real US address with a fake one
| FakeCity | Used to replace a city column
Expand All @@ -261,6 +260,7 @@ Below is a list of fake data creators and scramblers. This table may not be up t
| RandomDigits | Randomizes a string of digit(s), but keeps the same length
| RandomUUID | Randomizes a UUID string, but keep a mapping of the old UUID and map it to the new UUID. If the old is found elsewhere in the database the new UUID will be used instead of creating another one. Useful for UUID primary key mapping (relationships).
| ScrubString | Replaces a string with \*'s. Useful for password hashes.
| UniqueAlphaNumericScrambler | Similar to AlphaNumericScrambler but that all scrambled strings in the table column will be unique.

#### Inclusive Map Files
An *inclusive* map file is a map file which includes every column in every table that is contained in a list of schemas
Expand Down
2 changes: 1 addition & 1 deletion processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ var UUIDMap = safeUUIDMap{
func init() {
ProcessorCatalog = map[string]ProcessorFunc{
"AlphaNumericScrambler": ProcessorAlphaNumericScrambler,
"UniqueAlphaNumericScrambler": ProcessorUniqueAlphaNumericScrambler,
"EmptyJson": ProcessorEmptyJson,
"FakeStreetAddress": ProcessorAddress,
"FakeCity": ProcessorCity,
Expand All @@ -208,6 +207,7 @@ func init() {
"RandomDigits": ProcessorRandomDigits,
"RandomUUID": ProcessorRandomUUID,
"ScrubString": ProcessorScrubString,
"UniqueAlphaNumericScrambler": ProcessorUniqueAlphaNumericScrambler,
}

}
Expand Down
89 changes: 35 additions & 54 deletions processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ var cMap = ColumnMapper{
Comment: "",
}

// Pre-generated scrambled strings for the text "This is my unscrambled text" using a fixed rng seed
const rngSeed = 5336
var preGeneratedScrambledStrings = []string{
"Hdva nn ef lujjclagwxv mdtj",
"Wjpp vj nw idiicqtcaab yyoy",
"Whcg fx cz qdtmlhiyyse bmnn",
"Qneu ci nn uknqprmkygn oqic",
"Awsf mm ga gbafitnmqnv uats",
"Xvga jz fm ymbeyrhovce zfft",
"Jcev we tx yozybzwejug wcor",
"Pktc fh rg zblwnrixhel xddv",
"Mmfl iu ai lkarkpjxrcm gihj",
"Xatp qr ud jkwiapqpekp jvmy",
"Gvom pt zh qngneelcwne bqyk",
"Uegd el xu afeqhhkrrsg aocg",
"Vcbu om az wphtejtptqu wmvq",
"Vdto fu qx xvtchqlafpw vxcg",
"Zhjf nh sg umiyxwlwobn nwuk",
"Gnno uf if divtacntszp armf",
"Gvth xk ma nqpvrdtmylr tqje",
"Grqz ai tl amqkfzrhhca bjzh",
"Abzk jp bq nbhbdhtypbl gvxf",
"Xoxg sl uf dimoothtcqv iwtw",
"Aiya kb zg ljctcijzuyj fqze",
}


func TestProcessorFunc(t *testing.T) {
}

Expand Down Expand Up @@ -124,40 +151,17 @@ func TestProcessorUniqueAlphaNumericScramblerBehavesLikeProcessorAlphaNumericScr
}

func TestProcessorUniqueAlphaNumericScramblerEnsuresUniqueness(t *testing.T) {
rand.Seed(5336)

// Use a fixed seed to pre-generate the scrambled strings
preGeneratedUniqueStrings := []string{
"Hdva nn ef lujjclagwxv mdtj",
"Wjpp vj nw idiicqtcaab yyoy",
"Whcg fx cz qdtmlhiyyse bmnn",
"Qneu ci nn uknqprmkygn oqic",
"Awsf mm ga gbafitnmqnv uats",
"Xvga jz fm ymbeyrhovce zfft",
"Jcev we tx yozybzwejug wcor",
"Pktc fh rg zblwnrixhel xddv",
"Mmfl iu ai lkarkpjxrcm gihj",
"Xatp qr ud jkwiapqpekp jvmy",
"Gvom pt zh qngneelcwne bqyk",
"Uegd el xu afeqhhkrrsg aocg",
"Vcbu om az wphtejtptqu wmvq",
"Vdto fu qx xvtchqlafpw vxcg",
"Zhjf nh sg umiyxwlwobn nwuk",
"Gnno uf if divtacntszp armf",
"Gvth xk ma nqpvrdtmylr tqje",
"Grqz ai tl amqkfzrhhca bjzh",
"Abzk jp bq nbhbdhtypbl gvxf",
"Xoxg sl uf dimoothtcqv iwtw",
"Aiya kb zg ljctcijzuyj fqze",
}
// Set a fixed rng seed
rand.Seed(rngSeed)

var found struct{}
tableKey := fmt.Sprintf("%s.%s.%s", cMap.TableSchema, cMap.TableName, cMap.ColumnName)

// Pre-populate the mapping to check that the scrambler only returns unique values
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = safeStringMap{
v: make(map[string]struct{}),
}
for _, scrambledString := range preGeneratedUniqueStrings {
for _, scrambledString := range preGeneratedScrambledStrings {
UniqueScrambledColumnValueMap.uniqueMap[tableKey].v[scrambledString] = found
}

Expand All @@ -168,40 +172,17 @@ func TestProcessorUniqueAlphaNumericScramblerEnsuresUniqueness(t *testing.T) {
}

func TestProcessorUniqueAlphaNumericScramblerEnsuresUniquenessPerColumn(t *testing.T) {
rand.Seed(5336)

// Use a fixed seed to pre-generate the scrambled strings
preGeneratedUniqueStrings := []string{
"Hdva nn ef lujjclagwxv mdtj",
"Wjpp vj nw idiicqtcaab yyoy",
"Whcg fx cz qdtmlhiyyse bmnn",
"Qneu ci nn uknqprmkygn oqic",
"Awsf mm ga gbafitnmqnv uats",
"Xvga jz fm ymbeyrhovce zfft",
"Jcev we tx yozybzwejug wcor",
"Pktc fh rg zblwnrixhel xddv",
"Mmfl iu ai lkarkpjxrcm gihj",
"Xatp qr ud jkwiapqpekp jvmy",
"Gvom pt zh qngneelcwne bqyk",
"Uegd el xu afeqhhkrrsg aocg",
"Vcbu om az wphtejtptqu wmvq",
"Vdto fu qx xvtchqlafpw vxcg",
"Zhjf nh sg umiyxwlwobn nwuk",
"Gnno uf if divtacntszp armf",
"Gvth xk ma nqpvrdtmylr tqje",
"Grqz ai tl amqkfzrhhca bjzh",
"Abzk jp bq nbhbdhtypbl gvxf",
"Xoxg sl uf dimoothtcqv iwtw",
"Aiya kb zg ljctcijzuyj fqze",
}
// Set a fixed rng seed
rand.Seed(rngSeed)

var found struct{}
tableKey := fmt.Sprintf("%s.%s.%s", cMap.TableSchema, cMap.TableName, cMap.ColumnName)

// Pre-populate the mapping to check that the scrambler only returns unique values
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = safeStringMap{
v: make(map[string]struct{}),
}
for _, scrambledString := range preGeneratedUniqueStrings {
for _, scrambledString := range preGeneratedScrambledStrings {
UniqueScrambledColumnValueMap.uniqueMap[tableKey].v[scrambledString] = found
}

Expand Down

0 comments on commit f1d3435

Please sign in to comment.