This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package upstream
|
||||
|
||||
import (
|
||||
"cmpp-platform/gateway/internal/queue"
|
||||
"encoding/json"
|
||||
cmpp "github.com/bigwhite/gocmpp"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCMPP3ReceiptKeepsUnsignedFieldsAndFullDestination(t *testing.T) {
|
||||
events := make(chan queue.ReceiptEvent, 1)
|
||||
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var e queue.ReceiptEvent
|
||||
if err := json.NewDecoder(r.Body).Decode(&e); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
events <- e
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer api.Close()
|
||||
receipt := cmpp.CmppReceiptPkt{MsgId: ^uint64(0), Stat: "DELIVRD", DestTerminalId: strings.Repeat("9", 32), SmscSequence: ^uint32(0)}
|
||||
raw, err := receipt.PackVersion(cmpp.V30)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn := &connection{channelID: "qa", apiBaseURL: api.URL, httpClient: api.Client()}
|
||||
packet := deliverPacketFromCMPP3(&cmpp.Cmpp3DeliverReqPkt{SeqId: ^uint32(0), RegisterDelivery: 1, MsgContent: string(raw)})
|
||||
if err = conn.handleDeliver(packet); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
event := <-events
|
||||
if event.GatewayMessageID != "18446744073709551615" || event.SequenceID != ^uint32(0) || event.PhoneNumber != receipt.DestTerminalId {
|
||||
t.Fatalf("truncated callback: %+v", event)
|
||||
}
|
||||
packet.msgContent = string(raw[:60])
|
||||
if conn.handleDeliver(packet) == nil {
|
||||
t.Fatal("legacy 60-byte body silently accepted on CMPP3")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpstreamSequenceAvailabilityIncludesHeartbeatAndSubmit(t *testing.T) {
|
||||
conn := &connection{pending: map[uint32]chan submitPartResponse{0: make(chan submitPartResponse)}, heartbeatPending: map[uint32]time.Time{^uint32(0): time.Now()}}
|
||||
if conn.sequenceAvailable(0) || conn.sequenceAvailable(^uint32(0)) || !conn.sequenceAvailable(1) {
|
||||
t.Fatal("wrapped sequence overwrites outstanding request")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user