Added tests for diamagent errored reply

This commit is contained in:
Trial97
2020-04-14 15:20:22 +03:00
committed by Dan Christian Bogos
parent a624a81048
commit 959d6ac05b
4 changed files with 396 additions and 0 deletions

View File

@@ -66,6 +66,9 @@ var (
testDiamItCCRTerminate,
testDiamItCCRSMS,
testDiamItCCRMMS,
testDiamItTemplateErr,
testDiamItDRR,
testDiamItKillEngine,
}
@@ -1258,3 +1261,87 @@ func testDiamItDRR(t *testing.T) {
t.Errorf("expecting: %s, received: <%s>", eVal, val)
}
}
func testDiamItTemplateErr(t *testing.T) {
ccr := diam.NewRequest(diam.CreditControl, 4, nil)
ccr.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("TestDmtAgentSendCCRError"))
ccr.NewAVP(avp.OriginHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA"))
ccr.NewAVP(avp.OriginRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
ccr.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4))
ccr.NewAVP(avp.ServiceContextID, avp.Mbit, 0, datatype.UTF8String("error@DiamItError"))
ccr.NewAVP(avp.CCRequestType, avp.Mbit, 0, datatype.Enumerated(4))
ccr.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, datatype.Unsigned32(0))
ccr.NewAVP(avp.EventTimestamp, avp.Mbit, 0, datatype.Time(time.Date(2018, 10, 5, 11, 43, 10, 0, time.UTC)))
ccr.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.SubscriptionIDType, avp.Mbit, 0, datatype.Enumerated(0)),
diam.NewAVP(avp.SubscriptionIDData, avp.Mbit, 0, datatype.UTF8String("1001")), // Subscription-Id-Data
}})
ccr.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.SubscriptionIDType, avp.Mbit, 0, datatype.Enumerated(1)),
diam.NewAVP(avp.SubscriptionIDData, avp.Mbit, 0, datatype.UTF8String("104502200011")), // Subscription-Id-Data
}})
ccr.NewAVP(avp.ServiceIdentifier, avp.Mbit, 0, datatype.Unsigned32(0))
ccr.NewAVP(avp.RequestedAction, avp.Mbit, 0, datatype.Enumerated(0))
ccr.NewAVP(avp.RequestedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.CCTime, avp.Mbit, 0, datatype.Unsigned32(1))}})
ccr.NewAVP(873, avp.Mbit, 10415, &diam.GroupedAVP{ //
AVP: []*diam.AVP{
diam.NewAVP(20300, avp.Mbit, 2011, &diam.GroupedAVP{ // IN-Information
AVP: []*diam.AVP{
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("22509")), // Calling-Vlr-Number
diam.NewAVP(20385, avp.Mbit, 2011, datatype.UTF8String("4002")), // Called-Party-NP
},
}),
diam.NewAVP(2000, avp.Mbit, 10415, &diam.GroupedAVP{ // SMS-Information
AVP: []*diam.AVP{
diam.NewAVP(886, avp.Mbit, 10415, &diam.GroupedAVP{ // Originator-Address
AVP: []*diam.AVP{
diam.NewAVP(899, avp.Mbit, 10415, datatype.Enumerated(1)), // Address-Type
diam.NewAVP(897, avp.Mbit, 10415, datatype.UTF8String("1001")), // Address-Data
}}),
diam.NewAVP(1201, avp.Mbit, 10415, &diam.GroupedAVP{ // Recipient-Address
AVP: []*diam.AVP{
diam.NewAVP(899, avp.Mbit, 10415, datatype.Enumerated(1)), // Address-Type
diam.NewAVP(897, avp.Mbit, 10415, datatype.UTF8String("1003")), // Address-Data
}}),
},
}),
}})
// ============================================
// prevent nil pointer dereference
// ============================================
if diamClnt == nil {
t.Fatal("Diameter client should not be nil")
}
if diamClnt.conn == nil {
t.Fatal("Diameter connection should not be nil")
}
if ccr == nil {
t.Fatal("The mesage to diameter should not be nil")
}
// ============================================
if err := diamClnt.SendMessage(ccr); err != nil {
t.Error(err)
}
time.Sleep(time.Duration(100) * time.Millisecond)
msg := diamClnt.ReceivedMessage(rplyTimeout)
if msg == nil {
t.Fatal("Message should not be nil")
}
// Result-Code
eVal := "5012" // error code diam.UnableToComply
if avps, err := msg.FindAVPsWithPath([]interface{}{"Result-Code"}, dict.UndefinedVendorID); err != nil {
t.Error(err)
} else if len(avps) == 0 {
t.Error("Missing AVP")
} else if val, err := diamAVPAsString(avps[0]); err != nil {
t.Error(err)
} else if val != eVal {
t.Errorf("expecting: %s, received: <%s>", eVal, val)
}
}

View File

@@ -0,0 +1,103 @@
{
"diameter_agent": {
"request_processors": [
{ // this request proccessor is only used to test that an error message
// is sent if one is raised when proccesing the request
"id": "ErrorProcessing",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:4",
"*prefix:~*req.Service-Context-Id:error"
],
"flags": ["*event", "*accounts"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*sms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "sms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{"tag": "CCATemplate", "type": "*template", "value": "*cca"},
{
"tag": "GrantedUnitsError",
"path": "*rep.Granted-Service-Unit.CC-Total", // this should return a error because it expect an unsigned integer
"type": "*constant", "blocker": true,
"value": "-10"
},
{
"tag": "ResultCode","path": "*rep.Result-Code",
"filters": ["*eq:~*cgrep.MaxUsage:0"],
"type": "*constant", "value": "4012",
"blocker": true
},
{
"tag": "ResultCode", "path": "*rep.Result-Code",
"filters": ["*notempty:~*cgrep.Error:"],
"type": "*constant", "value": "5030",
"blocker": true
}
]
}
]
}
}

View File

@@ -0,0 +1,103 @@
{
"diameter_agent": {
"request_processors": [
{ // this request proccessor is only used to test that an error message
// is sent if one is raised when proccesing the request
"id": "ErrorProcessing",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:4",
"*prefix:~*req.Service-Context-Id:error"
],
"flags": ["*event", "*accounts"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*sms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "sms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{"tag": "CCATemplate", "type": "*template", "value": "*cca"},
{
"tag": "GrantedUnitsError",
"path": "*rep.Granted-Service-Unit.CC-Total", // this should return a error because it expect an unsigned integer
"type": "*constant", "blocker": true,
"value": "-10"
},
{
"tag": "ResultCode","path": "*rep.Result-Code",
"filters": ["*eq:~*cgrep.MaxUsage:0"],
"type": "*constant", "value": "4012",
"blocker": true
},
{
"tag": "ResultCode", "path": "*rep.Result-Code",
"filters": ["*notempty:~*cgrep.Error:"],
"type": "*constant", "value": "5030",
"blocker": true
}
]
}
]
}
}

View File

@@ -0,0 +1,103 @@
{
"diameter_agent": {
"request_processors": [
{ // this request proccessor is only used to test that an error message
// is sent if one is raised when proccesing the request
"id": "ErrorProcessing",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:4",
"*prefix:~*req.Service-Context-Id:error"
],
"flags": ["*event", "*accounts"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*sms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "sms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{"tag": "CCATemplate", "type": "*template", "value": "*cca"},
{
"tag": "GrantedUnitsError",
"path": "*rep.Granted-Service-Unit.CC-Total", // this should return a error because it expect an unsigned integer
"type": "*constant", "blocker": true,
"value": "-10"
},
{
"tag": "ResultCode","path": "*rep.Result-Code",
"filters": ["*eq:~*cgrep.MaxUsage:0"],
"type": "*constant", "value": "4012",
"blocker": true
},
{
"tag": "ResultCode", "path": "*rep.Result-Code",
"filters": ["*notempty:~*cgrep.Error:"],
"type": "*constant", "value": "5030",
"blocker": true
}
]
}
]
}
}