Add integration test diameter authorization with ForceDuration flag

This commit is contained in:
TeoV
2020-12-16 16:26:47 +02:00
committed by Dan Christian Bogos
parent 249fd7eec3
commit 2116571e57
8 changed files with 788 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ var (
testDiamItTPFromFolder,
testDiamItDryRun,
testDiamItCCRAuth,
testDiamItCCRAuthForceDuration,
testDiamItCCRInit,
testDiamItCCRInitWithForceDuration,
testDiamItCCRUpdate,
@@ -651,6 +652,94 @@ func testDiamItCCRAuth(t *testing.T) {
}
}
func testDiamItCCRAuthForceDuration(t *testing.T) {
m := diam.NewRequest(diam.CreditControl, 4, nil)
m.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8"))
m.NewAVP(avp.OriginHost, avp.Mbit, 0, datatype.DiameterIdentity("192.168.1.1"))
m.NewAVP(avp.OriginRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
m.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4))
m.NewAVP(avp.CCRequestType, avp.Mbit, 0, datatype.Enumerated(1))
m.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, datatype.Unsigned32(0))
m.NewAVP(avp.DestinationHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA"))
m.NewAVP(avp.DestinationRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
m.NewAVP(avp.ServiceContextID, avp.Mbit, 0, datatype.UTF8String("EventVoiceForceDuration@DiamItCCRAuth"))
m.NewAVP(avp.EventTimestamp, avp.Mbit, 0, datatype.Time(time.Date(2018, 10, 4, 14, 42, 20, 0, time.UTC)))
m.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(450, avp.Mbit, 0, datatype.Enumerated(0)), // Subscription-Id-Type
diam.NewAVP(444, avp.Mbit, 0, datatype.UTF8String("1006")), // Subscription-Id-Data
}})
m.NewAVP(avp.ServiceIdentifier, avp.Mbit, 0, datatype.Unsigned32(0))
m.NewAVP(avp.RequestedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(300))}})
m.NewAVP(avp.UsedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(0))}})
m.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(831, avp.Mbit, 10415, datatype.UTF8String("1006")), // Calling-Party-Address
diam.NewAVP(832, avp.Mbit, 10415, datatype.UTF8String("1002")), // Called-Party-Address
diam.NewAVP(20327, avp.Mbit, 2011, datatype.UTF8String("1002")), // Real-Called-Number
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")), // Call-Reference-Number
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
diam.NewAVP(20385, avp.Mbit, 2011, datatype.UTF8String("")), // Called-Party-NP
diam.NewAVP(20386, avp.Mbit, 2011, datatype.UTF8String("")), // SSP-Time
},
}),
}})
// ============================================
// 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 m == nil {
t.Fatal("The mesage to diameter should not be nil")
}
// ============================================
if err := diamClnt.SendMessage(m); err != nil {
t.Error(err)
}
msg := diamClnt.ReceivedMessage(rplyTimeout)
if msg == nil {
t.Fatal("No message returned")
}
// Result-Code
eVal := "2001"
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)
}
// Result-Code
eVal = "300" // 5 mins of session
if avps, err := msg.FindAVPsWithPath([]interface{}{"Granted-Service-Unit", "CC-Time"},
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)
}
}
func testDiamItCCRInit(t *testing.T) {
m := diam.NewRequest(diam.CreditControl, 4, nil)
m.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8"))

View File

@@ -102,6 +102,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [

View File

@@ -102,6 +102,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [

View File

@@ -201,6 +201,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInit",
"filters": [

View File

@@ -102,6 +102,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [

View File

@@ -102,6 +102,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [

View File

@@ -102,6 +102,105 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [

View File

@@ -108,6 +108,111 @@
},
],
},
{
"id": "VoiceEventAuthForceDuration",
"filters": [
"*string:~*vars.*cmd:CCR",
"*string:~*req.CC-Request-Type:1",
"*string:~*req.Service-Context-Id:EventVoiceForceDuration@DiamItCCRAuth"
],
"flags": ["*event", "*rals:*authorize;*fd", "*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*voice"
},
{
"tag": "*api_key",
"path": "*cgreq.*api_key",
"type": "*constant",
"value": "ses12345"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "OriginHost",
"path": "*cgreq.OriginHost",
"type": "*remote_host",
"mandatory": true
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "call"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*constant",
"value": "*attributes"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"value": "~*req.Service-Information.IN-Information.Real-Called-Number",
"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:s/(.*)/${1}s/",
"mandatory": true
},
{
"tag": "SubscriberID",
"path": "*cgreq.SubscriberId",
"type": "*variable",
"value": "~*req.Subscription-Id.Subscription-Id-Data",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
{
"tag": "ResultCode",
"path": "*rep.Result-Code",
"type": "*constant",
"value": "2001"
},
{
"tag": "GrantedUnits",
"path": "*rep.Granted-Service-Unit.CC-Time",
"type": "*variable",
"value": "~*cgrep.MaxUsage{*duration_seconds}",
"mandatory": true
},
],
},
{
"id": "VoiceInitForceDuration",
"filters": [