From fe506d48d4f894bbb5907a3fabdce25dee7bc8ee Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Wed, 31 Mar 2021 18:11:17 +0300 Subject: [PATCH] Fixed panic for ping methods in dispatchers --- apier/v1/dispatcher.go | 2 +- dispatchers/attributes.go | 8 ++++++-- dispatchers/attributes_it_test.go | 10 ++++++++++ dispatchers/caches.go | 6 +++++- dispatchers/caches_it_test.go | 10 ++++++++++ dispatchers/cdrs.go | 6 +++++- dispatchers/cdrs_it_test.go | 10 ++++++++++ dispatchers/chargers.go | 6 +++++- dispatchers/chargers_it_test.go | 10 ++++++++++ dispatchers/guardian.go | 6 +++++- dispatchers/guardian_it_test.go | 10 ++++++++++ dispatchers/rals.go | 6 +++++- dispatchers/rals_it_test.go | 10 ++++++++++ dispatchers/resources.go | 6 +++++- dispatchers/resources_it_test.go | 10 ++++++++++ dispatchers/responder.go | 6 +++++- dispatchers/responder_it_test.go | 10 ++++++++++ dispatchers/scheduler.go | 6 +++++- dispatchers/scheduler_it_test.go | 11 ++++++++++- dispatchers/sessions.go | 7 +++++++ dispatchers/sessions_it_test.go | 10 ++++++++++ dispatchers/stats.go | 6 +++++- dispatchers/stats_it_test.go | 10 ++++++++++ dispatchers/suppliers.go | 6 +++++- dispatchers/suppliers_it_test.go | 10 ++++++++++ dispatchers/thresholds.go | 6 +++++- dispatchers/thresholds_it_test.go | 10 ++++++++++ utils/cgrevent.go | 5 ++++- utils/cgrevent_test.go | 11 +++++++---- 29 files changed, 210 insertions(+), 20 deletions(-) diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index b07ca7581..140d69580 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -535,7 +535,7 @@ func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithArgDispatcher, rep return dS.dS.ResponderShutdown(args, reply) } -// Ping used to detreminate if component is active +// Ping used to determinate if component is active func (dS *DispatcherResponder) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error { return dS.dS.ResponderPing(args, reply) } diff --git a/dispatchers/attributes.go b/dispatchers/attributes.go index ab925c7ae..5bffd3f39 100755 --- a/dispatchers/attributes.go +++ b/dispatchers/attributes.go @@ -23,11 +23,15 @@ import ( "github.com/cgrates/cgrates/utils" ) -// AttributeSv1Ping interogates AttributeS server responsible to process the event +// AttributeSv1Ping interrogates AttributeS server responsible to process the event func (dS *DispatcherService) AttributeSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 95f3bcf0f..45b299fba 100755 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -37,6 +37,7 @@ var sTestsDspAttr = []func(t *testing.T){ testDspAttrGetAttrRoundRobin, testDspAttrPing, + testDspAttrPingEmptyCGREventWIthArgDispatcher, testDspAttrTestMissingArgDispatcher, testDspAttrTestMissingApiKey, testDspAttrTestUnknownApiKey, @@ -326,6 +327,15 @@ func testDspAttrPing(t *testing.T) { } } +func testDspAttrPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspAttrTestMissingArgDispatcher(t *testing.T) { args := &engine.AttrArgsProcessEvent{ Context: utils.StringPointer("simpleauth"), diff --git a/dispatchers/caches.go b/dispatchers/caches.go index cb751ac22..7ebe56f7a 100644 --- a/dispatchers/caches.go +++ b/dispatchers/caches.go @@ -28,8 +28,12 @@ import ( // CacheSv1Ping interogates CacheSv1 server responsible to process the event func (dS *DispatcherService) CacheSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/caches_it_test.go b/dispatchers/caches_it_test.go index f06ebdd01..1daa97ccd 100644 --- a/dispatchers/caches_it_test.go +++ b/dispatchers/caches_it_test.go @@ -33,6 +33,7 @@ import ( var sTestsDspChc = []func(t *testing.T){ testDspChcPing, + testDspChcPingEmptyCGREventWIthArgDispatcher, testDspChcLoadAfterFolder, testDspChcPrecacheStatus, testDspChcGetItemIDs, @@ -95,6 +96,15 @@ func testDspChcPing(t *testing.T) { } } +func testDspChcPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + var reply string + expected := "MANDATORY_IE_MISSING: [APIKey]" + if err := dispEngine.RPC.Call(utils.CacheSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspChcLoadAfterFolder(t *testing.T) { var rcvStats map[string]*ltcache.CacheStats expStats := engine.GetDefaultEmptyCacheStats() diff --git a/dispatchers/cdrs.go b/dispatchers/cdrs.go index 8b5ce4d42..42dba54c3 100644 --- a/dispatchers/cdrs.go +++ b/dispatchers/cdrs.go @@ -28,8 +28,12 @@ import ( // CDRsV1Ping interogates CDRsV1 server responsible to process the event func (dS *DispatcherService) CDRsV1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } tnt := dS.cfg.GeneralCfg().DefaultTenant if args.CGREvent != nil && args.CGREvent.Tenant != utils.EmptyString { diff --git a/dispatchers/cdrs_it_test.go b/dispatchers/cdrs_it_test.go index c1399d260..709931b30 100644 --- a/dispatchers/cdrs_it_test.go +++ b/dispatchers/cdrs_it_test.go @@ -31,6 +31,7 @@ import ( var ( sTestsDspCDRs = []func(t *testing.T){ testDspCDRsPing, + testDspCDRsPingEmptyCGREventWIthArgDispatcher, testDspCDRsProcessEvent, testDspCDRsCountCDR, testDspCDRsGetCDR, @@ -113,6 +114,15 @@ func testDspCDRsPing(t *testing.T) { } } +func testDspCDRsPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.CDRsV1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspCDRsProcessEvent(t *testing.T) { var reply string args := &engine.ArgV1ProcessEvent{ diff --git a/dispatchers/chargers.go b/dispatchers/chargers.go index 9c56f0d94..8817082ea 100755 --- a/dispatchers/chargers.go +++ b/dispatchers/chargers.go @@ -24,8 +24,12 @@ import ( ) func (dS *DispatcherService) ChargerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go index e44f49c6d..ae2ba282a 100755 --- a/dispatchers/chargers_it_test.go +++ b/dispatchers/chargers_it_test.go @@ -36,6 +36,7 @@ var sTestsDspCpp = []func(t *testing.T){ testDspCppGetChtgRoundRobin, testDspCppPing, + testDspCppPingEmptyCGREventWIthArgDispatcher, testDspCppTestAuthKey, testDspCppTestAuthKey2, } @@ -185,6 +186,15 @@ func testDspCppPing(t *testing.T) { } } +func testDspCppPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.ChargerSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspCppTestAuthKey(t *testing.T) { args := utils.CGREventWithArgDispatcher{ CGREvent: &utils.CGREvent{ diff --git a/dispatchers/guardian.go b/dispatchers/guardian.go index 2af93da1b..9c88f91e6 100644 --- a/dispatchers/guardian.go +++ b/dispatchers/guardian.go @@ -27,8 +27,12 @@ import ( // GuardianSv1Ping interogates GuardianSv1 server responsible to process the event func (dS *DispatcherService) GuardianSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/guardian_it_test.go b/dispatchers/guardian_it_test.go index 1322cbca9..cbc3d6884 100644 --- a/dispatchers/guardian_it_test.go +++ b/dispatchers/guardian_it_test.go @@ -30,6 +30,7 @@ import ( var sTestsDspGrd = []func(t *testing.T){ testDspGrdPing, + testDspGrdPingEmptyCGREventWIthArgDispatcher, testDspGrdLock, } @@ -81,6 +82,15 @@ func testDspGrdPing(t *testing.T) { } } +func testDspGrdPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.GuardianSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspGrdLock(t *testing.T) { // lock args := utils.AttrRemoteLock{ diff --git a/dispatchers/rals.go b/dispatchers/rals.go index 553ea4183..6df92f250 100644 --- a/dispatchers/rals.go +++ b/dispatchers/rals.go @@ -23,8 +23,12 @@ import ( ) func (dS *DispatcherService) RALsV1Ping(args *utils.CGREventWithArgDispatcher, rpl *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/rals_it_test.go b/dispatchers/rals_it_test.go index 9bfcf6244..50fd55083 100644 --- a/dispatchers/rals_it_test.go +++ b/dispatchers/rals_it_test.go @@ -29,6 +29,7 @@ import ( var sTestsDspRALs = []func(t *testing.T){ testDspRALsPing, + testDspRALsPingEmptyCGREventWIthArgDispatcher, testDspRALsGetRatingPlanCost, } @@ -80,6 +81,15 @@ func testDspRALsPing(t *testing.T) { } } +func testDspRALsPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + var reply string + expected := "MANDATORY_IE_MISSING: [APIKey]" + if err := dispEngine.RPC.Call(utils.RALsV1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspRALsGetRatingPlanCost(t *testing.T) { arg := &utils.RatingPlanCostArg{ Destination: "1002", diff --git a/dispatchers/resources.go b/dispatchers/resources.go index 57a887809..1e66bd23c 100755 --- a/dispatchers/resources.go +++ b/dispatchers/resources.go @@ -24,8 +24,12 @@ import ( ) func (dS *DispatcherService) ResourceSv1Ping(args *utils.CGREventWithArgDispatcher, rpl *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/resources_it_test.go b/dispatchers/resources_it_test.go index ecd371da1..60c695508 100755 --- a/dispatchers/resources_it_test.go +++ b/dispatchers/resources_it_test.go @@ -32,6 +32,7 @@ var sTestsDspRes = []func(t *testing.T){ testDspResPingFailover, testDspResPing, + testDspResPingEmptyCGREventWIthArgDispatcher, testDspResTestAuthKey, testDspResTestAuthKey2, testDspResTestAuthKey3, @@ -119,6 +120,15 @@ func testDspResPing(t *testing.T) { } } +func testDspResPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.ResourceSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspResTestAuthKey(t *testing.T) { var rs *engine.Resources args := &utils.ArgRSv1ResourceUsage{ diff --git a/dispatchers/responder.go b/dispatchers/responder.go index 057397b59..d20ddf976 100644 --- a/dispatchers/responder.go +++ b/dispatchers/responder.go @@ -28,8 +28,12 @@ import ( // ResponderPing interogates Responder server responsible to process the event func (dS *DispatcherService) ResponderPing(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/responder_it_test.go b/dispatchers/responder_it_test.go index 51422e00a..298242e06 100644 --- a/dispatchers/responder_it_test.go +++ b/dispatchers/responder_it_test.go @@ -34,6 +34,7 @@ var sTestsDspRsp = []func(t *testing.T){ testDspResponderRandom, testDspResponderBroadcast, testDspResponderInternal, + testDspResponderPingEmptyCGREventWIthArgDispatcher, } //Test start here @@ -246,3 +247,12 @@ func testDspResponderInternal(t *testing.T) { t.Errorf("Expected: DispatcherS1 , received: %s", strRply) } } + +func testDspResponderPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.ResponderPing, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} diff --git a/dispatchers/scheduler.go b/dispatchers/scheduler.go index 2410ae8eb..0584e45c7 100644 --- a/dispatchers/scheduler.go +++ b/dispatchers/scheduler.go @@ -23,8 +23,12 @@ import ( ) func (dS *DispatcherService) SchedulerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/scheduler_it_test.go b/dispatchers/scheduler_it_test.go index dcc129618..7ea2749b7 100644 --- a/dispatchers/scheduler_it_test.go +++ b/dispatchers/scheduler_it_test.go @@ -28,10 +28,10 @@ import ( var sTestsDspSched = []func(t *testing.T){ testDspSchedPing, + testDspSchedPingEmptyCGREventWIthArgDispatcher, } //Test start here - func TestDspSchedulerS(t *testing.T) { var config1, config2, config3 string switch *dbType { @@ -78,3 +78,12 @@ func testDspSchedPing(t *testing.T) { t.Errorf("Received: %s", reply) } } + +func testDspSchedPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.SchedulerSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} diff --git a/dispatchers/sessions.go b/dispatchers/sessions.go index 0326e6a5a..51420f051 100755 --- a/dispatchers/sessions.go +++ b/dispatchers/sessions.go @@ -26,6 +26,13 @@ import ( ) func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { + args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) + } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if args.ArgDispatcher == nil { diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index 2b69ba64b..327752a51 100755 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -39,6 +39,7 @@ var sTestsDspSession = []func(t *testing.T){ testDspSessionPingFailover, testDspSessionPing, + testDspSessPingEmptyCGREventWIthArgDispatcher, testDspSessionTestAuthKey, testDspSessionAuthorize, testDspSessionInit, @@ -148,6 +149,15 @@ func testDspSessionPing(t *testing.T) { } } +func testDspSessPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.SessionSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspSessionPingFailover(t *testing.T) { var reply string if err := allEngine.RPC.Call(utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil { diff --git a/dispatchers/stats.go b/dispatchers/stats.go index 9c1df6dd4..fff6b50dc 100755 --- a/dispatchers/stats.go +++ b/dispatchers/stats.go @@ -26,8 +26,12 @@ import ( ) func (dS *DispatcherService) StatSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/stats_it_test.go b/dispatchers/stats_it_test.go index 10b5e0f00..1b7e42703 100755 --- a/dispatchers/stats_it_test.go +++ b/dispatchers/stats_it_test.go @@ -35,6 +35,7 @@ var sTestsDspSts = []func(t *testing.T){ testDspStsGetStatFailover, testDspStsPing, + testDspStsPingEmptyCGREventWIthArgDispatcher, testDspStsTestAuthKey, testDspStsTestAuthKey2, testDspStsTestAuthKey3, @@ -174,6 +175,15 @@ func testDspStsPing(t *testing.T) { } } +func testDspStsPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.StatSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspStsTestAuthKey(t *testing.T) { var reply []string args := engine.StatsArgsProcessEvent{ diff --git a/dispatchers/suppliers.go b/dispatchers/suppliers.go index 41e4e4c04..20284a0a0 100755 --- a/dispatchers/suppliers.go +++ b/dispatchers/suppliers.go @@ -24,8 +24,12 @@ import ( ) func (dS *DispatcherService) SupplierSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/dispatchers/suppliers_it_test.go b/dispatchers/suppliers_it_test.go index ba0fe07e3..8a867aa85 100755 --- a/dispatchers/suppliers_it_test.go +++ b/dispatchers/suppliers_it_test.go @@ -36,6 +36,7 @@ var sTestsDspSup = []func(t *testing.T){ testDspSupGetSupRoundRobin, testDspSupPing, + testDspSupPingEmptyCGREventWIthArgDispatcher, testDspSupTestAuthKey, testDspSupTestAuthKey2, testDspSupGetSupplierForEvent, @@ -89,6 +90,15 @@ func testDspSupPing(t *testing.T) { } } +func testDspSupPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.SupplierSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspSupPingFailover(t *testing.T) { var reply string if err := allEngine.RPC.Call(utils.SupplierSv1Ping, new(utils.CGREvent), &reply); err != nil { diff --git a/dispatchers/thresholds.go b/dispatchers/thresholds.go index 495bdc5ad..a0290834b 100755 --- a/dispatchers/thresholds.go +++ b/dispatchers/thresholds.go @@ -26,8 +26,12 @@ import ( ) func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) { - if args == nil { + if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) { args = utils.NewCGREventWithArgDispatcher() + } else if args.CGREvent == nil { + args.CGREvent = new(utils.CGREvent) + } else if args.ArgDispatcher == nil { + args.ArgDispatcher = new(utils.ArgDispatcher) } args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if args.ArgDispatcher == nil { diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go index 6d1cd00e8..6fd7b17ef 100755 --- a/dispatchers/thresholds_it_test.go +++ b/dispatchers/thresholds_it_test.go @@ -35,6 +35,7 @@ var sTestsDspTh = []func(t *testing.T){ testDspThProcessEventFailover, testDspThPing, + testDspThPingEmptyCGREventWIthArgDispatcher, testDspThTestAuthKey, testDspThTestAuthKey2, testDspThTestAuthKey3, @@ -153,6 +154,15 @@ func testDspThPing(t *testing.T) { } } +func testDspThPingEmptyCGREventWIthArgDispatcher(t *testing.T) { + expected := "MANDATORY_IE_MISSING: [APIKey]" + var reply string + if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping, + &utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected { + t.Errorf("Expected %+v, received %+v", expected, err) + } +} + func testDspThTestAuthKey(t *testing.T) { var ids []string nowTime := time.Now() diff --git a/utils/cgrevent.go b/utils/cgrevent.go index 9541f1fb9..5b425b149 100644 --- a/utils/cgrevent.go +++ b/utils/cgrevent.go @@ -224,7 +224,10 @@ type CGREvents struct { } func NewCGREventWithArgDispatcher() *CGREventWithArgDispatcher { - return new(CGREventWithArgDispatcher) + return &CGREventWithArgDispatcher{ + CGREvent: new(CGREvent), + ArgDispatcher: new(ArgDispatcher), + } } type CGREventWithArgDispatcher struct { diff --git a/utils/cgrevent_test.go b/utils/cgrevent_test.go index 598db4ac6..1f148b3e1 100644 --- a/utils/cgrevent_test.go +++ b/utils/cgrevent_test.go @@ -447,11 +447,14 @@ func TestCGREventConsumeArgs(t *testing.T) { } func TestNewCGREventWithArgDispatcher(t *testing.T) { - eOut := new(CGREventWithArgDispatcher) - rcv := NewCGREventWithArgDispatcher() + exp := &CGREventWithArgDispatcher{ + CGREvent: new(CGREvent), + ArgDispatcher: new(ArgDispatcher), + } + eOut := NewCGREventWithArgDispatcher() - if !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) + if !reflect.DeepEqual(eOut, exp) { + t.Errorf("Expecting: %+v, received: %+v", eOut, exp) } }