|
|
|
@@ -4759,11 +4759,12 @@ func TestServeIMCallRTCJoinReturnsAgoraAppIDMode(t *testing.T) {
|
|
|
|
|
oldCalls := store.Calls
|
|
|
|
|
oldThirdParty := store.ThirdPartyConfig
|
|
|
|
|
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
|
|
|
|
topic := types.Uid(42).P2PName(types.Uid(43))
|
|
|
|
|
calls := &testCallsStore{items: []types.CallRecord{{
|
|
|
|
|
ID: 9,
|
|
|
|
|
TenantID: 7,
|
|
|
|
|
CallID: "call-1",
|
|
|
|
|
Topic: "p2pTopic",
|
|
|
|
|
Topic: topic,
|
|
|
|
|
SeqID: 12,
|
|
|
|
|
CallerID: 42,
|
|
|
|
|
CalleeID: 43,
|
|
|
|
@@ -4788,18 +4789,18 @@ func TestServeIMCallRTCJoinReturnsAgoraAppIDMode(t *testing.T) {
|
|
|
|
|
store.Calls = oldCalls
|
|
|
|
|
store.ThirdPartyConfig = oldThirdParty
|
|
|
|
|
}()
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), "p2pTopic", types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: "p2pTopic", ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), topic, types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: topic, ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"p2pTopic","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+topic+`","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
req.Header.Set("Authorization", "Bearer token-caller")
|
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(rec, req)
|
|
|
|
|
if rec.Code != http.StatusOK {
|
|
|
|
|
t.Fatalf("rtc join status: got %d body=%s", rec.Code, rec.Body.String())
|
|
|
|
|
}
|
|
|
|
|
if !calls.listed || calls.tenant != 7 || calls.user != 42 || calls.topic != "p2pTopic" || calls.limit != 100 {
|
|
|
|
|
if !calls.listed || calls.tenant != 7 || calls.user != 42 || calls.topic != topic || calls.limit != 100 {
|
|
|
|
|
t.Fatalf("calls lookup mismatch: %#v", calls)
|
|
|
|
|
}
|
|
|
|
|
resp := decodeIMHTTPResponse(t, rec)
|
|
|
|
@@ -4810,6 +4811,62 @@ func TestServeIMCallRTCJoinReturnsAgoraAppIDMode(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestServeIMCallRTCJoinAcceptsP2PAliasTopic(t *testing.T) {
|
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
expectIMBearer(t, ctrl, "token-caller", 7, 42)
|
|
|
|
|
oldSubs := store.Subs
|
|
|
|
|
oldCalls := store.Calls
|
|
|
|
|
oldThirdParty := store.ThirdPartyConfig
|
|
|
|
|
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
|
|
|
|
peer := types.Uid(43)
|
|
|
|
|
topic := types.Uid(42).P2PName(peer)
|
|
|
|
|
calls := &testCallsStore{items: []types.CallRecord{{
|
|
|
|
|
ID: 9,
|
|
|
|
|
TenantID: 7,
|
|
|
|
|
CallID: "call-1",
|
|
|
|
|
Topic: topic,
|
|
|
|
|
SeqID: 12,
|
|
|
|
|
CallerID: 42,
|
|
|
|
|
CalleeID: peer,
|
|
|
|
|
CallType: "audio",
|
|
|
|
|
Status: types.CallStatusStarted,
|
|
|
|
|
StartedAt: time.Date(2026, 9, 2, 9, 0, 0, 0, time.UTC),
|
|
|
|
|
CreatedAt: time.Date(2026, 9, 2, 9, 0, 0, 0, time.UTC),
|
|
|
|
|
UpdatedAt: time.Date(2026, 9, 2, 9, 0, 0, 0, time.UTC),
|
|
|
|
|
}}}
|
|
|
|
|
store.Subs = subs
|
|
|
|
|
store.Calls = calls
|
|
|
|
|
store.ThirdPartyConfig = testThirdPartyConfigStore{
|
|
|
|
|
"agora_enabled": "1",
|
|
|
|
|
"agora_auth_mode": "app_id",
|
|
|
|
|
"agora_app_id": "app123",
|
|
|
|
|
"agora_channel_prefix": "call_",
|
|
|
|
|
"agora_uid_mode": "string",
|
|
|
|
|
"agora_token_ttl_seconds": "3600",
|
|
|
|
|
}
|
|
|
|
|
defer func() {
|
|
|
|
|
store.Subs = oldSubs
|
|
|
|
|
store.Calls = oldCalls
|
|
|
|
|
store.ThirdPartyConfig = oldThirdParty
|
|
|
|
|
}()
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), topic, types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: topic, ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+peer.UserId()+`","call_id":"call-1","seq":12,"call_type":"audio","role":"caller"}`))
|
|
|
|
|
req.Header.Set("Authorization", "Bearer token-caller")
|
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(rec, req)
|
|
|
|
|
if rec.Code != http.StatusOK {
|
|
|
|
|
t.Fatalf("rtc join status: got %d body=%s", rec.Code, rec.Body.String())
|
|
|
|
|
}
|
|
|
|
|
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
|
|
|
|
if data["topic"] != topic || calls.topic != topic {
|
|
|
|
|
t.Fatalf("alias topic was not normalized: data=%#v calls=%#v", data, calls)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestServeIMCallRTCJoinReturnsSameAgoraChannelForCallee(t *testing.T) {
|
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
|
defer ctrl.Finish()
|
|
|
|
@@ -4827,11 +4884,12 @@ func TestServeIMCallRTCJoinReturnsSameAgoraChannelForCallee(t *testing.T) {
|
|
|
|
|
oldCalls := store.Calls
|
|
|
|
|
oldThirdParty := store.ThirdPartyConfig
|
|
|
|
|
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
|
|
|
|
topic := types.Uid(42).P2PName(types.Uid(43))
|
|
|
|
|
calls := &testCallsStore{items: []types.CallRecord{{
|
|
|
|
|
ID: 9,
|
|
|
|
|
TenantID: 7,
|
|
|
|
|
CallID: "call-1",
|
|
|
|
|
Topic: "p2pTopic",
|
|
|
|
|
Topic: topic,
|
|
|
|
|
SeqID: 12,
|
|
|
|
|
CallerID: 42,
|
|
|
|
|
CalleeID: 43,
|
|
|
|
@@ -4857,14 +4915,14 @@ func TestServeIMCallRTCJoinReturnsSameAgoraChannelForCallee(t *testing.T) {
|
|
|
|
|
store.Calls = oldCalls
|
|
|
|
|
store.ThirdPartyConfig = oldThirdParty
|
|
|
|
|
}()
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), "p2pTopic", types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: "p2pTopic", ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), topic, types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: topic, ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
}, nil)
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), "p2pTopic", types.Uid(43), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(43).String(), Topic: "p2pTopic", ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), topic, types.Uid(43), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(43).String(), Topic: topic, ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
callerReq := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"p2pTopic","call_id":"call-1","seq":12,"call_type":"audio","role":"caller"}`))
|
|
|
|
|
callerReq := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+topic+`","call_id":"call-1","seq":12,"call_type":"audio","role":"caller"}`))
|
|
|
|
|
callerReq.Header.Set("Authorization", "Bearer token-caller")
|
|
|
|
|
callerRec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(callerRec, callerReq)
|
|
|
|
@@ -4872,7 +4930,7 @@ func TestServeIMCallRTCJoinReturnsSameAgoraChannelForCallee(t *testing.T) {
|
|
|
|
|
t.Fatalf("caller rtc join status: got %d body=%s", callerRec.Code, callerRec.Body.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calleeReq := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"p2pTopic","call_id":"call-1","seq":12,"call_type":"audio","role":"callee"}`))
|
|
|
|
|
calleeReq := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+topic+`","call_id":"call-1","seq":12,"call_type":"audio","role":"callee"}`))
|
|
|
|
|
calleeReq.Header.Set("Authorization", "Bearer token-callee")
|
|
|
|
|
calleeRec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(calleeRec, calleeReq)
|
|
|
|
@@ -4901,11 +4959,12 @@ func TestServeIMCallRTCJoinReturnsAgoraTokenMode(t *testing.T) {
|
|
|
|
|
oldCalls := store.Calls
|
|
|
|
|
oldThirdParty := store.ThirdPartyConfig
|
|
|
|
|
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
|
|
|
|
topic := types.Uid(42).P2PName(types.Uid(43))
|
|
|
|
|
calls := &testCallsStore{items: []types.CallRecord{{
|
|
|
|
|
ID: 9,
|
|
|
|
|
TenantID: 7,
|
|
|
|
|
CallID: "call-1",
|
|
|
|
|
Topic: "p2pTopic",
|
|
|
|
|
Topic: topic,
|
|
|
|
|
SeqID: 12,
|
|
|
|
|
CallerID: 42,
|
|
|
|
|
CalleeID: 43,
|
|
|
|
@@ -4931,11 +4990,11 @@ func TestServeIMCallRTCJoinReturnsAgoraTokenMode(t *testing.T) {
|
|
|
|
|
store.Calls = oldCalls
|
|
|
|
|
store.ThirdPartyConfig = oldThirdParty
|
|
|
|
|
}()
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), "p2pTopic", types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: "p2pTopic", ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
subs.EXPECT().Get(types.TenantID(7), topic, types.Uid(42), false).Return(&types.Subscription{
|
|
|
|
|
TenantID: 7, User: types.Uid(42).String(), Topic: topic, ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"p2pTopic","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+topic+`","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
req.Header.Set("Authorization", "Bearer token-1")
|
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(rec, req)
|
|
|
|
@@ -4959,7 +5018,8 @@ func TestServeIMCallRTCJoinRejectsDisabledAgora(t *testing.T) {
|
|
|
|
|
store.ThirdPartyConfig = testThirdPartyConfigStore{"agora_enabled": "0"}
|
|
|
|
|
defer func() { store.ThirdPartyConfig = oldThirdParty }()
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"p2pTopic","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
topic := types.Uid(42).P2PName(types.Uid(43))
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/v1/im/calls/rtc-join", strings.NewReader(`{"topic":"`+topic+`","call_id":"call-1","seq":12,"call_type":"video","role":"caller"}`))
|
|
|
|
|
req.Header.Set("Authorization", "Bearer token-1")
|
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
|
serveIMCallRTCJoin(rec, req)
|
|
|
|
|