diff --git a/gdpr/protect_device_id.go b/gdpr/protect_device_id.go index c90112e..949ba53 100644 --- a/gdpr/protect_device_id.go +++ b/gdpr/protect_device_id.go @@ -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 @@ -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) diff --git a/gdpr/protect_device_id_test.go b/gdpr/protect_device_id_test.go index 9cdd40f..fb94f80 100644 --- a/gdpr/protect_device_id_test.go +++ b/gdpr/protect_device_id_test.go @@ -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", @@ -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") + } +}