sync: 同步生产版 v1.0.4 并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 15:03:39 +08:00
parent fed9459244
commit 2d045591b7
32 changed files with 695 additions and 80 deletions
+17 -1
View File
@@ -2,11 +2,12 @@ package simKeyFill
import (
"context"
"encoding/json"
"strings"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/dao"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/model/entity"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/service"
"strings"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@@ -24,6 +25,21 @@ func init() {
}
func (s *sSimKeyFill) SimKeyFill(ctx context.Context, input *model.SimBaseReqJson) (output model.SimBaseResJson, err error) {
var operation struct {
OperationID string `json:"operationId"`
}
request := g.RequestFromCtx(ctx)
if request != nil && (request.URL.Path == "/sim/change/sim-apn" || request.URL.Path == "/sim/query/sim-apn-capability") && json.Unmarshal(input.ReqData, &operation) == nil && operation.OperationID != "" {
if len(input.SimKeys) == 0 || len(input.SimKeys) > 100 {
return nil, gerror.New("异步子任务卡数必须在1至100之间")
}
for _, key := range input.SimKeys {
if key == nil || key.ChanKey == "" || key.ICCID == "" {
return nil, gerror.New("异步子任务必须保留chanKey和ICCID快照")
}
}
return service.UpstreamAPI().SimBase(ctx, input)
}
simKeys, err := s.batchGetSimKey(ctx, input.SimKeys)
if err != nil {
return nil, err
@@ -0,0 +1,38 @@
package simKeyFill
import (
"context"
"encoding/json"
"net/http/httptest"
"testing"
"github.com/gogf/gf/v2/net/ghttp"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/service"
)
type snapshotTestAPI struct {
service.IUpstreamAPI
input *model.SimBaseReqJson
}
func (a *snapshotTestAPI) SimBase(_ context.Context, in *model.SimBaseReqJson) (model.SimBaseResJson, error) {
a.input = in
return nil, nil
}
func TestAsyncOperationPreservesCardSnapshot(t *testing.T) {
api := &snapshotTestAPI{}
service.RegisterUpstreamAPI(api)
defer service.RegisterUpstreamAPI(nil)
in := &model.SimBaseReqJson{SimKeys: []*model.SimKey{{ChanKey: "test", ICCID: "test-card", MSISDN: "snapshot-number"}}, ReqData: json.RawMessage(`{"operationId":"stable-id","submitOnly":true}`)}
_, err := NewSimKeyFill().SimKeyFill((&ghttp.Request{Request: httptest.NewRequest("POST", "/sim/change/sim-apn", nil)}).Context(), in)
if err != nil || api.input != in || api.input.SimKeys[0].MSISDN != "snapshot-number" {
t.Fatalf("异步请求不应重新填充或改写卡快照:%v", err)
}
}
func TestAsyncOperationRejectsIncompleteSnapshot(t *testing.T) {
_, err := NewSimKeyFill().SimKeyFill((&ghttp.Request{Request: httptest.NewRequest("POST", "/sim/change/sim-apn", nil)}).Context(), &model.SimBaseReqJson{SimKeys: []*model.SimKey{{ICCID: "test-card"}}, ReqData: json.RawMessage(`{"operationId":"stable-id"}`)})
if err == nil {
t.Fatal("缺失通道快照应在调用前拒绝")
}
}