Initial commit
This commit is contained in:
41
encrypt_test.go
Normal file
41
encrypt_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package persist
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUser_EncryptPassword(t *testing.T) {
|
||||
u := &User{
|
||||
Password: "1234",
|
||||
}
|
||||
|
||||
encrypted := u.EncryptPassword()
|
||||
|
||||
if u.Password != encrypted {
|
||||
t.Fatal("Failed to encrypt password")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_CheckPassword(t *testing.T) {
|
||||
u := &User{
|
||||
Password: "1234",
|
||||
}
|
||||
|
||||
u.EncryptPassword()
|
||||
|
||||
if !u.CheckPassword("1234") {
|
||||
t.Fatal("Failed to check password")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_CheckPassword_FalsePositive(t *testing.T) {
|
||||
u := &User{
|
||||
Password: "1234",
|
||||
}
|
||||
|
||||
u.EncryptPassword()
|
||||
|
||||
if u.CheckPassword("!234") {
|
||||
t.Fatal("Should have not accepted password")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user