From 8dc3d5485c8de6d0398d5df5a6fc4682687f4c9b Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 6 Aug 2024 11:00:32 -0300 Subject: tests/gobang.go: Add tests for Random(), Salt() and Hash() --- tests/gobang.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/gobang.go') diff --git a/tests/gobang.go b/tests/gobang.go index 46cc9c5..324a155 100644 --- a/tests/gobang.go +++ b/tests/gobang.go @@ -10,6 +10,7 @@ import ( "fmt" "hash" "log/slog" + "os" "time" ) @@ -345,6 +346,42 @@ func test_scrypt() { }) } +func test_Random() { + TestStart("Random()") + + Testing("we get the desired output size", func() { + for i := 0; i < 100; i++ { + buffer := Random(i) + AssertEqual(len(buffer), i) + } + }) +} + +func test_Salt() { + TestStart("Salt()") + + Testing("we generate a random salt of a fixed size", func() { + salt := Salt() + AssertEqual(len(salt), scryptSaltMinLength) + + var buffer [scryptSaltMinLength * 2]byte + hex.Encode(buffer[:], salt) + fmt.Fprintf(os.Stderr, "%s ", string(buffer[:])) + }) +} + +func test_Hash() { + TestStart("Hash()") + + Testing("same input, same output", func() { + password := Random(16) + salt := Salt() + hash1 := Hash(password, salt) + hash2 := Hash(password, salt) + AssertEqual(hash1, hash2) + }) +} + func test_newUUIDFrom() { TestStart("newUUIDFrom()") @@ -480,6 +517,9 @@ func TestSetLoggerOutput() { func MainTest() { test__PBKDF() test_scrypt() + test_Hash() + test_Random() + test_Salt() test_newUUIDFrom() test_NewUUID() test_UUIDString() -- cgit v1.2.3