Added Validation on MessageId and RegistryPrefix
Message ID's and Registry prefixes used to subscribe to an event
will be checked against allowed values.
Corrected "Task" registry prefix to "TaskEvent".
Tested:
- Validated POST action with different combinations of
Message id's and Registry Prefix.
- Redfish validator passed.
Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Change-Id: I921cafeca8b2a1813f4aa4c41ecd01c831e3465b
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index ad567ef..64a2009 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -22,7 +22,7 @@
static constexpr const std::array<const char*, 2> supportedEvtFormatTypes = {
eventFormatType, metricReportFormatType};
static constexpr const std::array<const char*, 3> supportedRegPrefixes = {
- "Base", "OpenBMC", "Task"};
+ "Base", "OpenBMC", "TaskEvent"};
static constexpr const std::array<const char*, 3> supportedRetryPolicies = {
"TerminateAfterRetries", "SuspendRetries", "RetryForever"};
@@ -397,8 +397,54 @@
if (msgIds)
{
- // Do we need to loop-up MessageRegistry and validate
- // data for authenticity??? Not mandate, i believe.
+ std::vector<std::string> registryPrefix;
+
+ // If no registry prefixes are mentioned, consider all supported
+ // prefixes
+ if (subValue->registryPrefixes.empty())
+ {
+ registryPrefix.assign(supportedRegPrefixes.begin(),
+ supportedRegPrefixes.end());
+ }
+ else
+ {
+ registryPrefix = subValue->registryPrefixes;
+ }
+
+ for (const std::string& id : *msgIds)
+ {
+ bool validId = false;
+
+ // Check for Message ID in each of the selected Registry
+ for (const std::string& it : registryPrefix)
+ {
+ const boost::beast::span<
+ const redfish::message_registries::MessageEntry>
+ registry =
+ redfish::message_registries::getRegistryFromPrefix(
+ it);
+
+ if (std::any_of(
+ registry.cbegin(), registry.cend(),
+ [&id](
+ const redfish::message_registries::MessageEntry&
+ messageEntry) {
+ return !id.compare(messageEntry.first);
+ }))
+ {
+ validId = true;
+ break;
+ }
+ }
+
+ if (!validId)
+ {
+ messages::propertyValueNotInList(asyncResp->res, id,
+ "MessageIds");
+ return;
+ }
+ }
+
subValue->registryMsgIds = *msgIds;
}