mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added check for empty path before AttributeProfile set
This commit is contained in:
committed by
Dan Christian Bogos
parent
43f36fdea6
commit
947362c60b
@@ -91,15 +91,16 @@ func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *AttributeWithCache, reply
|
||||
if missing := utils.MissingStructFields(alsWrp.AttributeProfile, []string{"Tenant", "ID", "Attributes"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if len(alsWrp.Attributes) != 0 {
|
||||
for _, attr := range alsWrp.Attributes {
|
||||
for _, sub := range attr.Value {
|
||||
if sub.Rules == "" {
|
||||
return utils.NewErrMandatoryIeMissing("Rules")
|
||||
}
|
||||
if err := sub.Compile(); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
for _, attr := range alsWrp.Attributes {
|
||||
if attr.Path == utils.EmptyString {
|
||||
return utils.NewErrMandatoryIeMissing("Path")
|
||||
}
|
||||
for _, sub := range attr.Value {
|
||||
if sub.Rules == utils.EmptyString {
|
||||
return utils.NewErrMandatoryIeMissing("Rules")
|
||||
}
|
||||
if err := sub.Compile(); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ var (
|
||||
testAttributeSProcessWithMultipleRuns,
|
||||
testAttributeSProcessWithMultipleRuns2,
|
||||
testAttributeSGetAttributeProfileIDsCount,
|
||||
testAttributeSSetAttributeWithEmptyPath,
|
||||
testAttributeSKillEngine,
|
||||
//start test for cache options
|
||||
testAttributeSInitCfg,
|
||||
@@ -1716,3 +1717,26 @@ func testAttributeSCachingMetaRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testAttributeSSetAttributeWithEmptyPath(t *testing.T) {
|
||||
eAttrPrf2 := &AttributeWithCache{
|
||||
AttributeProfile: &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_3",
|
||||
FilterIDs: []string{"*string:~*req.Account:dan"},
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Value: config.NewRSRParsersMustCompile("1001", utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err == nil {
|
||||
t.Errorf("Expected error received nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,9 @@ func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfil
|
||||
}
|
||||
attr.Attributes = make([]*Attribute, len(ext.Attributes))
|
||||
for i, extAttr := range ext.Attributes {
|
||||
if extAttr.Path == utils.EmptyString {
|
||||
return nil, utils.NewErrMandatoryIeMissing("Path")
|
||||
}
|
||||
if len(extAttr.Value) == 0 {
|
||||
return nil, utils.NewErrMandatoryIeMissing("Value")
|
||||
}
|
||||
@@ -145,6 +148,10 @@ func NewAttributeFromInline(tenant, inlnRule string) (attr *AttributeProfile, er
|
||||
if vals, err = config.NewRSRParsers(ruleSplt[2], utils.PipeSep); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ruleSplt[1]) == 0 {
|
||||
err = fmt.Errorf("empty path in inline AttributeProfile <%s>", inlnRule)
|
||||
return
|
||||
}
|
||||
attr.Attributes = append(attr.Attributes, &Attribute{
|
||||
Path: ruleSplt[1],
|
||||
Type: ruleSplt[0],
|
||||
|
||||
@@ -2322,6 +2322,10 @@ func APItoAttributeProfile(tpAttr *utils.TPAttributeProfile, timezone string) (a
|
||||
attrPrf.Contexts[i] = context
|
||||
}
|
||||
for i, reqAttr := range tpAttr.Attributes {
|
||||
if reqAttr.Path == utils.EmptyString { // we do not suppot empty Path in Attributes
|
||||
err = fmt.Errorf("empty path in AttributeProfile <%s>", attrPrf.TenantID())
|
||||
return
|
||||
}
|
||||
sbstPrsr, err := config.NewRSRParsers(reqAttr.Value, config.CgrConfig().GeneralCfg().RSRSep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1206,6 +1206,12 @@ func (tpr *TpReader) LoadAttributeProfilesFiltered(tag string) (err error) {
|
||||
if err = verifyInlineFilterS(attr.FilterIDs); err != nil {
|
||||
return
|
||||
}
|
||||
for _, at := range attr.Attributes {
|
||||
if at.Path == utils.EmptyString { // we do not suppot empty Path in Attributes
|
||||
err = fmt.Errorf("empty path in AttributeProfile <%s>", utils.ConcatenatedKey(attr.Tenant, attr.ID))
|
||||
return
|
||||
}
|
||||
}
|
||||
mapAttrPfls[utils.TenantID{Tenant: attr.Tenant, ID: attr.ID}] = attr
|
||||
}
|
||||
tpr.attributeProfiles = mapAttrPfls
|
||||
|
||||
@@ -111,6 +111,8 @@ func alias2AtttributeProfile(alias *v1Alias, defaultTenant string) *engine.Attri
|
||||
fld = utils.MetaTenant
|
||||
} else if fieldName != utils.EmptyString {
|
||||
fld = utils.MetaReq + utils.NestingSep + fieldName
|
||||
} else {
|
||||
continue // ignore empty fieldNames
|
||||
}
|
||||
attr := &engine.Attribute{
|
||||
Path: fld,
|
||||
|
||||
@@ -237,6 +237,12 @@ func (m *Migrator) migrateAttributeProfile() (err error) {
|
||||
}
|
||||
|
||||
if !m.dryRun {
|
||||
for _, attr := range v6Attr.Attributes {
|
||||
if attr.Path == utils.EmptyString { // we do not suppot empty Path in Attributes
|
||||
err = fmt.Errorf("the AttributeProfile <%s> was not migrated corectly", v6Attr.TenantID())
|
||||
return
|
||||
}
|
||||
}
|
||||
if vrs[utils.Attributes] == 1 {
|
||||
if err = m.dmOut.DataManager().DataDB().SetAttributeProfileDrv(v6Attr); err != nil {
|
||||
return
|
||||
|
||||
@@ -83,9 +83,10 @@ func fieldinfo2Attribute(attr []*engine.Attribute, fieldName, fieldInfo string)
|
||||
return attr
|
||||
}
|
||||
var path string
|
||||
if fieldName != utils.EmptyString {
|
||||
path = utils.MetaReq + utils.NestingSep + fieldName
|
||||
if fieldName == utils.EmptyString {
|
||||
return attr // do not append attribute if fieldName is empty
|
||||
}
|
||||
path = utils.MetaReq + utils.NestingSep + fieldName
|
||||
return append(attr, &engine.Attribute{
|
||||
Path: path,
|
||||
Value: rp,
|
||||
|
||||
@@ -499,6 +499,11 @@ func (m *Migrator) migrateAttributeProfileFiltersV1() (err error) {
|
||||
attrPrf.FilterIDs[i] = migrateInlineFilter(fl)
|
||||
}
|
||||
for i, attr := range attrPrf.Attributes {
|
||||
if attr.Path == utils.EmptyString {
|
||||
// in case of older version of attributes we do not have Path
|
||||
// stop the inline migration until the attributes are migrated
|
||||
return fmt.Errorf("error: <empty path> when migrating filter for attribute profile: <%s>", attrPrf.TenantID())
|
||||
}
|
||||
for j, fl := range attr.FilterIDs {
|
||||
attrPrf.Attributes[i].FilterIDs[j] = migrateInlineFilter(fl)
|
||||
}
|
||||
@@ -712,6 +717,11 @@ func (m *Migrator) migrateAttributeProfileFiltersV2() (err error) {
|
||||
attrPrf.FilterIDs[i] = migrateInlineFilterV2(fl)
|
||||
}
|
||||
for i, attr := range attrPrf.Attributes {
|
||||
if attr.Path == utils.EmptyString {
|
||||
// in case of older version of attributes we do not have Path
|
||||
// stop the inline migration until the attributes are migrated
|
||||
return fmt.Errorf("error: <empty path> when migrating filter for attribute profile: <%s>", attrPrf.TenantID())
|
||||
}
|
||||
for j, fl := range attr.FilterIDs {
|
||||
attrPrf.Attributes[i].FilterIDs[j] = migrateInlineFilterV2(fl)
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr
|
||||
var path string
|
||||
if fieldName != utils.EmptyString {
|
||||
path = utils.MetaReq + utils.NestingSep + fieldName
|
||||
} else {
|
||||
continue // ignore empty filedNames
|
||||
}
|
||||
attr.Attributes = append(attr.Attributes, &engine.Attribute{
|
||||
Path: path,
|
||||
|
||||
Reference in New Issue
Block a user