management: correct behavior of FaceUpdateCommand::applyDefaultsToRequest and validateResponse
refs #3731
Change-Id: I37feb7a9c4002f723da8e65b40afe0242fd42bfc
diff --git a/src/management/nfd-control-command.cpp b/src/management/nfd-control-command.cpp
index 9853f9d..45c2a08 100644
--- a/src/management/nfd-control-command.cpp
+++ b/src/management/nfd-control-command.cpp
@@ -147,16 +147,17 @@
.optional(CONTROL_PARAMETER_FLAGS)
.optional(CONTROL_PARAMETER_MASK);
m_responseValidator
- .optional(CONTROL_PARAMETER_FACE_ID)
- .optional(CONTROL_PARAMETER_FACE_PERSISTENCY)
- .optional(CONTROL_PARAMETER_FLAGS)
- .optional(CONTROL_PARAMETER_MASK);
+ .required(CONTROL_PARAMETER_FACE_ID)
+ .required(CONTROL_PARAMETER_FACE_PERSISTENCY)
+ .required(CONTROL_PARAMETER_FLAGS);
}
void
FaceUpdateCommand::applyDefaultsToRequest(ControlParameters& parameters) const
{
- parameters.setFaceId(0);
+ if (!parameters.hasFaceId()) {
+ parameters.setFaceId(0);
+ }
}
void
@@ -172,7 +173,11 @@
void
FaceUpdateCommand::validateResponse(const ControlParameters& parameters) const
{
- this->validateRequest(parameters);
+ this->ControlCommand::validateResponse(parameters);
+
+ if (parameters.getFaceId() == 0) {
+ BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
+ }
}
FaceDestroyCommand::FaceDestroyCommand()
diff --git a/src/management/nfd-control-command.hpp b/src/management/nfd-control-command.hpp
index 2f1c4e0..169d837 100644
--- a/src/management/nfd-control-command.hpp
+++ b/src/management/nfd-control-command.hpp
@@ -171,6 +171,10 @@
virtual void
validateRequest(const ControlParameters& parameters) const override;
+ /**
+ * \note This can only validate ControlParameters in a success response.
+ * Failure responses should be validated with validateRequest.
+ */
virtual void
validateResponse(const ControlParameters& parameters) const override;
};