26 Star 238 Fork 48

golang-module / dongle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bcrypt_test.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-12-07 09:04 . 统一单元测试格式
package dongle
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestBcrypt_String(t *testing.T) {
s1 := Sign.FromString("").ByBcrypt(10)
v1 := Verify.FromRawString(s1.ToRawString(), "").ByBcrypt()
assert.Equal(t, false, v1.ToBool())
s2 := Sign.FromString("hello world").ByBcrypt(10)
v2 := Verify.FromRawString(s2.ToRawString(), "hello world").ByBcrypt()
assert.Equal(t, true, v2.ToBool())
s3 := Sign.FromString("hello world").ByBcrypt()
v3 := Verify.FromRawString(s3.ToRawString(), "hello world").ByBcrypt()
assert.Equal(t, true, v3.ToBool())
s4 := Sign.FromString("hello world").ByBcrypt()
v4 := Verify.FromRawString(fmt.Sprintf("%s", s4), "hello world").ByBcrypt()
assert.Equal(t, true, v4.ToBool())
}
func TestBcrypt_Bytes(t *testing.T) {
s1 := Sign.FromBytes([]byte("")).ByBcrypt(1)
v1 := Verify.FromRawBytes(s1.ToRawBytes(), []byte("")).ByBcrypt()
assert.Equal(t, false, v1.ToBool())
s2 := Sign.FromBytes([]byte("hello world")).ByBcrypt(10)
v2 := Verify.FromRawBytes(s2.ToRawBytes(), []byte("hello world")).ByBcrypt()
assert.Equal(t, true, v2.ToBool())
}
func TestBcrypt_Rounds_Error(t *testing.T) {
s := Sign.FromString("hello world").ByBcrypt(1)
assert.Equal(t, invalidBcryptRoundsError(), s.Error)
}
Go
1
https://gitee.com/golang-module/dongle.git
git@gitee.com:golang-module/dongle.git
golang-module
dongle
dongle
master

搜索帮助