[Easy Setup] Check required properties for UPDATE 93/27793/3
authorAbhishek Pandey <abhi.siso@samsung.com>
Mon, 24 Dec 2018 10:05:14 +0000 (15:35 +0530)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Mon, 11 Feb 2019 18:35:03 +0000 (18:35 +0000)
[IOT-3252]
https://jira.iotivity.org/browse/IOT-3252

Per the WiFiConf Schema, for an UPDATE request:
 "required":["tnn", "wat", "wet"]

This means that all three of these Properties must be in every
UPDATE request. If they are not there, the Device is supposed
to reject the request with a 4.xx error. However, IoTivity
responds with a 2.04 Changed response instead currently.

This patch fixes above issue by checking the POST request
for required properties (tnn, wat, wet). If any of these
are not included in POST request, it will be rejected.

Change-Id: I00f02c93cd273a02706c85c5d236584d45d6ca77
Signed-off-by: Abhishek Pandey <abhi.siso@samsung.com>
service/easy-setup/enrollee/src/resourcehandler.c

index d963843..af6a7c3 100644 (file)
@@ -587,6 +587,16 @@ OCEntityHandlerResult updateWiFiConfResource(OCRepPayload* input)
         return OC_EH_BAD_REQ;
     }
 
+    // If payload does not contain all required properties, then the request is
+    // considered as a bad request.
+    if (OCRepPayloadIsNull(input, OC_RSRVD_ES_SSID) ||
+        OCRepPayloadIsNull(input, OC_RSRVD_ES_AUTHTYPE) ||
+        OCRepPayloadIsNull(input, OC_RSRVD_ES_ENCTYPE))
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Required property for Update is missing!");
+        return OC_EH_BAD_REQ;
+    }
+
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     ESWiFiConfData* wiFiData = (ESWiFiConfData*) OICMalloc(sizeof(ESWiFiConfData));
     if (wiFiData == NULL)