mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Added protection for wrong inline filers in TPReader at load
This commit is contained in:
committed by
Dan Christian Bogos
parent
bb0f2602d2
commit
2ab5f1795c
@@ -665,3 +665,13 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e
|
||||
}
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
func verifyInlineFilterS(fltrs []string) (err error) {
|
||||
for _, fl := range fltrs {
|
||||
if strings.HasPrefix(fl, utils.Meta) {
|
||||
if _, err = NewFilterFromInline(utils.EmptyString, fl); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1359,3 +1359,12 @@ func TestNewFilterFromInline(t *testing.T) {
|
||||
t.Error("Expected error received nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyInlineFilterS(t *testing.T) {
|
||||
if err := verifyInlineFilterS([]string{"ATTR", "*string:~*req,Acoount:1001"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := verifyInlineFilterS([]string{"ATTR", "*string:~*req,Acoount1001"}); err == nil {
|
||||
t.Errorf("Expected error received nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1085,6 +1085,9 @@ func (tpr *TpReader) LoadResourceProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapRsPfls := make(map[utils.TenantID]*utils.TPResourceProfile)
|
||||
for _, rl := range rls {
|
||||
if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapRsPfls[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
|
||||
}
|
||||
tpr.resProfiles = mapRsPfls
|
||||
@@ -1109,6 +1112,9 @@ func (tpr *TpReader) LoadStatsFiltered(tag string) (err error) {
|
||||
}
|
||||
mapSTs := make(map[utils.TenantID]*utils.TPStatProfile)
|
||||
for _, st := range tps {
|
||||
if err = verifyInlineFilterS(st.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapSTs[utils.TenantID{Tenant: st.Tenant, ID: st.ID}] = st
|
||||
}
|
||||
tpr.sqProfiles = mapSTs
|
||||
@@ -1133,6 +1139,9 @@ func (tpr *TpReader) LoadThresholdsFiltered(tag string) (err error) {
|
||||
}
|
||||
mapTHs := make(map[utils.TenantID]*utils.TPThresholdProfile)
|
||||
for _, th := range tps {
|
||||
if err = verifyInlineFilterS(th.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapTHs[utils.TenantID{Tenant: th.Tenant, ID: th.ID}] = th
|
||||
}
|
||||
tpr.thProfiles = mapTHs
|
||||
@@ -1174,6 +1183,9 @@ func (tpr *TpReader) LoadRouteProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapRsPfls := make(map[utils.TenantID]*utils.TPRouteProfile)
|
||||
for _, rl := range rls {
|
||||
if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapRsPfls[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
|
||||
}
|
||||
tpr.routeProfiles = mapRsPfls
|
||||
@@ -1191,6 +1203,9 @@ func (tpr *TpReader) LoadAttributeProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapAttrPfls := make(map[utils.TenantID]*utils.TPAttributeProfile)
|
||||
for _, attr := range attrs {
|
||||
if err = verifyInlineFilterS(attr.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapAttrPfls[utils.TenantID{Tenant: attr.Tenant, ID: attr.ID}] = attr
|
||||
}
|
||||
tpr.attributeProfiles = mapAttrPfls
|
||||
@@ -1208,6 +1223,9 @@ func (tpr *TpReader) LoadChargerProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapChargerProfile := make(map[utils.TenantID]*utils.TPChargerProfile)
|
||||
for _, rl := range rls {
|
||||
if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapChargerProfile[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
|
||||
}
|
||||
tpr.chargerProfiles = mapChargerProfile
|
||||
@@ -1225,6 +1243,9 @@ func (tpr *TpReader) LoadDispatcherProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapDispatcherProfile := make(map[utils.TenantID]*utils.TPDispatcherProfile)
|
||||
for _, rl := range rls {
|
||||
if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapDispatcherProfile[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
|
||||
}
|
||||
tpr.dispatcherProfiles = mapDispatcherProfile
|
||||
@@ -1259,6 +1280,9 @@ func (tpr *TpReader) LoadRateProfilesFiltered(tag string) (err error) {
|
||||
}
|
||||
mapRateProfiles := make(map[utils.TenantID]*utils.TPRateProfile)
|
||||
for _, rl := range rls {
|
||||
if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
mapRateProfiles[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
|
||||
}
|
||||
tpr.rateProfiles = mapRateProfiles
|
||||
|
||||
@@ -39,6 +39,36 @@ func TestAuthSetStorage(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
}
|
||||
|
||||
func TestAuthLoadCsvFail(t *testing.T) {
|
||||
timings := ``
|
||||
destinations := ``
|
||||
rates := ``
|
||||
destinationRates := ``
|
||||
ratingPlans := ``
|
||||
ratingProfiles := ``
|
||||
sharedGroups := ``
|
||||
actions := ``
|
||||
actionPlans := ``
|
||||
actionTriggers := ``
|
||||
accountActions := ``
|
||||
resLimits := ``
|
||||
stats := ``
|
||||
thresholds := ``
|
||||
filters := ``
|
||||
suppliers := ``
|
||||
attrProfiles := `cgrates.org,ATTR_1,*any,*string~*req.RunID:route1,,,*req.Info,*constant,1001,false,10`
|
||||
chargerProfiles := ``
|
||||
csvr, err := engine.NewTpReader(dbAuth.DataDB(), engine.NewStringCSVStorage(utils.CSV_SEP, destinations, timings, rates, destinationRates,
|
||||
ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions,
|
||||
resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``, "", utils.EmptyString), "", "", nil, nil, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := csvr.LoadAll(); err == nil {
|
||||
t.Fatal("Expected error received nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthLoadCsv(t *testing.T) {
|
||||
timings := ``
|
||||
destinations := `DST_GERMANY_LANDLINE,49`
|
||||
|
||||
Reference in New Issue
Block a user