Updated APIBan precache integration tests

This commit is contained in:
Trial97
2020-11-05 12:09:34 +02:00
committed by Dan Christian Bogos
parent 31c635e3f7
commit 03359b0ae6
5 changed files with 228 additions and 81 deletions

View File

@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package v1
import (
"flag"
"net/rpc"
"path"
"reflect"
@@ -40,6 +41,9 @@ var (
precacheDataDir = "/usr/share/cgrates"
precacheConfigDIR string //run tests for specific configuration
// use this flag to test the APIBan implemnentation for precache
apiBan = flag.Bool("apiban", true, "used to control if we run the apiban tests")
sTestsPrecache = []func(t *testing.T){
testPrecacheInitCfg,
testPrecacheResetDataDB,
@@ -69,6 +73,9 @@ func TestPrecacheIT(t *testing.T) {
default:
t.Fatal("Unknown Database type")
}
if *apiBan {
precacheConfigDIR += "_apiban"
}
for _, stest := range sTestsPrecache {
t.Run(precacheConfigDIR, stest)
}
@@ -157,97 +164,59 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
expectedStats := &map[string]*ltcache.CacheStats{
utils.MetaDefault: {},
utils.CacheAccountActionPlans: {},
utils.CacheActionPlans: {
Items: 4,
},
utils.CacheActionTriggers: {
Items: 1,
},
utils.CacheActions: {
Items: 9,
},
utils.CacheActionPlans: {Items: 4},
utils.CacheActionTriggers: {Items: 1},
utils.CacheActions: {Items: 9},
utils.CacheAttributeFilterIndexes: {
Items: 2,
Groups: 2,
},
utils.CacheAttributeProfiles: {
Items: 1,
},
utils.CacheChargerFilterIndexes: {},
utils.CacheChargerProfiles: {},
utils.CacheDispatcherFilterIndexes: {},
utils.CacheDispatcherProfiles: {
Items: 6,
},
utils.CacheDispatcherHosts: {
Items: 1,
},
utils.CacheDispatcherRoutes: {},
utils.CacheDispatcherLoads: {},
utils.CacheDestinations: {
Items: 5,
},
utils.CacheDispatchers: {},
utils.CacheEventResources: {},
utils.CacheFilters: {
Items: 15,
},
utils.CacheAttributeProfiles: {Items: 1},
utils.CacheChargerFilterIndexes: {},
utils.CacheChargerProfiles: {},
utils.CacheDispatcherFilterIndexes: {},
utils.CacheDispatcherProfiles: {Items: 6},
utils.CacheDispatcherHosts: {Items: 1},
utils.CacheDispatcherRoutes: {},
utils.CacheDispatcherLoads: {},
utils.CacheDestinations: {Items: 5},
utils.CacheDispatchers: {},
utils.CacheEventResources: {},
utils.CacheFilters: {Items: 15},
utils.CacheRateProfilesFilterIndexes: {},
utils.CacheRateFilterIndexes: {},
utils.CacheRateProfiles: {},
utils.CacheRatingPlans: {
Items: 4,
},
utils.CacheRatingProfiles: {
Items: 5,
},
utils.CacheRatingPlans: {Items: 4},
utils.CacheRatingProfiles: {Items: 5},
utils.CacheResourceFilterIndexes: {
Items: 6,
Groups: 1,
},
utils.CacheResourceProfiles: {
Items: 3,
},
utils.CacheResources: {
Items: 3,
},
utils.CacheReverseDestinations: {
Items: 7,
},
utils.CacheRPCResponses: {},
utils.CacheSharedGroups: {
Items: 1,
},
utils.CacheResourceProfiles: {Items: 3},
utils.CacheResources: {Items: 3},
utils.CacheReverseDestinations: {Items: 7},
utils.CacheRPCResponses: {},
utils.CacheSharedGroups: {Items: 1},
utils.CacheStatFilterIndexes: {
Items: 2,
Groups: 1,
},
utils.CacheStatQueueProfiles: {
Items: 1,
},
utils.CacheStatQueues: {
Items: 1,
},
utils.CacheSTIR: {},
utils.CacheCapsEvents: {},
utils.CacheEventCharges: {},
utils.CacheStatQueueProfiles: {Items: 1},
utils.CacheStatQueues: {Items: 1},
utils.CacheSTIR: {},
utils.CacheCapsEvents: {},
utils.CacheEventCharges: {},
utils.CacheRouteFilterIndexes: {
Items: 6,
Groups: 1,
},
utils.CacheRouteProfiles: {
Items: 3,
},
utils.CacheRouteProfiles: {Items: 3},
utils.CacheThresholdFilterIndexes: {
Items: 10,
Groups: 1,
},
utils.CacheThresholdProfiles: {
Items: 7,
},
utils.CacheThresholds: {
Items: 7,
},
utils.CacheThresholdProfiles: {Items: 7},
utils.CacheThresholds: {Items: 7},
utils.CacheTimings: {},
utils.CacheDiameterMessages: {},
utils.CacheClosedSessions: {},
@@ -282,7 +251,10 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
utils.CacheTBLTPDispatchers: {},
utils.CacheTBLTPDispatcherHosts: {},
utils.CacheTBLTPRateProfiles: {},
utils.MetaAPIBan: {Items: 254},
utils.MetaAPIBan: {},
}
if *apiBan {
(*expectedStats)[utils.MetaAPIBan] = &ltcache.CacheStats{Items: 254}
}
if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil {
t.Error(err.Error())

View File

@@ -58,7 +58,6 @@
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
@@ -90,9 +89,4 @@
},
"apiban": {
"keys": ["4c8140a0d7ec506e03ac59283eea8a9a", "559bbfa6808558b3197bf4960bbc1635", "2efdcd5d3d1b3a3ab4d71636b7b6d847"],
},
}

View File

@@ -0,0 +1,98 @@
{
// CGRateS Configuration file
"general": {
"log_level": 7,
"reply_timeout": "30s",
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": {
"db_type": "mongo",
"db_name": "10",
"db_port": 27017,
},
"stor_db": {
"db_type": "mongo",
"db_name": "cgrates",
"db_port": 27017,
},
"caches":{
"partitions": {
"*destinations": {"limit": 10000, "ttl":"0s", "precache": true},
"*reverse_destinations": {"limit": 10000, "ttl":"0s", "precache": true},
"*rating_plans": {"limit": 10000, "ttl":"0s","precache": true},
"*rating_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*actions": {"limit": 10000, "ttl":"0s", "precache": true},
"*action_plans": {"limit": 10000, "ttl":"0s", "precache": true},
"*account_action_plans": {"limit": 10000, "ttl":"0s", "precache": true},
"*action_triggers": {"limit": 10000, "ttl":"0s", "precache": true},
"*shared_groups": {"limit": 10000, "ttl":"0s", "precache": true},
"*resource_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*resources": {"limit": 10000, "ttl":"0s", "precache": true},
"*statqueues": {"limit": 10000, "ttl":"0s", "precache": true},
"*statqueue_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*thresholds": {"limit": 10000, "ttl":"0s", "precache": true},
"*threshold_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*filters": {"limit": 10000, "ttl":"0s", "precache": true},
"*route_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*resource_filter_indexes" :{"limit": 10000, "ttl":"0s", "precache": true},
"*stat_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*threshold_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*route_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*attribute_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
"rals": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"migrator": {
"out_datadb_type": "mongo",
"out_datadb_port": "27017",
"out_datadb_name": "10",
"out_stordb_type": "mongo",
"out_stordb_port": "27017",
"out_stordb_name": "cgrates",
"users_filters":["Account"],
},
"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
"apiban": {
"keys": ["8b0622b2d29a1f1e43c648ac45737204","2efdcd5d3d1b3a3ab4d71636b7b6d847","4c8140a0d7ec506e03ac59283eea8a9a","559bbfa6808558b3197bf4960bbc1635"],
},
}

View File

@@ -54,7 +54,6 @@
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
@@ -81,9 +80,4 @@
},
"apiban": {
"keys": ["4c8140a0d7ec506e03ac59283eea8a9a", "559bbfa6808558b3197bf4960bbc1635", "2efdcd5d3d1b3a3ab4d71636b7b6d847"],
},
}

View File

@@ -0,0 +1,89 @@
{
// CGRateS Configuration file
//
"general": {
"log_level": 7,
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
"db_type": "redis", // data_db type: <redis|mongo>
"db_port": 6379, // data_db port to reach the database
"db_name": "10", // data_db database name to connect to
},
"stor_db": {
"db_password": "CGRateS.org",
},
"caches":{
"partitions": {
"*destinations": {"limit": 10000, "ttl":"0s", "precache": true},
"*reverse_destinations": {"limit": 10000, "ttl":"0s", "precache": true},
"*rating_plans": {"limit": 10000, "ttl":"0s","precache": true},
"*rating_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*actions": {"limit": 10000, "ttl":"0s", "precache": true},
"*action_plans": {"limit": 10000, "ttl":"0s", "precache": true},
"*account_action_plans": {"limit": 10000, "ttl":"0s", "precache": true},
"*action_triggers": {"limit": 10000, "ttl":"0s", "precache": true},
"*shared_groups": {"limit": 10000, "ttl":"0s", "precache": true},
"*resource_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*resources": {"limit": 10000, "ttl":"0s", "precache": true},
"*statqueues": {"limit": 10000, "ttl":"0s", "precache": true},
"*statqueue_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*thresholds": {"limit": 10000, "ttl":"0s", "precache": true},
"*threshold_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*filters": {"limit": 10000, "ttl":"0s", "precache": true},
"*route_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
"*resource_filter_indexes" :{"limit": 10000, "ttl":"0s", "precache": true},
"*stat_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*threshold_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*route_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*attribute_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
"rals": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"migrator":{
"out_stordb_password": "CGRateS.org",
"users_filters":["Account"],
},
"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
"apiban": {
"keys": ["8b0622b2d29a1f1e43c648ac45737204","2efdcd5d3d1b3a3ab4d71636b7b6d847","4c8140a0d7ec506e03ac59283eea8a9a","559bbfa6808558b3197bf4960bbc1635"],
},
}