Skip to content

Commit

Permalink
Fix Latitude and Longitude anonymization (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
reidab authored Sep 23, 2022
1 parent 17d2104 commit 9171d25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/anonymiser/anonymiser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
literalPrefix = "literal:"
email = "EmailAddress"
username = "UserName"
latitude = "Latitude"
longitude = "Longitude"
)

var requireArgs = map[string]bool{
Expand Down Expand Up @@ -97,6 +99,8 @@ func (a *anonymiser) ReadTable(tableName string, rowChan chan<- database.Row, op
faker.Call([]reflect.Value{})[0].String(),
hex.EncodeToString(b),
)
case latitude, longitude:
value = fmt.Sprintf("%f", faker.Call(args)[0].Float())
default:
value = faker.Call(args)[0].String()
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/anonymiser/anonymiser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func TestReadTable(t *testing.T) {
opts: reader.ReadTableOpt{},
config: config.Tables{{Name: "test", Anonymise: map[string]string{"column_test": "literal:Hello"}}},
},
{
scenario: "when column is anonymised with float value",
function: testWhenColumnIsAnonymisedWithFloatValue,
opts: reader.ReadTableOpt{},
config: config.Tables{{Name: "test", Anonymise: map[string]string{"column_test": "Latitude"}}},
},
{
scenario: "when column anonymiser in invalid",
function: testWhenColumnAnonymiserIsInvalid,
Expand Down Expand Up @@ -143,6 +149,24 @@ func testWhenColumnIsAnonymisedWithLiteral(t *testing.T, opts reader.ReadTableOp
}
}

func testWhenColumnIsAnonymisedWithFloatValue(t *testing.T, opts reader.ReadTableOpt, tables config.Tables) {
anonymiser := NewAnonymiser(&mockReader{}, tables)

rowChan := make(chan database.Row)
defer close(rowChan)

err := anonymiser.ReadTable("test", rowChan, opts)
require.NoError(t, err)

timeoutChan := time.After(waitTimeout)
select {
case row := <-rowChan:
assert.NotEqual(t, "<float32 Value>", row["column_test"])
case <-timeoutChan:
assert.FailNow(t, "Failing due to timeout")
}
}

func testWhenColumnAnonymiserIsInvalid(t *testing.T, opts reader.ReadTableOpt, tables config.Tables) {
anonymiser := NewAnonymiser(&mockReader{}, tables)

Expand Down

0 comments on commit 9171d25

Please sign in to comment.