diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/benchmarks/hash/scrypt.go | 2 | ||||
-rw-r--r-- | tests/functional/hash-and-check/scrypt.go | 8 | ||||
-rw-r--r-- | tests/fuzz/api/scrypt.go | 2 | ||||
-rwxr-xr-x | tests/integration.sh | 2 | ||||
-rw-r--r-- | tests/scrypt.go | 112 |
5 files changed, 116 insertions, 10 deletions
diff --git a/tests/benchmarks/hash/scrypt.go b/tests/benchmarks/hash/scrypt.go index 54657d0..894e6da 100644 --- a/tests/benchmarks/hash/scrypt.go +++ b/tests/benchmarks/hash/scrypt.go @@ -18,7 +18,7 @@ func MainTest() { password := []byte("password") salt := []byte("salt0123456789abcdef0123456789abcdef") - input := HashInput{ + input := HashInputT{ Password: password, Salt: salt, } diff --git a/tests/functional/hash-and-check/scrypt.go b/tests/functional/hash-and-check/scrypt.go index 065b9b5..9eeeb22 100644 --- a/tests/functional/hash-and-check/scrypt.go +++ b/tests/functional/hash-and-check/scrypt.go @@ -14,14 +14,14 @@ func MainTest() { salt = []byte("a fixed salt____________________") ) - hashInput := HashInput{ + hashInput := HashInputT{ Password: password, Salt: salt, } hash, err := Hash(hashInput) g.TErrorIf(err) - checkInput := CheckInput{ + checkInput := CheckInputT{ Password: password, Salt: salt, Hash: hash, @@ -38,14 +38,14 @@ func MainTest() { salt, err := Salt() g.TErrorIf(err) - hashInput := HashInput{ + hashInput := HashInputT{ Password: password, Salt: salt, } hash, err := Hash(hashInput) g.TErrorIf(err) - checkInput := CheckInput{ + checkInput := CheckInputT{ Password: password, Salt: salt, Hash: hash, diff --git a/tests/fuzz/api/scrypt.go b/tests/fuzz/api/scrypt.go index c037add..7c2c503 100644 --- a/tests/fuzz/api/scrypt.go +++ b/tests/fuzz/api/scrypt.go @@ -14,7 +14,7 @@ func api(f *testing.F) { return } - input := HashInput{ + input := HashInputT{ Password: password, Salt: salt, } diff --git a/tests/integration.sh b/tests/integration.sh index e31ae4d..8115ce5 100755 --- a/tests/integration.sh +++ b/tests/integration.sh @@ -13,7 +13,7 @@ test_needs_minimum_salt_length() { trap 'rm -f "$OUT" "$ERR"' EXIT STATUS=0 ./scrypt.bin password salt 1>"$OUT" 2>"$ERR" || STATUS=$? - assert_status 2 + assert_status 1 assert_empty_stdout assert_fgrep_stderr 'salt is too small' rm -f "$OUT" "$ERR" 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() } |