From 03359b0ae60011ac7f4e6c39ff5aec2f57bfbe8b Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 5 Nov 2020 12:09:34 +0200 Subject: [PATCH] Updated APIBan precache integration tests --- apier/v1/precache_it_test.go | 110 +++++++----------- .../samples/precache/tutmongo/cgrates.json | 6 - .../precache/tutmongo_apiban/cgrates.json | 98 ++++++++++++++++ .../samples/precache/tutmysql/cgrates.json | 6 - .../precache/tutmysql_apiban/cgrates.json | 89 ++++++++++++++ 5 files changed, 228 insertions(+), 81 deletions(-) create mode 100644 data/conf/samples/precache/tutmongo_apiban/cgrates.json create mode 100644 data/conf/samples/precache/tutmysql_apiban/cgrates.json diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go index 323240179..af8f5b42e 100644 --- a/apier/v1/precache_it_test.go +++ b/apier/v1/precache_it_test.go @@ -21,6 +21,7 @@ along with this program. If not, see 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] = <cache.CacheStats{Items: 254} } if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil { t.Error(err.Error()) diff --git a/data/conf/samples/precache/tutmongo/cgrates.json b/data/conf/samples/precache/tutmongo/cgrates.json index 556c500b0..c6865189d 100644 --- a/data/conf/samples/precache/tutmongo/cgrates.json +++ b/data/conf/samples/precache/tutmongo/cgrates.json @@ -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"], -}, - - } diff --git a/data/conf/samples/precache/tutmongo_apiban/cgrates.json b/data/conf/samples/precache/tutmongo_apiban/cgrates.json new file mode 100644 index 000000000..afec722f3 --- /dev/null +++ b/data/conf/samples/precache/tutmongo_apiban/cgrates.json @@ -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"], +}, + + +} diff --git a/data/conf/samples/precache/tutmysql/cgrates.json b/data/conf/samples/precache/tutmysql/cgrates.json index 4f0007a55..158dd7096 100644 --- a/data/conf/samples/precache/tutmysql/cgrates.json +++ b/data/conf/samples/precache/tutmysql/cgrates.json @@ -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"], -}, - - } diff --git a/data/conf/samples/precache/tutmysql_apiban/cgrates.json b/data/conf/samples/precache/tutmysql_apiban/cgrates.json new file mode 100644 index 000000000..79c9eaca1 --- /dev/null +++ b/data/conf/samples/precache/tutmysql_apiban/cgrates.json @@ -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: + "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"], +}, + + +}