From 6ed1d91b18142ffebe0c57203b54ffc28fcd1b78 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Thu, 30 May 2024 13:04:51 -0400 Subject: [PATCH] update --- .../src/RSUConfigurationList.cpp | 12 +---------- .../src/RSUConfigurationList.h | 2 -- .../src/RSUHealthMonitorPlugin.cpp | 1 - .../test/test_RSUConfigurationList.cpp | 20 +++++++++---------- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp index 5b3caa040..62a751551 100644 --- a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp +++ b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp @@ -84,16 +84,6 @@ namespace RSUHealthMonitor throw RSUConfigurationException(errMsg); } - if (rsuArray[i].isMember(RSUIdentifierKey)) - { - config.RSUIdentifier = rsuArray[i][RSUIdentifierKey].asString(); - } - else - { - auto errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU Identifier [" + std::string(RSUIdentifierKey) + "] is required."; - throw RSUConfigurationException(errMsg); - } - if (rsuArray[i].isMember(SecurityLevelKey)) { config.securityLevel = rsuArray[i][SecurityLevelKey].asString(); @@ -142,7 +132,7 @@ namespace RSUHealthMonitor std::ostream &operator<<(std::ostream &os, const RSUConfiguration &config) { - os << RSUIpKey << ": " << config.rsuIp << ", " << SNMPPortKey << ": " << config.snmpPort << ", " << UserKey << ": " << config.user << ", " << AuthPassPhraseKey << ": " << config.authPassPhrase << ", " << SecurityLevelKey << ": " << config.securityLevel << ", " << RSUMIBVersionKey << ": " << config.mibVersion << ", " << RSUIdentifierKey << ": " << config.RSUIdentifier; + os << RSUIpKey << ": " << config.rsuIp << ", " << SNMPPortKey << ": " << config.snmpPort << ", " << UserKey << ": " << config.user << ", " << AuthPassPhraseKey << ": " << config.authPassPhrase << ", " << SecurityLevelKey << ": " << config.securityLevel << ", " << RSUMIBVersionKey << ": " << config.mibVersion; return os; } } \ No newline at end of file diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h index 7f0caed03..5ba523e76 100644 --- a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h +++ b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.h @@ -17,7 +17,6 @@ namespace RSUHealthMonitor static constexpr const char *SecurityLevelKey = "SecurityLevel"; static constexpr const char *RSU4_1_str = "RSU4.1"; static constexpr const char *RSU1218_str = "RSU1218"; - static constexpr const char *RSUIdentifierKey = "RSUIdentifier"; enum class RSUMibVersion { @@ -34,7 +33,6 @@ namespace RSUHealthMonitor std::string authPassPhrase; std::string securityLevel; RSUMibVersion mibVersion; - std::string RSUIdentifier; friend std::ostream &operator<<(std::ostream &os, const RSUConfiguration &config); }; diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp index 835612dfd..ea4a0ce09 100755 --- a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp +++ b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp @@ -27,7 +27,6 @@ namespace RSUHealthMonitor for (auto rsuConfig : _rsuConfigListPtr->getConfigs()) { auto rsuStatusJson = _rsuWorker->getRSUStatus(rsuConfig.mibVersion, rsuConfig.rsuIp, rsuConfig.snmpPort, rsuConfig.user, rsuConfig.authPassPhrase, rsuConfig.securityLevel, SEC_TO_MICRO); - rsuStatusJson[RSUIdentifierKey] = rsuConfig.RSUIdentifier; BroadcastRSUStatus(rsuStatusJson, rsuConfig.mibVersion); } } diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/test/test_RSUConfigurationList.cpp b/src/v2i-hub/RSUHealthMonitorPlugin/test/test_RSUConfigurationList.cpp index d3441ffbc..ae7c35974 100644 --- a/src/v2i-hub/RSUHealthMonitorPlugin/test/test_RSUConfigurationList.cpp +++ b/src/v2i-hub/RSUHealthMonitorPlugin/test/test_RSUConfigurationList.cpp @@ -12,18 +12,18 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"}] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; rsuConfigList->parseRSUs(rsuConfigsStr); ASSERT_EQ(2, rsuConfigList->getConfigs().size()); std::stringstream ss; ss << rsuConfigList->getConfigs()[0]; - std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU4.1, RSUIdentifier: NA"; + std::string expected = "RSUIp: 192.168.XX.XX, SNMPPort: 161, User: authOnlyUser, AuthPassPhrase: dummy, SecurityLevel: authPriv, RSUMIBVersion: RSU4.1"; ASSERT_EQ(expected, ss.str()); } TEST_F(test_RSUConfigurationList, parseAndGetConfigs_MalformatJSON) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -31,7 +31,7 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_RSUS) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"ERROR\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"},{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\"}] }"; + std::string rsuConfigsStr = "{ \"ERROR\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -39,14 +39,14 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_SNMPPORT) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort_Missing\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort_Missing\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } TEST_F(test_RSUConfigurationList, parseAndGetConfigs_INVALID_SNMPPORT) { - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.01.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"INVALID_PORT\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.01.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"INVALID_PORT\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -54,7 +54,7 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_AuthPassPhrase) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase_Missing\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase_Missing\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -62,7 +62,7 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_User) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User_Missing\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User_Missing\": \"authOnlyUser\", \"RSUMIBVersion\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -70,7 +70,7 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Missing_MibVersion) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion_Missing\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\",\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion_Missing\": \"RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); } @@ -78,7 +78,7 @@ namespace RSUHealthMonitor TEST_F(test_RSUConfigurationList, parseAndGetConfigs_Invalid_MibVersion) { ASSERT_EQ(0, rsuConfigList->getConfigs().size()); - std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"INVALID_RSU4.1\" ,\"RSUIdentifier\":\"NA\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" ,\"RSUIdentifier\":\"NA\" }] }"; + std::string rsuConfigsStr = "{ \"RSUS\": [ { \"RSUIp\": \"192.168.XX.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"161\", \"AuthPassPhrase\": \"dummy\", \"User\": \"authOnlyUser\", \"RSUMIBVersion\": \"INVALID_RSU4.1\" },{ \"RSUIp\": \"192.168.00.XX\",\"SecurityLevel\": \"authPriv\", \"SNMPPort\": \"162\", \"AuthPassPhrase\": \"tester\", \"User\": \"authPrivUser\", \"RSUMIBVersion\": \"RSU4.1\" }] }"; ASSERT_THROW(rsuConfigList->parseRSUs(rsuConfigsStr), RSUHealthMonitor::RSUConfigurationException); ASSERT_EQ(0, rsuConfigList->getConfigs().size()); }