fix: complete first version issue remediation

This commit is contained in:
hectorzhao
2026-07-11 10:14:37 +08:00
parent 709ac97764
commit 208a6c23f8
73 changed files with 1549 additions and 245 deletions
+64
View File
@@ -1,6 +1,7 @@
package inbound
import (
"bytes"
"context"
"encoding/json"
"log"
@@ -166,6 +167,69 @@ func TestInboundServerAuthenticatesAndSubmits(t *testing.T) {
}
}
func TestPostIncludesAPIErrorResponseBody(t *testing.T) {
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(`{"message":"CMPP submit content does not match an approved template and signature","statusCode":400}`))
}))
defer api.Close()
err := (Server{APIBaseURL: api.URL}).post(context.Background(), "/inbound/submit", map[string]string{"account": "100001"}, nil)
if err == nil || !bytes.Contains([]byte(err.Error()), []byte("CMPP submit content does not match an approved template and signature")) {
t.Fatalf("expected API response body in error, got %v", err)
}
}
func TestNormalizeInboundSubmitSupportsCMPP2AndCMPP3(t *testing.T) {
tests := []struct {
name string
packet any
protocol string
}{
{name: "cmpp2", packet: &cmpp.Cmpp2SubmitReqPkt{MsgSrc: "100001", SeqId: 20}, protocol: "cmpp20"},
{name: "cmpp3", packet: &cmpp.Cmpp3SubmitReqPkt{MsgSrc: "100001", SeqId: 30}, protocol: "cmpp30"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, ok := normalizeInboundSubmit(test.packet)
if !ok || got.protocol != test.protocol || got.msgSrc != "100001" {
t.Fatalf("unexpected normalized packet: %+v ok=%v", got, ok)
}
})
}
}
func TestSetInboundSubmitResponseSupportsCMPP2AndCMPP3(t *testing.T) {
cmpp2 := &cmpp.Cmpp2SubmitRspPkt{}
setInboundSubmitResponse(cmpp2, 101, 9)
if cmpp2.MsgId != 101 || cmpp2.Result != 9 {
t.Fatalf("unexpected CMPP2 response: %+v", cmpp2)
}
cmpp3 := &cmpp.Cmpp3SubmitRspPkt{}
setInboundSubmitResponse(cmpp3, 202, 9)
if cmpp3.MsgId != 202 || cmpp3.Result != 9 {
t.Fatalf("unexpected CMPP3 response: %+v", cmpp3)
}
}
func TestInboundClientProtocolUsesConnectRequestVersion(t *testing.T) {
resetDownstreamRegistry()
defer resetDownstreamRegistry()
conn := &cmpp.Conn{}
downstreamRegistry.byAccount["100001"] = &downstreamSession{
account: "100001",
protocol: "cmpp20",
conn: conn,
}
if got := inboundClientProtocol("100001", conn, "cmpp30"); got != "cmpp20" {
t.Fatalf("protocol = %s, want cmpp20", got)
}
if got := inboundClientProtocol("missing", conn, "cmpp30"); got != "cmpp30" {
t.Fatalf("fallback protocol = %s, want cmpp30", got)
}
}
func TestFlushOnlineAccountsFetchesPendingDeliveries(t *testing.T) {
resetDownstreamRegistry()
defer resetDownstreamRegistry()