Update checking for Attributes

This commit is contained in:
TeoV
2018-08-21 11:00:26 -04:00
committed by Dan Christian Bogos
parent 050b24fc76
commit d622d49e77
3 changed files with 38 additions and 4 deletions

View File

@@ -62,11 +62,11 @@ func (apierV1 *ApierV1) SetAttributeProfile(alsPrf *engine.AttributeProfile, rep
if len(alsPrf.Attributes) != 0 {
for _, attr := range alsPrf.Attributes {
for _, sub := range attr.Substitute {
if missing := utils.MissingStructFields(sub, []string{"Rules"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
if sub.Rules == "" {
return utils.NewErrMandatoryIeMissing("Rules")
}
if err := sub.Compile(); err != nil {
return err
return utils.NewErrServerError(err)
}
}
}

View File

@@ -65,6 +65,7 @@ var sTestsAlsPrf = []func(t *testing.T){
testAttributeSRemAlsPrf,
testAttributeSSetAlsPrf2,
testAttributeSSetAlsPrf3,
testAttributeSSetAlsPrf4,
testAttributeSPing,
testAttributeSKillEngine,
}
@@ -760,6 +761,37 @@ func testAttributeSSetAlsPrf2(t *testing.T) {
}
func testAttributeSSetAlsPrf3(t *testing.T) {
alsPrf = &engine.AttributeProfile{
Tenant: "golant",
ID: "ATTR_972587832508_SESSIONAUTH",
Contexts: []string{utils.MetaSessionS},
FilterIDs: []string{"*string:Account:972587832508"},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
},
Attributes: []*engine.Attribute{
&engine.Attribute{
FieldName: utils.Subject,
Initial: utils.ANY,
Substitute: utils.RSRParsers{
&utils.RSRParser{
Rules: "",
},
},
Append: false,
},
},
Blocker: false,
Weight: 10,
}
var result string
if err := attrSRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err == nil {
t.Error(err)
}
}
func testAttributeSSetAlsPrf4(t *testing.T) {
alsPrf = &engine.AttributeProfile{
Tenant: "golant",
ID: "ATTR_972587832508_SESSIONAUTH",

View File

@@ -189,7 +189,9 @@ func (prsr *RSRParser) Compile() (err error) {
if newPrsr, err = NewRSRParser(prsr.Rules, prsr.AllFiltersMatch); err != nil {
return
}
*prsr = *newPrsr
if newPrsr != nil {
*prsr = *newPrsr
}
return
}