Skip to content

Commit

Permalink
[TASK] TRK-3577 N - Device ID masking GDPR - do not protect unknown o…
Browse files Browse the repository at this point in the history
…r N/A value (#35)
  • Loading branch information
tsknadaj authored Oct 14, 2024
1 parent f1d3980 commit a05669c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gdpr/protect_device_id.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package gdpr

import "strings"

const (
hiddenRune = '*'
hiddenRune = '*'
unknownValue = "unknown"
nonAvailableValue = "n/a"
)

// ProtectDeviceID hides last two character from passed device id and returns string with protected value
Expand All @@ -10,6 +14,11 @@ func ProtectDeviceID(val string) string {
return val
}

lowered := strings.ToLower(val)
if lowered == unknownValue || lowered == nonAvailableValue {
return val
}

r := []rune(val)
l := len(r)

Expand Down
75 changes: 75 additions & 0 deletions gdpr/protect_device_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ func Test_ProtectDeviceID(t *testing.T) {
value: "",
want: "",
},
{
name: "unknown value - lower case",
value: "unknown",
want: "unknown",
},
{
name: "unknown value - upper case",
value: "UNKNOWN",
want: "UNKNOWN",
},
{
name: "unknown value - mixed case",
value: "unKNowN",
want: "unKNowN",
},
{
name: "non available value - upper case",
value: "N/A",
want: "N/A",
},
{
name: "non available value - lower case",
value: "n/a",
want: "n/a",
},
{
name: "non available value - mixed case",
value: "n/A",
want: "n/A",
},
{
name: "correct value to protect",
value: "some_value",
Expand Down Expand Up @@ -56,3 +86,48 @@ func BenchmarkProtectDeviceID(b *testing.B) {
ProtectDeviceID(strconv.Itoa(i))
}
}

func BenchmarkProtectDeviceID_Empty(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("")
}
}

func BenchmarkProtectDeviceID_NA_Mixed(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("N/a")
}
}

func BenchmarkProtectDeviceID_NA_Lower(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("n/a")
}
}

func BenchmarkProtectDeviceID_Unknown_Mixed(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("Unknown")
}
}

func BenchmarkProtectDeviceID_Unknown_Lower(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("unknown")
}
}

0 comments on commit a05669c

Please sign in to comment.