Add extra input validation for AddReport
Now AddReport checks if ReadingParams exceeds limits that is set
to 200. AddReport checks if interval is less than allowed interval
only for Periodic reports. AddReport verify if only single sensor
for each reading parameters is provided.
Tested:
- Ran unit-tests with success.
- Added few reports in OpenBMC environment to check if results are
as expected.
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
Change-Id: Ife4f8a4cf6a8dc3fa526b66e4c698a57a733de48
diff --git a/tests/src/test_report_manager.cpp b/tests/src/test_report_manager.cpp
index c780556..1a81844 100644
--- a/tests/src/test_report_manager.cpp
+++ b/tests/src/test_report_manager.cpp
@@ -120,6 +120,7 @@
reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock), _)
.Times(0);
+ reportParams.reportingType("Periodic");
reportParams.interval(reportParams.interval() - 1ms);
auto [ec, path] = addReport(reportParams);
@@ -127,6 +128,39 @@
EXPECT_THAT(path, Eq(std::string()));
}
+TEST_F(TestReportManager, DISABLED_failToAddReportWithInvalidReportingType)
+{
+ reportFactoryMock.expectMake(_, std::nullopt, Ref(*sut), Ref(storageMock))
+ .Times(0);
+ reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock), _)
+ .Times(0);
+
+ reportParams.reportingType("Invalid");
+
+ auto [ec, path] = addReport(reportParams);
+ EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+ EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithMoreSensorsThanExpected)
+{
+ reportFactoryMock.expectMake(_, std::nullopt, Ref(*sut), Ref(storageMock))
+ .Times(0);
+ reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock), _)
+ .Times(0);
+
+ auto readingParams = reportParams.readingParameters();
+ for (size_t i = 0; i < ReportManager::maxReadingParams + 1; i++)
+ {
+ readingParams.push_back(readingParams.front());
+ }
+ reportParams.readingParameters(std::move(readingParams));
+
+ auto [ec, path] = addReport(reportParams);
+ EXPECT_THAT(ec.value(), Eq(boost::system::errc::argument_list_too_long));
+ EXPECT_THAT(path, Eq(std::string()));
+}
+
TEST_F(TestReportManager, DISABLED_failToAddReportWhenMaxReportIsReached)
{
reportFactoryMock.expectMake(_, std::nullopt, Ref(*sut), Ref(storageMock))