summaryrefslogtreecommitdiff
path: root/tests/scrypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/scrypt.go')
-rw-r--r--tests/scrypt.go112
1 files changed, 109 insertions, 3 deletions
diff --git a/tests/scrypt.go b/tests/scrypt.go
index 710ea82..0a9f599 100644
--- a/tests/scrypt.go
+++ b/tests/scrypt.go
@@ -217,7 +217,7 @@ func test_Hash() {
salt, err := Salt()
g.TErrorIf(err)
- input := HashInput{
+ input := HashInputT{
Password: password,
Salt: salt,
}
@@ -236,7 +236,7 @@ func test_Check() {
g.TestStart("Check()")
h := func(password []byte, salt []byte) []byte {
- input := HashInput{
+ input := HashInputT{
Password: password,
Salt: salt,
}
@@ -246,7 +246,7 @@ func test_Check() {
}
chk := func(password []byte, salt []byte, hash []byte) bool {
- input := CheckInput{
+ input := CheckInputT{
Password: password,
Salt: salt,
Hash: hash,
@@ -301,12 +301,118 @@ func test_Check() {
})
}
+func test_usage() {
+ g.TestStart("usage()")
+
+ g.Testing("it writes the usage string to the io.Writer", func() {
+ w := strings.Builder{}
+ usage("xxx", &w)
+
+ expected := g.Heredoc(`
+ Usage: xxx PASSWORD SALT
+ `)
+ g.TAssertEqual(w.String(), expected)
+ })
+}
+
+func test_getopt() {
+ g.TestStart("getopt()")
+
+ usage := g.Heredoc(`
+ Usage: $0 PASSWORD SALT
+ `)
+
+ g.Testing("we suppress the default error message", func() {
+ w := strings.Builder{}
+ argv := []string{"$0", "-h"}
+ _, rc := getopt(argv, &w)
+
+ g.TAssertEqual(w.String(), usage)
+ g.TAssertEqual(rc, 2)
+ })
+
+ g.Testing("we get an unsupported option error", func() {
+ w := strings.Builder{}
+ argv := []string{"$0", "-a"}
+ _, rc := getopt(argv, &w)
+
+ const message = "flag provided but not defined: -a\n"
+ g.TAssertEqual(w.String(), message + usage)
+ g.TAssertEqual(rc, 2)
+ })
+
+ g.Testing("the args have the input data", func() {
+ w := strings.Builder{}
+ argv := []string{"$0", "abcdef", "aaaabbbbccccdddd"}
+ args, rc := getopt(argv, &w)
+
+ expected := argsT{
+ allArgs: []string{"$0", "abcdef", "aaaabbbbccccdddd"},
+ input: HashInputT{
+ Password: []byte("abcdef"),
+ Salt: []byte("aaaabbbbccccdddd"),
+ },
+ }
+
+ g.TAssertEqual(args, expected)
+ g.TAssertEqual(rc, 0)
+ })
+}
+
+func test_run() {
+ g.TestStart("run()")
+
+ g.Testing("a small salt returns 1", func() {
+ w := strings.Builder{}
+ env := envT{
+ args: argsT{
+ input: HashInputT{
+ Salt: []byte("a salt"),
+ },
+ },
+ err: &w,
+ }
+
+ rc := run(env)
+ g.TAssertEqual(rc, 1)
+ g.TAssertEqual(w.String(), "scrypt: salt is too small\n")
+ })
+
+ g.Testing("return of 0 and output otherwise", func() {
+ w := strings.Builder{}
+ env := envT{
+ args: argsT{
+ input: HashInputT{
+ Salt: []byte(
+ "eeeeffffgggghhhh" +
+ "iiiijjjjjkkkkllll",
+ ),
+ Password: []byte("password"),
+ },
+ },
+ out: &w,
+ }
+
+ const expected =
+ "9073ca9ad51942a30b20af1747e98195" +
+ "960e76fd8f20b246821692ce82c2d6f7\n"
+ rc := run(env)
+ g.TAssertEqual(w.String(), expected)
+ g.TAssertEqual(rc, 0)
+ })
+}
+
func MainTest() {
+ g.Init()
+
test_scrypt()
test_SaltFrom()
test_Salt()
test_Hash()
test_Check()
+ test_usage()
+ test_getopt()
+ test_run()
}