All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Signed-off-by: Asai Neko <sugar@sne.moe>
37 lines
874 B
Go
37 lines
874 B
Go
package cryptography
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"github.com/stretchr/testify/assert"
|
||
"github.com/stretchr/testify/require"
|
||
)
|
||
|
||
func TestBcryptHashAndVerify(t *testing.T) {
|
||
input := "super-secret-password"
|
||
hash, err := BcryptHash(input)
|
||
require.NoError(t, err)
|
||
require.NotEmpty(t, hash)
|
||
assert.NotEqual(t, input, hash)
|
||
assert.True(t, BcryptVerify(input, hash))
|
||
}
|
||
|
||
func TestBcryptVerifyWrongPassword(t *testing.T) {
|
||
hash, err := BcryptHash("correct-password")
|
||
require.NoError(t, err)
|
||
assert.False(t, BcryptVerify("wrong-password", hash))
|
||
}
|
||
|
||
func TestBcryptHashUniqueness(t *testing.T) {
|
||
h1, _ := BcryptHash("same")
|
||
h2, _ := BcryptHash("same")
|
||
// bcrypt uses a random salt – hashes must differ
|
||
assert.NotEqual(t, h1, h2)
|
||
}
|
||
|
||
func TestBcryptHashEmptyInput(t *testing.T) {
|
||
hash, err := BcryptHash("")
|
||
require.NoError(t, err)
|
||
assert.True(t, BcryptVerify("", hash))
|
||
}
|