diff options
Diffstat (limited to 'tests')
l--------- | tests/benchmarks/hash/main.go | 1 | ||||
-rw-r--r-- | tests/benchmarks/hash/scrypt.go | 28 | ||||
l--------- | tests/functional/hash-and-check/main.go | 1 | ||||
-rw-r--r-- | tests/functional/hash-and-check/scrypt.go | 40 | ||||
l--------- | tests/fuzz/api/main.go | 1 | ||||
-rw-r--r-- | tests/fuzz/api/scrypt.go | 37 | ||||
-rw-r--r-- | tests/libbuild.go | 22 |
7 files changed, 108 insertions, 22 deletions
diff --git a/tests/benchmarks/hash/main.go b/tests/benchmarks/hash/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/hash/main.go @@ -0,0 +1 @@ +../../main.go
\ No newline at end of file diff --git a/tests/benchmarks/hash/scrypt.go b/tests/benchmarks/hash/scrypt.go new file mode 100644 index 0000000..82f9ed5 --- /dev/null +++ b/tests/benchmarks/hash/scrypt.go @@ -0,0 +1,28 @@ +package scrypt + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 100, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + password := []byte("password") + salt := []byte("salt0123456789abcdef0123456789abcdef") + + for i := 0; i < n; i++ { + _, err := Hash(password, salt) + if err != nil { + panic(err) + } + } +} diff --git a/tests/functional/hash-and-check/main.go b/tests/functional/hash-and-check/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/functional/hash-and-check/main.go @@ -0,0 +1 @@ +../../main.go
\ No newline at end of file diff --git a/tests/functional/hash-and-check/scrypt.go b/tests/functional/hash-and-check/scrypt.go new file mode 100644 index 0000000..17f2982 --- /dev/null +++ b/tests/functional/hash-and-check/scrypt.go @@ -0,0 +1,40 @@ +package scrypt + +import ( + g "gobang" + +) + + + +func MainTest() { + g.Testing("from a known input we check the hash", func() { + const ( + password = "a fixed password" + salt = "a fixed salt____________________" + ) + + hash, err := Hash([]byte(password), []byte(salt)) + g.TErrorIf(err) + + ok, err := Check([]byte(password), []byte(salt), hash) + g.TErrorIf(err) + g.TAssertEqual(ok, true) + }) + + g.Testing("we can genereate a hash and check it is equal", func() { + password, err := Salt() + g.TErrorIf(err) + + salt, err := Salt() + g.TErrorIf(err) + + hash, err := Hash(password, salt) + g.TErrorIf(err) + + ok, err := Check(password, salt, hash) + g.TErrorIf(err) + + g.TAssertEqual(ok, true) + }) +} diff --git a/tests/fuzz/api/main.go b/tests/fuzz/api/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/fuzz/api/main.go @@ -0,0 +1 @@ +../../main.go
\ No newline at end of file diff --git a/tests/fuzz/api/scrypt.go b/tests/fuzz/api/scrypt.go new file mode 100644 index 0000000..eb29d2d --- /dev/null +++ b/tests/fuzz/api/scrypt.go @@ -0,0 +1,37 @@ +package scrypt + +import ( + "os" + "testing" + "testing/internal/testdeps" +) + + + +func api(f *testing.F) { + f.Fuzz(func(t *testing.T, password []byte, salt []byte) { + if len(salt) < saltMinLength { + return + } + + _, err := Hash(password, salt) + if err != nil { + t.Errorf("Failed on: %#v\n", err) + } + }) +} + + + +func MainTest() { + fuzzTargets := []testing.InternalFuzzTarget{ + { "api", api }, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples) + os.Exit(m.Run()) +} diff --git a/tests/libbuild.go b/tests/libbuild.go deleted file mode 100644 index 31e93c9..0000000 --- a/tests/libbuild.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "encoding/hex" - - g "gobang" - - "scrypt" -) - -func main() { - s1, err := scrypt.Salt() - g.TErrorIf(err) - - s2, err := scrypt.Salt() - g.TErrorIf(err) - - hash, err := scrypt.Hash(s1, s2) - g.TErrorIf(err) - - println(hex.EncodeToString(hash)) -} |