Commit 3f184aa8 authored by Nathan Heldt-Sheller's avatar Nathan Heldt-Sheller

[IOT-1958] CR 22 State Specific Property Access for /pstat Resource

Implementation of CR 22 feature to deny UPDATE to /pstat if any
Property in the POST representation is read-only in the current
/pstat.dos.s state.

Includes necessary update to the CBOR marshalling code to support
partial Resource representations for /pstat.

Includes updates to provisioning tools to correctly include only the
/pstat Properties being updated in the POST payload.

This same change must be implemented for each SVR.

- patch set 2&3: rebased
- patch set 4: fixed a few comments and trigger jenkins
- patch set 5&6: rebased
- patch set 7: addressed Greg's review comments

Change-Id: Ie86fcc1edf4b2370ffcb755c78f1289252dcb516
Signed-off-by: Nathan Heldt-Sheller's avatarNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18989Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarKevin Kane <kkane@microsoft.com>
parent 72e1ab0d
...@@ -25,6 +25,17 @@ ...@@ -25,6 +25,17 @@
extern "C" { extern "C" {
#endif #endif
typedef enum {
PSTAT_DOS = 0,
PSTAT_ISOP,
PSTAT_CM,
PSTAT_TM,
PSTAT_OM,
PSTAT_SM,
PSTAT_ROWNERUUID,
PSTAT_PROPERTY_COUNT
} PstatProperty_t;
/** /**
* Initialize Pstat resource by loading data from persistent storage. * Initialize Pstat resource by loading data from persistent storage.
* *
...@@ -40,18 +51,36 @@ OCStackResult InitPstatResource(); ...@@ -40,18 +51,36 @@ OCStackResult InitPstatResource();
OCStackResult DeInitPstatResource(); OCStackResult DeInitPstatResource();
/** /**
* This method converts PSTAT into the cbor payload. * Converts PSTAT into the cbor payload, including only the
* Properties marked "true" in the propertiesToInclude array.
* *
* @param pstat pointer to the initialized pstat structure. * @param pstat pointer to the initialized pstat structure.
* @param cborPayload pointer to pstat cbor payload. * @param payload pointer to pstat cbor payload.
* @param cborSize of the cbor payload converted. It is 0 in case of error, * @param size of the cbor payload converted. It is 0 in case of error,
* else a positive value if succcessful. * else a positive value if succcessful.
* @param writableOnly indicates whether it is writable only or not. * @param propertiesToInclude Array of bools, size "PSTAT_PROPERTY_COUNT",
* where "true" indicates the corresponding property should be
* included in the CBOR representation that is created.
* *
* @return ::OC_STACK_OK for Success, otherwise some error value. * @return ::OC_STACK_OK for Success, otherwise some error value.
*/ */
OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat, uint8_t **cborPayload, OCStackResult PstatToCBORPayloadPartial(const OicSecPstat_t *pstat,
size_t *cborSize, bool writableOnly); uint8_t **payload, size_t *size, const bool *propertiesToInclude);
/**
* Converts PSTAT into the cbor payload, including all Properties for a
* full representation.
*
* @param pstat pointer to the initialized pstat structure.
* @param payload pointer to pstat cbor payload.
* @param size of the cbor payload converted. It is 0 in case of error,
* else a positive value if succcessful.
*
* @return ::OC_STACK_OK for Success, otherwise some error value.
*/
OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat,
uint8_t **payload, size_t *size);
/** /**
* This method converts cbor into PSTAT data. * This method converts cbor into PSTAT data.
...@@ -59,11 +88,11 @@ OCStackResult DeInitPstatResource(); ...@@ -59,11 +88,11 @@ OCStackResult DeInitPstatResource();
* @param cborPayload is the pstat data in cbor format. * @param cborPayload is the pstat data in cbor format.
* @param cborSize of the cborPayload. In case 0 is provided it assigns CBOR_SIZE (255) value. * @param cborSize of the cborPayload. In case 0 is provided it assigns CBOR_SIZE (255) value.
* @param pstat pointer to @ref OicSecPstat_t. * @param pstat pointer to @ref OicSecPstat_t.
* *
* @return ::OC_STACK_OK for Success, otherwise some error value. * @return ::OC_STACK_OK for Success, otherwise some error value.
*/ */
OCStackResult CBORPayloadToPstat(const uint8_t *cborPayload, const size_t cborSize, OCStackResult CBORPayloadToPstat(const uint8_t *cborPayload, const size_t cborSize,
OicSecPstat_t **pstat); OicSecPstat_t **pstat);
/** This function deallocates the memory for OicSecPstat_t. /** This function deallocates the memory for OicSecPstat_t.
* *
......
...@@ -224,7 +224,8 @@ typedef enum OicSecDeviceOnboardingState ...@@ -224,7 +224,8 @@ typedef enum OicSecDeviceOnboardingState
DOS_RFOTM, DOS_RFOTM,
DOS_RFPRO, DOS_RFPRO,
DOS_RFNOP, DOS_RFNOP,
DOS_SRESET DOS_SRESET,
DOS_STATE_COUNT
} OicSecDeviceOnboardingState_t; } OicSecDeviceOnboardingState_t;
typedef struct OicSecDostype typedef struct OicSecDostype
......
...@@ -414,7 +414,7 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx); ...@@ -414,7 +414,7 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx);
/** /**
* Function to update pstat as Ready for provisioning. * Function to update pstat as Ready for provisioning.
* This function would update 'cm' from bx0000,0010 to bx0000,0000. * This function would update 'dos.s' to DOS_RFPRO.
* *
* @param[in] ctx context value passed to callback from calling function. * @param[in] ctx context value passed to callback from calling function.
* @param[in] selectedDevice selected device information to performing provisioning. * @param[in] selectedDevice selected device information to performing provisioning.
...@@ -424,7 +424,7 @@ static OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx); ...@@ -424,7 +424,7 @@ static OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx);
/** /**
* Function to update pstat as Ready for Normal Operation. * Function to update pstat as Ready for Normal Operation.
* This function would update 'isop' from false to true. * This function would update 'dos.s' to DOS_RFNOP.
* *
* @param[in] ctx context value passed to callback from calling function. * @param[in] ctx context value passed to callback from calling function.
* @param[in] selectedDevice selected device information to performing provisioning. * @param[in] selectedDevice selected device information to performing provisioning.
...@@ -1995,7 +1995,7 @@ static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx) ...@@ -1995,7 +1995,7 @@ static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx)
static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx) static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
{ {
OIC_LOG(DEBUG, TAG, "IN PostOwnershipInformation"); OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
if(!otmCtx || !otmCtx->selectedDeviceInfo) if(!otmCtx || !otmCtx->selectedDeviceInfo)
{ {
...@@ -2012,7 +2012,7 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx) ...@@ -2012,7 +2012,7 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
deviceInfo->connType, deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI)) query, sizeof(query), OIC_RSRC_DOXM_URI))
{ {
OIC_LOG(ERROR, TAG, "PostOwnershipInformation : Failed to generate query"); OIC_LOG_V(ERROR, TAG, "%s : Failed to generate query", __func__);
return OC_STACK_ERROR; return OC_STACK_ERROR;
} }
OIC_LOG_V(DEBUG, TAG, "Query=%s", query); OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
...@@ -2049,14 +2049,14 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx) ...@@ -2049,14 +2049,14 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
OIC_LOG(ERROR, TAG, "OCStack resource error"); OIC_LOG(ERROR, TAG, "OCStack resource error");
} }
OIC_LOG(DEBUG, TAG, "OUT PostOwnershipInformation"); OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
return res; return res;
} }
static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx) static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
{ {
OIC_LOG(DEBUG, TAG, "IN PostUpdateOperationMode"); OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
if(!otmCtx || !otmCtx->selectedDeviceInfo) if(!otmCtx || !otmCtx->selectedDeviceInfo)
{ {
...@@ -2072,7 +2072,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx) ...@@ -2072,7 +2072,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
deviceInfo->connType, deviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI)) query, sizeof(query), OIC_RSRC_PSTAT_URI))
{ {
OIC_LOG(ERROR, TAG, "PostUpdateOperationMode : Failed to generate query"); OIC_LOG_V(ERROR, TAG, "%s Failed to generate query", __func__);
return OC_STACK_ERROR; return OC_STACK_ERROR;
} }
OIC_LOG_V(DEBUG, TAG, "Query=%s", query); OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
...@@ -2084,8 +2084,13 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx) ...@@ -2084,8 +2084,13 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
secPayload->base.type = PAYLOAD_TYPE_SECURITY; secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = PstatToCBORPayload(deviceInfo->pstat, &secPayload->securityData,
&secPayload->payloadSize, true); bool propertiesToInclude[PSTAT_PROPERTY_COUNT];
memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
propertiesToInclude[PSTAT_OM] = true;
OCStackResult res = PstatToCBORPayloadPartial(deviceInfo->pstat, &secPayload->securityData,
&secPayload->payloadSize, propertiesToInclude);
if (OC_STACK_OK != res) if (OC_STACK_OK != res)
{ {
OCPayloadDestroy((OCPayload *)secPayload); OCPayloadDestroy((OCPayload *)secPayload);
...@@ -2104,7 +2109,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx) ...@@ -2104,7 +2109,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
OIC_LOG(ERROR, TAG, "OCStack resource error"); OIC_LOG(ERROR, TAG, "OCStack resource error");
} }
OIC_LOG(DEBUG, TAG, "OUT PostUpdateOperationMode"); OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
return res; return res;
} }
...@@ -2432,7 +2437,7 @@ OCStackResult OTMSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus ...@@ -2432,7 +2437,7 @@ OCStackResult OTMSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus
OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx) OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
{ {
OIC_LOG(INFO, TAG, "IN PostProvisioningStatus"); OIC_LOG_V(INFO, TAG, "IN %s", __func__);
if(!otmCtx || !otmCtx->selectedDeviceInfo) if(!otmCtx || !otmCtx->selectedDeviceInfo)
{ {
...@@ -2440,9 +2445,15 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx) ...@@ -2440,9 +2445,15 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
return OC_STACK_INVALID_PARAM; return OC_STACK_INVALID_PARAM;
} }
//Change the TAKE_OWNER bit of TM to 0. // Change the TAKE_OWNER bit of TM to 0 (optional in Client Directed)
otmCtx->selectedDeviceInfo->pstat->tm &= (~TAKE_OWNER); otmCtx->selectedDeviceInfo->pstat->tm &= (~TAKE_OWNER);
// Change the dos.s value to RFPRO
otmCtx->selectedDeviceInfo->pstat->dos.state = DOS_RFPRO;
// TODO [IOT-2052] set the rowneruuid for /pstat directly, so the hack
// in pstatresource.c which sets all rowneruuids can be removed.
OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload)); OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
if (!secPayload) if (!secPayload)
{ {
...@@ -2450,8 +2461,18 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx) ...@@ -2450,8 +2461,18 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
secPayload->base.type = PAYLOAD_TYPE_SECURITY; secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize, true)) // Note [IOT-2052] all the POST payloads in the provisioningclient app
// should be updated to use the Partial payload APIs for the SVRs, so they
// do not include read-only Properties for the Server device current
// state.
bool propertiesToInclude[PSTAT_PROPERTY_COUNT];
memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
propertiesToInclude[PSTAT_DOS] = true;
propertiesToInclude[PSTAT_TM] = true;
if (OC_STACK_OK != PstatToCBORPayloadPartial(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize, propertiesToInclude))
{ {
OCPayloadDestroy((OCPayload *)secPayload); OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON; return OC_STACK_INVALID_JSON;
...@@ -2468,7 +2489,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx) ...@@ -2468,7 +2489,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
otmCtx->selectedDeviceInfo->connType, otmCtx->selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI)) query, sizeof(query), OIC_RSRC_PSTAT_URI))
{ {
OIC_LOG(ERROR, TAG, "PostProvisioningStatus : Failed to generate query"); OIC_LOG_V(ERROR, TAG, "%s : Failed to generate query", __func__);
return OC_STACK_ERROR; return OC_STACK_ERROR;
} }
OIC_LOG_V(DEBUG, TAG, "Query=%s", query); OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
...@@ -2485,7 +2506,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx) ...@@ -2485,7 +2506,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
OIC_LOG(ERROR, TAG, "OCStack resource error"); OIC_LOG(ERROR, TAG, "OCStack resource error");
} }
OIC_LOG(INFO, TAG, "OUT PostProvisioningStatus"); OIC_LOG_V(INFO, TAG, "OUT %s", __func__);
return ret; return ret;
} }
...@@ -2500,7 +2521,6 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx) ...@@ -2500,7 +2521,6 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
return OC_STACK_INVALID_PARAM; return OC_STACK_INVALID_PARAM;
} }
// TODO [IOT-1763] put RFPRO and other pstat.dos.s updates in the right places.
otmCtx->selectedDeviceInfo->pstat->dos.state = DOS_RFNOP; otmCtx->selectedDeviceInfo->pstat->dos.state = DOS_RFNOP;
OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload)); OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
...@@ -2510,8 +2530,13 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx) ...@@ -2510,8 +2530,13 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
secPayload->base.type = PAYLOAD_TYPE_SECURITY; secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize, true)) bool propertiesToInclude[PSTAT_PROPERTY_COUNT];
memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
propertiesToInclude[PSTAT_DOS] = true;
if (OC_STACK_OK != PstatToCBORPayloadPartial(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize, propertiesToInclude))
{ {
OCPayloadDestroy((OCPayload *)secPayload); OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON; return OC_STACK_INVALID_JSON;
......
...@@ -791,7 +791,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k ...@@ -791,7 +791,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k
OIC_LOG(INFO, TAG, "SRPProvisionCredentials: NULL Callback"); OIC_LOG(INFO, TAG, "SRPProvisionCredentials: NULL Callback");
return OC_STACK_INVALID_CALLBACK; return OC_STACK_INVALID_CALLBACK;
} }
if ((SYMMETRIC_PAIR_WISE_KEY == type) && if ((SYMMETRIC_PAIR_WISE_KEY == type) &&
(NULL != pDev2) && (NULL != pDev2) &&
(0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))) (0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t))))
{ {
...@@ -2534,6 +2534,8 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, ...@@ -2534,6 +2534,8 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
pstat->dos.state = DOS_RESET; // Note [IOT-2052] in OCF 1.0 this is the only
// value that needs to be set to cause RESET
pstat->cm = RESET; pstat->cm = RESET;
pstat->isOp = false; pstat->isOp = false;
pstat->tm = TAKE_OWNER; pstat->tm = TAKE_OWNER;
...@@ -2557,8 +2559,16 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, ...@@ -2557,8 +2559,16 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
} }
secPayload->base.type = PAYLOAD_TYPE_SECURITY; secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(pstat, &(secPayload->securityData), // Note [IOT-2052] all the POST payloads in the provisioningclient app
&(secPayload->payloadSize), true)) // should be updated to use the Partial payload APIs for the SVRs, so they
// do not include read-only Properties for the Server device current
// state.
bool propertiesToInclude[PSTAT_PROPERTY_COUNT];
memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
propertiesToInclude[PSTAT_DOS] = true;
if (OC_STACK_OK != PstatToCBORPayloadPartial(pstat, &(secPayload->securityData),
&(secPayload->payloadSize), propertiesToInclude))
{ {
OCPayloadDestroy((OCPayload *) secPayload); OCPayloadDestroy((OCPayload *) secPayload);
OIC_LOG(ERROR, TAG, "Failed to PstatToCBORPayload"); OIC_LOG(ERROR, TAG, "Failed to PstatToCBORPayload");
......
This diff is collapsed.
...@@ -145,7 +145,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName ...@@ -145,7 +145,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName
{ {
OicSecPstat_t *pstat = JSONToPstatBin(jsonStr); OicSecPstat_t *pstat = JSONToPstatBin(jsonStr);
VERIFY_NOT_NULL(TAG, pstat, FATAL); VERIFY_NOT_NULL(TAG, pstat, FATAL);
ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize, false); ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize);
if(OC_STACK_OK != ret) if(OC_STACK_OK != ret)
{ {
OIC_LOG (ERROR, TAG, "Failed converting Pstat to Cbor Payload"); OIC_LOG (ERROR, TAG, "Failed converting Pstat to Cbor Payload");
......
...@@ -75,7 +75,16 @@ TEST(PstatResourceTest, PstatEntityHandlerWithPostRequest) ...@@ -75,7 +75,16 @@ TEST(PstatResourceTest, PstatEntityHandlerWithPostRequest)
defaultPstat->sm[0] = 3; defaultPstat->sm[0] = 3;
size_t size = 0; size_t size = 0;
uint8_t *cbor = NULL; uint8_t *cbor = NULL;
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(defaultPstat, &cbor, &size, true)); bool propertiesToInclude[PSTAT_PROPERTY_COUNT] = {
true, // dos
false, // isop
false, // cm
true, // tm
false, // om
true, // sm
true // rowneruuid
};
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayloadPartial(defaultPstat, &cbor, &size, propertiesToInclude));
DeletePstatBinData(defaultPstat); DeletePstatBinData(defaultPstat);
ASSERT_TRUE(cbor != NULL); ASSERT_TRUE(cbor != NULL);
...@@ -94,20 +103,20 @@ TEST(PstatResourceTest, PstatEntityHandlerInvalidRequest) ...@@ -94,20 +103,20 @@ TEST(PstatResourceTest, PstatEntityHandlerInvalidRequest)
TEST(PstatResourceTest, PstatToCBORPayloadNULL) TEST(PstatResourceTest, PstatToCBORPayloadNULL)
{ {
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, NULL, 0, false)); EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, NULL, 0));
// Case when cbor payload is NULL // Case when cbor payload is NULL
OicSecPstat_t pstat; OicSecPstat_t pstat;
size_t size = 10; size_t size = 10;
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, NULL, &size, false)); EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, NULL, &size));
uint8_t *cborPayload = (uint8_t *) OICCalloc(1, size); uint8_t *cborPayload = (uint8_t *) OICCalloc(1, size);
ASSERT_TRUE(NULL != cborPayload); ASSERT_TRUE(NULL != cborPayload);
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, &size, false)); EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, &size));
OICFree(cborPayload); OICFree(cborPayload);
cborPayload = NULL; cborPayload = NULL;
// Case when pstat is zero. // Case when pstat is zero.
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, &cborPayload, &size, false)); EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, &cborPayload, &size));
// Case when size is 0. // Case when size is 0.
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, 0, false)); EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, 0));
OICFree(cborPayload); OICFree(cborPayload);
} }
...@@ -133,7 +142,7 @@ TEST(PstatResourceTest, PstatToCBORPayloadAndCBORPayloadToPstat) ...@@ -133,7 +142,7 @@ TEST(PstatResourceTest, PstatToCBORPayloadAndCBORPayloadToPstat)
size_t size = 0; size_t size = 0;
uint8_t *cbor = NULL; uint8_t *cbor = NULL;
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(&pstat, &cbor, &size, false)); EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(&pstat, &cbor, &size));
if (!cbor) if (!cbor)
{ {
OICFree(pstat.sm); OICFree(pstat.sm);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment