Remvoed subject verification for *any for RatingProfileID + test

This commit is contained in:
porosnicuadrian
2021-07-20 16:29:27 +03:00
committed by Dan Christian Bogos
parent 0df0181db1
commit cd85a1185f
2 changed files with 82 additions and 5 deletions

View File

@@ -1229,18 +1229,18 @@ type AttrRemoveRatingProfile struct {
func (arrp *AttrRemoveRatingProfile) GetId() (result string) {
result = utils.MetaOut + utils.ConcatenatedKeySep
if arrp.Tenant != "" && arrp.Tenant != utils.MetaAny {
if arrp.Tenant != utils.EmptyString && arrp.Tenant != utils.MetaAny {
result += arrp.Tenant + utils.ConcatenatedKeySep
} else {
return
}
if arrp.Category != "" && arrp.Category != utils.MetaAny {
if arrp.Category != utils.EmptyString && arrp.Category != utils.MetaAny {
result += arrp.Category + utils.ConcatenatedKeySep
} else {
return
}
if arrp.Subject != "" && arrp.Subject != utils.MetaAny {
if arrp.Subject != utils.EmptyString {
result += arrp.Subject
}
return
@@ -1250,8 +1250,8 @@ func (apierSv1 *APIerSv1) RemoveRatingProfile(attr *AttrRemoveRatingProfile, rep
if attr.Tenant == utils.EmptyString {
attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
}
if (attr.Subject != "" && utils.IsSliceMember([]string{attr.Tenant, attr.Category}, "")) ||
(attr.Category != "" && attr.Tenant == "") {
if (attr.Subject != utils.EmptyString && utils.IsSliceMember([]string{attr.Tenant, attr.Category}, utils.EmptyString)) ||
(attr.Category != utils.EmptyString && attr.Tenant == utils.EmptyString) {
return utils.ErrMandatoryIeMissing
}
err := guardian.Guardian.Guard(func() error {

View File

@@ -22,6 +22,7 @@ package v1
import (
"net/rpc"
"os/exec"
"path"
"reflect"
"sort"
@@ -65,6 +66,14 @@ var (
testAPIerLoadRatingProfile,
testAPIerLoadFromFolderAccountAction,
testAPIerKillEngine,
testAPIerInitDataDb,
testAPIerResetStorDb,
testAPIerStartEngineSleep,
testAPIerRPCConn,
testApierSetAndRemoveRatingProfileAnySubject,
testAPIerKillEngine,
}
)
@@ -74,6 +83,7 @@ func TestApierIT2(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
APIerSv2ConfigDIR = "tutinternal"
sTestsAPIer = sTestsAPIer[:len(sTestsAPIer)-6]
case utils.MetaMySQL:
APIerSv2ConfigDIR = "tutmysql"
case utils.MetaMongo:
@@ -110,6 +120,14 @@ func testAPIerResetStorDb(t *testing.T) {
}
}
// Start CGR Engine
func testAPIerStartEngineSleep(t *testing.T) {
time.Sleep(500*time.Millisecond)
if _, err := engine.StopStartEngine(apierCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
}
// Start CGR Engine
func testAPIerStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(apierCfgPath, *waitRater); err != nil {
@@ -658,6 +676,65 @@ func testAPIerLoadFromFolderAccountAction(t *testing.T) {
}
}
func testApierSetAndRemoveRatingProfileAnySubject(t *testing.T) {
loader := exec.Command("cgr-loader", "-config_path", apierCfgPath, "-path", path.Join(*dataDir, "tariffplans", "tutorial"))
if err := loader.Run(); err != nil {
t.Error(err)
}
rpf := &utils.AttrSetRatingProfile{
Tenant: "cgrates.org",
Category: "call",
Subject: "SUPPLIER1",
RatingPlanActivations: []*utils.TPRatingActivation{
{
ActivationTime: "2018-01-01T00:00:00Z",
RatingPlanId: "RP_SMS",
},
},
Overwrite: true,
}
var reply string
if err := apierRPC.Call(utils.APIerSv1SetRatingProfile, rpf, &reply); err != nil {
t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error())
} else if reply != utils.OK {
t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply)
}
expected := engine.RatingProfile{
Id: "*out:cgrates.org:sms:*any",
RatingPlanActivations: engine.RatingPlanActivations{
{
ActivationTime: time.Date(2014, 1, 14, 0, 0, 0,0, time.UTC),
RatingPlanId: "RP_SMS",
},
},
}
attrGetRatingPlan := &utils.AttrGetRatingProfile{
Tenant: "cgrates.org", Category: "sms", Subject: utils.MetaAny}
var rpl engine.RatingProfile
if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {
t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err)
} else if !reflect.DeepEqual(expected, rpl) {
t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))
}
if err := apierRPC.Call(utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{
Tenant: "cgrates.org",
Category: "sms",
Subject: utils.MetaAny,
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Expected: %s, received: %s ", utils.OK, reply)
}
if err := apierRPC.Call(utils.APIerSv1GetRatingProfile,
attrGetRatingPlan, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expected %v, \n but received %v", utils.ErrNotFound, err)
}
}
func testAPIerKillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)