31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package gameplatform
|
|
|
|
import "testing"
|
|
|
|
func TestLegacyPasswordFormats(t *testing.T) {
|
|
p := &Passwords{AuthCode: "test-auth", MigrateAuthCode: "test-migrate", TablePrefix: "sys_"}
|
|
// 固定向量由独立的 Python hashlib 按原 Java 算法生成。
|
|
for _, hash := range []string{"###eef6d9b7160f32a869f3e03b7ea575a5", "9db2515d8fcc62cc2d8b4bf2d8728120d052163a77df7f09", "##$##073cf9a979400c63c0dc69f201efcdf8"} {
|
|
if ok, err := p.Verify("demo123", hash); err != nil || !ok {
|
|
t.Fatalf("旧密码格式不兼容: %v", err)
|
|
}
|
|
if ok, _ := p.Verify("wrong", hash); ok {
|
|
t.Fatal("错误密码被接受")
|
|
}
|
|
}
|
|
if ok, err := (&Passwords{}).Verify("demo123", "###eef6d9b7160f32a869f3e03b7ea575a5"); ok || err == nil {
|
|
t.Fatal("缺少兼容盐时必须明确报错")
|
|
}
|
|
}
|
|
|
|
func TestNewChannelPasswordMatchesLegacyFixedVector(t *testing.T) {
|
|
passwords := &Passwords{AuthCode: "test-auth"}
|
|
hash, err := passwords.Encode("demo123")
|
|
if err != nil || hash != "###eef6d9b7160f32a869f3e03b7ea575a5" {
|
|
t.Fatal("新渠道密码与旧平台格式不兼容")
|
|
}
|
|
if _, err := (&Passwords{}).Encode("demo123"); err == nil {
|
|
t.Fatal("缺少盐不能写入不可登录的渠道密码")
|
|
}
|
|
}
|