Skip to content

Commit

Permalink
test: added verify test
Browse files Browse the repository at this point in the history
  • Loading branch information
aldy505 committed May 26, 2021
1 parent d99ce74 commit 1e7ae19
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions phc-crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,48 @@ func TestPHCCrypto(t *testing.T) {
t.Error("returned type is not string")
}
})
t.Run("verify should return true", func(t *testing.T) {
crypto, err := phccrypto.Use("scrypt", phccrypto.Config{})
if err != nil {
t.Error(err)
}
hash, err := crypto.Hash("password123")
if err != nil {
t.Error(err)
}
verify, err := crypto.Verify(hash, "password123")
if err != nil {
t.Error(err)
}
typeof := reflect.TypeOf(verify).Kind()
if typeof != reflect.Bool {
t.Error("returned type is not boolean")
}
if !verify {
t.Error("verify function returned false")
}
})
t.Run("verify should return false", func(t *testing.T) {
crypto, err := phccrypto.Use("scrypt", phccrypto.Config{})
if err != nil {
t.Error(err)
}
hash, err := crypto.Hash("password123")
if err != nil {
t.Error(err)
}
verify, err := crypto.Verify(hash, "password321")
if err != nil {
t.Error(err)
}
typeof := reflect.TypeOf(verify).Kind()
if typeof != reflect.Bool {
t.Error("returned type is not boolean")
}
if verify {
t.Error("verify function returned false")
}
})
})
t.Run("bcrypt test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
Expand All @@ -61,6 +103,48 @@ func TestPHCCrypto(t *testing.T) {
t.Error("returned type is not string")
}
})
t.Run("verify should return true", func(t *testing.T) {
crypto, err := phccrypto.Use("bcrypt", phccrypto.Config{})
if err != nil {
t.Error(err)
}
hash, err := crypto.Hash("password123")
if err != nil {
t.Error(err)
}
verify, err := crypto.Verify(hash, "password123")
if err != nil {
t.Error(err)
}
typeof := reflect.TypeOf(verify).Kind()
if typeof != reflect.Bool {
t.Error("returned type is not boolean")
}
if !verify {
t.Error("verify function returned false")
}
})
t.Run("verify should return false", func(t *testing.T) {
crypto, err := phccrypto.Use("bcrypt", phccrypto.Config{})
if err != nil {
t.Error(err)
}
hash, err := crypto.Hash("password123")
if err != nil {
t.Error(err)
}
verify, err := crypto.Verify(hash, "password321")
if err != nil {
t.Error(err)
}
typeof := reflect.TypeOf(verify).Kind()
if typeof != reflect.Bool {
t.Error("returned type is not boolean")
}
if verify {
t.Error("verify function returned false")
}
})
})
t.Run("pbkdf2 test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
Expand Down

0 comments on commit 1e7ae19

Please sign in to comment.