feat: harden CMPP delivery and platform workflows
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -112,7 +113,13 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
if err := json.NewDecoder(r.Body).Decode(&gotSubmit); err != nil {
|
||||
t.Fatalf("decode submit: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(submitResponse{Accepted: true, MessageID: "MSG-1"})
|
||||
_ = json.NewEncoder(w).Encode(submitResponse{
|
||||
Accepted: true, MessageID: "MSG-1",
|
||||
Messages: []submitResponseMessage{
|
||||
{PhoneNumber: "13500002696", MessageID: "MSG-1"},
|
||||
{PhoneNumber: "13600002696", MessageID: "MSG-2"},
|
||||
},
|
||||
})
|
||||
case "/api/gateway/events/downstream/pending":
|
||||
_ = json.NewEncoder(w).Encode([]pendingDelivery{})
|
||||
case "/api/gateway/events/inbound/connection":
|
||||
@@ -174,8 +181,8 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
FeeType: "02",
|
||||
FeeCode: "0",
|
||||
SrcId: "10690000",
|
||||
DestUsrTl: 1,
|
||||
DestTerminalId: []string{"13500002696"},
|
||||
DestUsrTl: 2,
|
||||
DestTerminalId: []string{"13500002696", "13600002696"},
|
||||
MsgLength: uint8(len(content)),
|
||||
MsgContent: content,
|
||||
})
|
||||
@@ -188,8 +195,8 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
}
|
||||
sendResult, err := PushReceiptWithResult(DownstreamReceipt{
|
||||
DeliveryID: "delivery-1",
|
||||
MessageID: "MSG-1",
|
||||
PhoneNumber: "13500002696",
|
||||
MessageID: "MSG-2",
|
||||
PhoneNumber: "13600002696",
|
||||
ReceiptStatus: "delivered",
|
||||
DeliveredAt: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
})
|
||||
@@ -204,7 +211,7 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
if err := receipt.Unpack([]byte(deliver.MsgContent)); err != nil {
|
||||
t.Fatalf("unpack pushed receipt: %v", err)
|
||||
}
|
||||
if receipt.Stat != "DELIVRD" || receipt.DestTerminalId != "13500002696" {
|
||||
if receipt.Stat != "DELIVRD" || receipt.DestTerminalId != "13600002696" || receipt.MsgId != rsp.MsgId {
|
||||
t.Fatalf("unexpected pushed receipt: %+v", receipt)
|
||||
}
|
||||
if err := client.SendRspPkt(&cmpp.Cmpp3DeliverRspPkt{MsgId: deliver.MsgId, Result: 0}, deliver.SeqId); err != nil {
|
||||
@@ -221,7 +228,8 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
|
||||
if gotAuth.Account != account || gotAuth.AuthSource == "" || gotAuth.RemoteIP == "" {
|
||||
t.Fatalf("unexpected auth payload: %+v", gotAuth)
|
||||
}
|
||||
if gotSubmit.Account != account || gotSubmit.PhoneNumber != "13500002696" || gotSubmit.Content != "测试入站" {
|
||||
if gotSubmit.Account != account || gotSubmit.PhoneNumber != "13500002696" || gotSubmit.Content != "测试入站" ||
|
||||
!reflect.DeepEqual(gotSubmit.PhoneNumbers, []string{"13500002696", "13600002696"}) {
|
||||
t.Fatalf("unexpected submit payload: %+v", gotSubmit)
|
||||
}
|
||||
}
|
||||
@@ -742,6 +750,15 @@ func TestReceiptLookupDoesNotFallbackToAccountBeforeSubmitMappingExists(t *testi
|
||||
if recovered.gatewayMsgID != messageIDFrom("MSG-NOT-REMEMBERED", 1216579149) || recovered.gatewayMsgID == 0 {
|
||||
t.Fatalf("unexpected recovered Msg_Id: %d", recovered.gatewayMsgID)
|
||||
}
|
||||
first := recoverReceiptSession(DownstreamReceipt{
|
||||
MessageID: "MSG-FIRST", SubmitGroupMessageID: "MSG-GROUP", Account: "100001", SubmitSequenceID: 77,
|
||||
})
|
||||
second := recoverReceiptSession(DownstreamReceipt{
|
||||
MessageID: "MSG-SECOND", SubmitGroupMessageID: "MSG-GROUP", Account: "100001", SubmitSequenceID: 77,
|
||||
})
|
||||
if first == nil || second == nil || first.gatewayMsgID != second.gatewayMsgID || first.gatewayMsgID != messageIDFrom("MSG-GROUP", 77) {
|
||||
t.Fatalf("multi-destination recovery did not preserve the original Msg_Id: first=%+v second=%+v", first, second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendDownstreamRejectsZeroMessageID(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user