sync: 同步 v1.0.4 开源代码并脱敏
This commit is contained in:
@@ -73,10 +73,10 @@ func validateTask(task *Task) bool {
|
||||
}
|
||||
for _, detail := range task.Details {
|
||||
if detail != nil && detail.Reason == "" {
|
||||
detail.Reason = "same batch contains validation failure; upstream request was skipped"
|
||||
detail.Reason = "同批次存在校验失败卡,本卡未请求上游"
|
||||
}
|
||||
}
|
||||
task.FailureReason = "batch validation failed; upstream request was skipped"
|
||||
task.FailureReason = "批次校验未通过,未发起上游请求"
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func validateDetail(operation Operation, detail *Detail) {
|
||||
return
|
||||
}
|
||||
if detail.Card == nil {
|
||||
detail.Reason = "ICCID does not exist in SIM card records"
|
||||
detail.Reason = "ICCID不存在或不属于当前租户"
|
||||
return
|
||||
}
|
||||
detail.MSISDN = strings.TrimSpace(detail.Card.MSISDN)
|
||||
@@ -94,21 +94,20 @@ func validateDetail(operation Operation, detail *Detail) {
|
||||
detail.StatusBefore = detail.Card.BossCardStatus
|
||||
|
||||
if !detail.Authorized {
|
||||
detail.Reason = "ICCID is outside the current operator authorization scope"
|
||||
detail.Reason = "ICCID不在当前操作员授权范围内"
|
||||
return
|
||||
}
|
||||
var reasons []string
|
||||
if detail.ChanKey == "" {
|
||||
detail.Reason = "ICCID is missing chanKey"
|
||||
return
|
||||
reasons = append(reasons, "ICCID缺少通道标识")
|
||||
}
|
||||
if detail.InputMSISDN != "" && detail.InputMSISDN != detail.MSISDN {
|
||||
detail.Reason = "MSISDN does not match the SIM card record"
|
||||
return
|
||||
reasons = append(reasons, "MSISDN与卡档案不一致")
|
||||
}
|
||||
if detail.InputIMSI != "" && detail.InputIMSI != detail.IMSI {
|
||||
detail.Reason = "IMSI does not match the SIM card record"
|
||||
return
|
||||
reasons = append(reasons, "IMSI与卡档案不一致")
|
||||
}
|
||||
detail.Reason = strings.Join(reasons, ";")
|
||||
// TODO: 正常系统开发完成后恢复卡状态限制
|
||||
// 注释原因:开发环境经常出现卡状态不在预期可操作范围内的情况,先放行
|
||||
// if detail.Card.BossCardStatus != operation.ExpectedStatus {
|
||||
@@ -162,7 +161,7 @@ func (e *executor) changeSubBatch(ctx context.Context, task *Task, details []*De
|
||||
if err != nil {
|
||||
outcomes := make([]Outcome, len(details))
|
||||
for index := range outcomes {
|
||||
outcomes[index].Message = "upstream request failed: " + err.Error()
|
||||
outcomes[index].Message = "请求上游失败:" + err.Error()
|
||||
}
|
||||
return outcomes
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestValidateDetailDetectsMSISDNMismatch(t *testing.T) {
|
||||
},
|
||||
}
|
||||
validateDetail(operation, detail)
|
||||
if detail.Reason != "MSISDN does not match the SIM card record" {
|
||||
if detail.Reason != "MSISDN与卡档案不一致" {
|
||||
t.Fatalf("unexpected reason: %q", detail.Reason)
|
||||
}
|
||||
if detail.MSISDN != "msisdn-card" || detail.InputMSISDN != "msisdn-input" {
|
||||
@@ -190,3 +190,22 @@ func (u *fakeUpstream) ChangeSimStatus(_ context.Context, input *model.SimCardSt
|
||||
u.input = input
|
||||
return u.response, u.responseError
|
||||
}
|
||||
|
||||
func TestValidateDetailCollectsIndependentDiagnostics(t *testing.T) {
|
||||
detail := &Detail{ICCID: "card", Authorized: true, InputMSISDN: "wrong-phone", InputIMSI: "wrong-imsi", Card: &Card{MSISDN: "phone", IMSI: "imsi"}}
|
||||
validateDetail(Operation{}, detail)
|
||||
want := "ICCID缺少通道标识;MSISDN与卡档案不一致;IMSI与卡档案不一致"
|
||||
if detail.Reason != want {
|
||||
t.Fatalf("独立校验原因丢失: got=%q want=%q", detail.Reason, want)
|
||||
}
|
||||
unauthorized := &Detail{ICCID: "card", InputMSISDN: "wrong", Card: &Card{MSISDN: "phone"}}
|
||||
validateDetail(Operation{}, unauthorized)
|
||||
if unauthorized.Reason != "ICCID不在当前操作员授权范围内" {
|
||||
t.Fatalf("越权卡不应返回其他数据差异: %q", unauthorized.Reason)
|
||||
}
|
||||
existing := &Detail{Reason: "原始输入格式错误", Authorized: true, Card: &Card{}}
|
||||
validateDetail(Operation{}, existing)
|
||||
if existing.Reason != "原始输入格式错误" {
|
||||
t.Fatal("原始原因被覆盖")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user