|
|
@ -2,20 +2,21 @@ package scrub |
|
|
|
|
|
|
|
import "testing" |
|
|
|
|
|
|
|
var testEntropy = []struct { |
|
|
|
Test, Want string |
|
|
|
}{ |
|
|
|
{"", ""}, |
|
|
|
{"1223334444", "1223334444"}, |
|
|
|
{"password123", Replacement}, |
|
|
|
{"Tr0ub4dour&3", Replacement}, |
|
|
|
{"test correcthorsebatterystaple", "test correcthorsebatterystaple"}, |
|
|
|
{"test coRrecth0rseba++ery9.23.2007staple$", "test " + Replacement}, |
|
|
|
{"rWibMFACxAUGZmxhVncy test", Replacement + " test"}, |
|
|
|
{"test Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$ test", "test " + Replacement + " test"}, |
|
|
|
} |
|
|
|
|
|
|
|
func TestEntropy(t *testing.T) { |
|
|
|
tests := []struct { |
|
|
|
Test, Want string |
|
|
|
}{ |
|
|
|
{"", ""}, |
|
|
|
{"1223334444", "1223334444"}, |
|
|
|
{"password123", Replacement}, |
|
|
|
{"Tr0ub4dour&3", Replacement}, |
|
|
|
{"test correcthorsebatterystaple", "test correcthorsebatterystaple"}, |
|
|
|
{"test coRrecth0rseba++ery9.23.2007staple$", "test " + Replacement}, |
|
|
|
{"rWibMFACxAUGZmxhVncy test", Replacement + " test"}, |
|
|
|
{"test Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$ test", "test " + Replacement + " test"}, |
|
|
|
} |
|
|
|
for _, test := range tests { |
|
|
|
for _, test := range testEntropy { |
|
|
|
t.Run(test.Test, func(it *testing.T) { |
|
|
|
if v := Entropy(test.Test); v != test.Want { |
|
|
|
it.Errorf("expected %q to return %q, got %q", test.Test, test.Want, v) |
|
|
@ -24,9 +25,20 @@ func TestEntropy(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestEntropyScrubber_Scrub(t *testing.T) { |
|
|
|
var scrubber EntropyScrubber // using defaults
|
|
|
|
for _, test := range testEntropy { |
|
|
|
t.Run(test.Test, func(it *testing.T) { |
|
|
|
if v := scrubber.Scrub(test.Test); v != test.Want { |
|
|
|
it.Errorf("expected %q to return %q, got %q", test.Test, test.Want, v) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestEntropyScrubber(t *testing.T) { |
|
|
|
scrubber := EntropyScrubber{ |
|
|
|
Whitespace: DefaultWhitespace, |
|
|
|
Whitespace: []rune(DefaultWhitespace), |
|
|
|
Threshold: DefaultEntropyThreshold, |
|
|
|
} |
|
|
|
tests := []struct { |
|
|
|