diff --git a/engine/filters.go b/engine/filters.go index b6b602a9a..749fdd8d3 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -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 +} diff --git a/engine/filters_test.go b/engine/filters_test.go index d49d9016a..988c67ef0 100644 --- a/engine/filters_test.go +++ b/engine/filters_test.go @@ -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") + } +} diff --git a/engine/tpreader.go b/engine/tpreader.go index 9b829d590..c73a21d4a 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -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 diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index 47efae716..042a96832 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -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`