6
0
gaore-common-sdk-go/services/chat/open_sign_test.go

24 lines
505 B
Go
Raw 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 chat
import (
"crypto/md5"
"encoding/hex"
"testing"
)
// TestSignOpenApi 校验 open 签名规则sign = md5(gkey + time + key)
func TestSignOpenApi(t *testing.T) {
gkey, key := "center-api", "test-secret"
g, ts, sign := signOpenApi(gkey, key)
if g != gkey {
t.Fatalf("gkey 应原样返回, got %s", g)
}
if ts == "" {
t.Fatal("time 不应为空")
}
want := md5.Sum([]byte(gkey + ts + key))
if sign != hex.EncodeToString(want[:]) {
t.Fatalf("签名不符: got %s", sign)
}
}