DiameterAgent return NOT_FOUND instead of "filter not passing" error and let other subsystem to handle this (e.g. FilterS)

This commit is contained in:
TeoV
2020-09-10 17:25:00 +03:00
committed by Dan Christian Bogos
parent 3289a59a41
commit 3128c29c4b
3 changed files with 88 additions and 1 deletions

View File

@@ -398,7 +398,7 @@ func (dP *diameterDP) FieldAsInterface(fldPath []string) (data interface{}, err
}
}
if !oneMatches {
return nil, utils.ErrFilterNotPassingNoCaps
return nil, utils.ErrNotFound // return NotFound and let the other subsystem handle it (e.g. FilterS )
}
}
}

View File

@@ -25,6 +25,8 @@ import (
"testing"
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/fiorix/go-diameter/diam"
@@ -1090,3 +1092,87 @@ func TestNewDiamDataType(t *testing.T) {
t.Errorf("Expected<%T>: %v ,received<%T>: %v ", exp, exp, rply, rply)
}
}
func TestDiamAvpGroupIface(t *testing.T) {
avps := diam.NewRequest(diam.CreditControl, 4, nil)
avps.NewAVP("Multiple-Services-Credit-Control", avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(432, avp.Mbit, 0, datatype.Unsigned32(1)),
}})
avps.NewAVP("Multiple-Services-Credit-Control", avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(432, avp.Mbit, 0, datatype.Unsigned32(99)),
}})
dP := newDADataProvider(nil, avps)
eOut := interface{}(uint32(1))
if out, err := dP.FieldAsInterface([]string{"Multiple-Services-Credit-Control", "Rating-Group"}); err != nil {
t.Error(err)
} else if eOut != out {
t.Errorf("Expecting: %v, received: %v", eOut, out)
}
if out, err := dP.FieldAsInterface([]string{"Multiple-Services-Credit-Control", "Rating-Group[~Rating-Group(1)]"}); err != nil {
t.Error(err)
} else if eOut != out {
t.Errorf("Expecting: %v, received: %v", eOut, out)
}
eOut = interface{}(uint32(99))
if out, err := dP.FieldAsInterface([]string{"Multiple-Services-Credit-Control", "Rating-Group[1]"}); err != nil {
t.Error(err)
} else if eOut != out {
t.Errorf("Expecting: %v, received: %v", eOut, out)
}
if out, err := dP.FieldAsInterface([]string{"Multiple-Services-Credit-Control", "Rating-Group[~Rating-Group(99)]"}); err != nil {
t.Error(err)
} else if eOut != out {
t.Errorf("Expecting: %v, received: %v", eOut, out)
}
if _, err := dP.FieldAsInterface([]string{"Multiple-Services-Credit-Control", "Rating-Group[~Rating-Group(10)]"}); err != utils.ErrNotFound {
t.Error(err)
}
}
func TestFilterWithDiameterDP(t *testing.T) {
avps := diam.NewRequest(diam.CreditControl, 4, nil)
avps.NewAVP("Multiple-Services-Credit-Control", avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(432, avp.Mbit, 0, datatype.Unsigned32(1)),
}})
avps.NewAVP("Multiple-Services-Credit-Control", avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(432, avp.Mbit, 0, datatype.Unsigned32(99)),
}})
dP := newDADataProvider(nil, avps)
cfg, _ := config.NewDefaultCGRConfig()
dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items),
config.CgrConfig().CacheCfg(), nil)
filterS := engine.NewFilterS(cfg, nil, dm)
agReq := NewAgentRequest(dP, nil, nil, nil, nil, "cgrates.org", "", filterS, nil, nil)
if pass, err := filterS.Pass("cgrates.org",
[]string{"*exists:~*req.Multiple-Services-Credit-Control.Rating-Group[~Rating-Group(99)]:"}, agReq); err != nil {
t.Error(err)
} else if !pass {
t.Errorf("Exptected true, received: %+v", pass)
}
if pass, err := filterS.Pass("cgrates.org",
[]string{"*exists:~*req.Multiple-Services-Credit-Control.Rating-Group[~Rating-Group(10)]:"}, agReq); err != nil {
t.Error(err)
} else if pass {
t.Errorf("Exptected false, received: %+v", pass)
}
if pass, err := filterS.Pass("cgrates.org",
[]string{"*string:~*req.Multiple-Services-Credit-Control.Rating-Group[~Rating-Group(10)]:12"}, agReq); err != nil {
t.Error(err)
} else if pass {
t.Errorf("Exptected false, received: %+v", pass)
}
if pass, err := filterS.Pass("cgrates.org",
[]string{"*string:~*req.Multiple-Services-Credit-Control.Rating-Group[~Rating-Group(1)]:1"}, agReq); err != nil {
t.Error(err)
} else if !pass {
t.Errorf("Exptected true, received: %+v", pass)
}
}

View File

@@ -12,6 +12,7 @@ cgrates (0.10.2~dev) UNRELEASED; urgency=medium
* [RSRParsers] Added grave accent(`) char as a delimiter to not split tge RSR value
* [SessionS] Rename from ResourceMessage to ResourceAllocation
* [AgentS] Correctly verify flags for setting max usage in ProcessEvent
* [AgentS] DiameterAgent return NOT_FOUND instead of "filter not passing" error and let other subsystem to handle this (e.g. FilterS)
-- DanB <danb@cgrates.org> Tue, 12 May 2020 13:08:15 +0300