mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' into pointer
This commit is contained in:
@@ -136,16 +136,23 @@ func (self DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestPro
|
||||
}
|
||||
}
|
||||
}
|
||||
var unauthorizedResultCode bool
|
||||
var populatedResultCode bool
|
||||
if err != nil {
|
||||
utils.Logger.Debug(fmt.Sprintf("Received error from rater: %+v", err))
|
||||
if strings.HasSuffix(err.Error(), utils.ErrAccountNotFound.Error()) { // 5030 in case of AccountNotFound
|
||||
if strings.HasSuffix(err.Error(), utils.ErrAccountNotFound.Error()) || strings.HasSuffix(err.Error(), utils.ErrUserNotFound.Error()) { // 5030 in case of AccountNotFound
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, "5030",
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v set CCA Reply-Code, error: %s", ccr.diamMessage, err))
|
||||
return nil
|
||||
}
|
||||
unauthorizedResultCode = true
|
||||
populatedResultCode = true
|
||||
} else if strings.HasSuffix(err.Error(), utils.ErrCreditInsufficient.Error()) {
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, "4012",
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v set CCA Reply-Code, error: %s", ccr.diamMessage, err))
|
||||
return nil
|
||||
}
|
||||
populatedResultCode = true
|
||||
} else {
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, strconv.Itoa(DiameterRatingFailed),
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
@@ -157,21 +164,21 @@ func (self DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestPro
|
||||
}
|
||||
|
||||
}
|
||||
if ccr.CCRequestType != 3 && ccr.CCRequestType != 4 && maxUsage == 0 { // Not enough balance, RFC demands 4012
|
||||
if ccr.CCRequestType != 3 && ccr.CCRequestType != 4 && maxUsage == 0 && !populatedResultCode { // Not enough balance, RFC demands 4012
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, "4012",
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v set CCA Reply-Code, error: %s", ccr.diamMessage, err))
|
||||
return nil
|
||||
}
|
||||
unauthorizedResultCode = true
|
||||
} else if !unauthorizedResultCode {
|
||||
populatedResultCode = true
|
||||
} else if !populatedResultCode {
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, strconv.Itoa(diam.Success),
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v set CCA Reply-Code, error: %s", ccr.diamMessage, err))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if ccr.CCRequestType != 3 && ccr.CCRequestType != 4 && !unauthorizedResultCode { // For terminate or previously marked unauthorized, we don't add granted-service-unit AVP
|
||||
if ccr.CCRequestType != 3 && ccr.CCRequestType != 4 && !populatedResultCode { // For terminate or previously marked unauthorized, we don't add granted-service-unit AVP
|
||||
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Granted-Service-Unit", "CC-Time"}, strconv.FormatFloat(maxUsage, 'f', 0, 64),
|
||||
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v set CCA Granted-Service-Unit, error: %s", ccr.diamMessage, err))
|
||||
|
||||
@@ -500,6 +500,40 @@ func TestDmtAgentSendCCRSMSWrongAccount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2015-11-07T08:42:26Z" TimeEnd="2015-11-07T08:47:26Z"'
|
||||
func TestDmtAgentSendCCRInitWrongAccount(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
cdr := &engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE,
|
||||
OriginID: "dsafdsaf", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out",
|
||||
Tenant: "cgrates.org", Category: "call", Account: "non_existent", Subject: "non_existent", Destination: "1004", Supplier: "SUPPL1",
|
||||
SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID,
|
||||
Usage: time.Duration(0) * time.Second, PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"},
|
||||
}
|
||||
ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId,
|
||||
daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, false)
|
||||
m, err := ccr.AsDiameterMessage()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dmtClient.SendMessage(m); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
msg := dmtClient.ReceivedMessage() // Discard the received message so we can test next one
|
||||
if msg == nil {
|
||||
t.Fatal("No message returned")
|
||||
}
|
||||
if avps, err := msg.FindAVPsWithPath([]interface{}{"Result-Code"}, dict.UndefinedVendorID); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(avps) == 0 {
|
||||
t.Error("Result-Code")
|
||||
} else if strResult := avpValAsString(avps[0]); strResult != "5030" { // Result-Code set in the template
|
||||
t.Errorf("Expecting 5030, received: %s", strResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDmtAgentCdrs(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
|
||||
@@ -495,5 +495,5 @@ func LoadUserProfile(in interface{}, extraFields string) error {
|
||||
utils.SetMapExtraFields(in, m, extraFields)
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotFound
|
||||
return utils.ErrUserNotFound
|
||||
}
|
||||
|
||||
@@ -708,7 +708,7 @@ func TestUsersExternalCDRGetLoadUserProfileExtraFieldsNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
err := LoadUserProfile(ur, "ExtraFields")
|
||||
if err != utils.ErrNotFound {
|
||||
if err != utils.ErrUserNotFound {
|
||||
t.Error("Error detecting err in loading user profile: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (self *SMGeneric) ChargeEvent(gev SMGenericEvent, clnt *rpc2.Client) (maxDu
|
||||
}
|
||||
sR.CallCosts = append(sR.CallCosts, cc) // Save it so we can revert on issues
|
||||
if ccDur := cc.GetDuration(); ccDur == 0 {
|
||||
err = errors.New("INSUFFICIENT_FUNDS")
|
||||
err = utils.ErrCreditInsufficient
|
||||
break
|
||||
} else if ccDur < maxDur {
|
||||
maxDur = ccDur
|
||||
|
||||
@@ -28,6 +28,8 @@ var (
|
||||
ErrUnauthorizedDestination = errors.New("UNAUTHORIZED_DESTINATION")
|
||||
ErrRatingPlanNotFound = errors.New("RATING_PLAN_NOT_FOUND")
|
||||
ErrAccountNotFound = errors.New("ACCOUNT_NOT_FOUND")
|
||||
ErrUserNotFound = errors.New("USER_NOT_FOUND")
|
||||
ErrCreditInsufficient = errors.New("CREDIT_INSUFFICIENT")
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user