Data scrubbing options for protecting sensitive data https://godoc.org/maze.io/x/scrub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.0 KiB

package scrub
import (
"strings"
"testing"
)
type testScrubberCase struct {
Test, Want string
}
func testScrubber(t *testing.T, s Scrubber, tests []testScrubberCase) {
t.Helper()
for _, test := range tests {
t.Run(strings.SplitN(test.Want, "\n", 2)[0], func(it *testing.T) {
if result := s.Scrub(test.Test); result != test.Want {
it.Fatalf("expected %q, got %q", test.Want, result)
} else {
it.Log(result)
}
})
}
}
var testAllCases = []testScrubberCase{
// Command tests.
{"/usr/bin/mysqldump", "/usr/bin/mysqldump"},
{"mysqldump -u john -h localhost", "mysqldump -u john -h localhost"},
{"mysqldump -u john -p testing -h localhost", "mysqldump -u john -p*redacted* -h localhost"},
{"/opt/sap/bin/mysqldump -u john -p testing -h localhost", "/opt/sap/bin/mysqldump -u john -p*redacted* -h localhost"},
// Entropy tests.
// No scrubbing:
{"ps axufwww", "ps axufwww"},
// Secret scrubbing:
{"chpasswd root coRrecth0rseba++ery9.23.2007staple$", "chpasswd root *redacted*"},
// Password tests.
{"$0$testing", "$0$*redacted*"},
{`$2a$06$/3OeRpbOf8/l6nPPRdZPp.nRiyYqPobEZGdNRBWihQhiFDh1ws1tu`, `$2a$*redacted*`},
{`$6$Np2eF8019ITolL$Q4ZB.EYJdr8nD8OyNPnOTuntLbZXl3YN5r49qtRZDd9JOR.5j1s6zQ7zPekxpVi1WEQ7pYB0AJkHU61Th6Ndf0`, `$6$*redacted*`},
{`$5$rounds=80000$wnsT7Yr92oJoP28r$cKhJImk5mfuSKV9b3mumNzlbstFUplKtQXXMo4G6Ep5`, `$5$*redacted*`},
{`$sha1$c6218$161d1ac8ab38979c5a31cbaba4a67378e7e60845`, `$sha1$*redacted*`},
// PEM tests.
{Test: testDHParams, Want: wantDHParams},
{Test: testRSAPrivateKey, Want: wantRSAPrivateKey},
{Test: testSSHEd25519Key, Want: wantSSHEd25519Key},
}
func TestAll(t *testing.T) {
testScrubber(t, All, testAllCases)
}
/*
func TestReader(t *testing.T) {
for _, test := range testAllCases {
t.Run(test.Test, func(it *testing.T) {
r := Reader(bytes.NewBufferString(test.Test), All)
b, err := ioutil.ReadAll(r)
if err != nil {
it.Fatal(err)
}
if result := string(b); result != test.Want {
it.Fatalf("expected %q, got %q", test.Want, result)
}
})
}
}
*/