feat: 接入消息加密与实名认证能力
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -259,6 +260,65 @@ func TestRealtimeP2PTopicFallbackRewritesVisibleInfoTopic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeCallEventRoutesToLocalTopic(t *testing.T) {
|
||||
oldHub := globals.hub
|
||||
defer func() { globals.hub = oldHub }()
|
||||
|
||||
tenantID := types.TenantID(1)
|
||||
caller := types.Uid(1001)
|
||||
callee := types.Uid(1002)
|
||||
topic := caller.P2PName(callee)
|
||||
if topic == "" {
|
||||
t.Fatal("failed to create p2p topic")
|
||||
}
|
||||
topics := &sync.Map{}
|
||||
topics.Store(types.TopicKey{TenantID: tenantID, Topic: topic}, &Topic{name: topic, tenantID: tenantID})
|
||||
globals.hub = &Hub{
|
||||
topics: topics,
|
||||
routeCli: make(chan *ClientComMessage, 1),
|
||||
}
|
||||
|
||||
payload := json.RawMessage(`{"callId":"call-1"}`)
|
||||
event := realtimeCallEventMessage{
|
||||
Topic: topic,
|
||||
From: callee.UserId(),
|
||||
Sid: "callee-sid",
|
||||
Event: constCallEventAccept,
|
||||
Seq: 12,
|
||||
Payload: payload,
|
||||
}
|
||||
raw, err := json.Marshal(event)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deliverRealtimeFanoutEnvelope(&store.RealtimeFanoutEnvelope{
|
||||
TenantID: tenantID,
|
||||
Kind: realtimeKindCallEvent,
|
||||
TargetType: realtimeTargetTopic,
|
||||
Target: topic,
|
||||
Message: raw,
|
||||
})
|
||||
|
||||
select {
|
||||
case got := <-globals.hub.routeCli:
|
||||
if got.TenantID != tenantID || got.RcptTo != topic || got.AsUser != callee.UserId() {
|
||||
t.Fatalf("unexpected routed message: tenant=%d rcpt=%q as=%q", got.TenantID, got.RcptTo, got.AsUser)
|
||||
}
|
||||
if got.Note == nil || got.Note.What != "call" || got.Note.Event != constCallEventAccept || got.Note.SeqId != 12 {
|
||||
t.Fatalf("unexpected call note: %#v", got.Note)
|
||||
}
|
||||
if string(got.Note.Payload) != string(payload) {
|
||||
t.Fatalf("payload = %s, want %s", got.Note.Payload, payload)
|
||||
}
|
||||
if got.sess == nil || got.sess.uid != callee || got.sess.sid != "redis-call:callee-sid" {
|
||||
t.Fatalf("unexpected synthetic session: %#v", got.sess)
|
||||
}
|
||||
default:
|
||||
t.Fatal("expected call event to be routed to local topic")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeInfoDedupKeySeparatesReadRecv(t *testing.T) {
|
||||
read := realtimeMessageDedupKey("p2pABC", &ServerComMessage{
|
||||
Info: &MsgServerInfo{From: "usrA", What: "read", SeqId: 12},
|
||||
|
||||
Reference in New Issue
Block a user