goProject/.svn/pristine/c0/c039b778dc27da0bcdd2b2ba3f68ccff92a08c4e.svn-base
2025-01-06 16:21:36 +08:00

41 lines
1.2 KiB
Plaintext

package securityUtil
import (
"fmt"
"testing"
)
var (
ExpectedUpperString = "5EB63BBBE01EEED093CB22BB8F5ACDC3"
ExpectedLowerString = "5eb63bbbe01eeed093cb22bb8f5acdc3"
)
func TestMd5String(t *testing.T) {
s := fmt.Sprintf("&GroupId=%s&ClusterId=%s&IP=%s&ServiceName=%s&ServiceId=%s&Timestamp=%d&GroupSecret=%s",
"DSN", "DSN_AREA1", "10.255.0.226", "gs1", "4fa2b870-f8eb-4a47-a4bb-becf14f3b628", 1649212351304327500, "88F5BC56-96D3-4021-A358-BBDAFFBF772A")
//s := "hello world"
result := Md5String(s, true)
if result != ExpectedUpperString {
t.Errorf("Md5String(\"hello world\") failed.Got %s, expected %s", result, ExpectedUpperString)
}
result = Md5String(s, false)
if result != ExpectedLowerString {
t.Errorf("Md5String(\"hello world\") failed.Got %s, expected %s", result, ExpectedLowerString)
}
}
func TestMd5Bytes(t *testing.T) {
s := "hello world"
b := []byte(s)
result := Md5Bytes(b, true)
if result != ExpectedUpperString {
t.Errorf("Md5String(\"hello world\") failed.Got %s, expected %s", result, ExpectedUpperString)
}
result = Md5Bytes(b, false)
if result != ExpectedLowerString {
t.Errorf("Md5String(\"hello world\") failed.Got %s, expected %s", result, ExpectedLowerString)
}
}