Files
2026-06-05 14:12:48 +08:00

44 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package nuoer
import "testing"
func TestMD5Encrypt(t *testing.T) {
got := MD5Encrypt("13290879000")
want := genMD5("13290879000")
if got != want {
t.Fatalf("MD5Encrypt mismatch: got %s want %s", got, want)
}
}
func TestEncryptBodyMD5(t *testing.T) {
body := map[string]string{
"idCard": "330129199511153412",
"mobile": "13290879000",
}
got := encryptBodyMD5(body)
if got["idCard"] != MD5Encrypt("330129199511153412") {
t.Fatalf("idCard not encrypted: got %s", got["idCard"])
}
if got["mobile"] != MD5Encrypt("13290879000") {
t.Fatalf("mobile not encrypted: got %s", got["mobile"])
}
}
func TestSign(t *testing.T) {
body := map[string]string{
"name": "张三",
"mobile": "13290879000",
"idCard": "330129199511153412",
}
secret := "secret"
got := Sign(body, secret)
if got == "" {
t.Fatal("sign should not be empty")
}
// 文档示例name张三mobile13290879000idCard330129199511153412secret
want := genMD5("idCard330129199511153412mobile13290879000name张三secret")
if got != want {
t.Fatalf("sign mismatch: got %s want %s", got, want)
}
}