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 32e13f508d
commit 7c8910bb06
3 changed files with 89 additions and 2 deletions

View File

@@ -412,7 +412,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/v4/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

@@ -100,6 +100,7 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
* [Config] Add new section "template"
* [LoaderS] Add support for *template type
* [ActionS] Replaced the poster action with *export that will send the event to EEs
* [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> Wed, 19 Feb 2020 13:25:52 +0200
@@ -144,4 +145,4 @@ cgrates (0.9.1~rc3) UNRELEASED; urgency=low
* RC3.
-- DanB <danb@cgrates.org> Fri, 03 Jan 2014 17:37:31 +0100
-- DanB <danb@cgrates.org> Fri, 03 Jan 2014 17:37:31 +0100