Skip to content

Commit

Permalink
Add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chinglee-iot committed May 16, 2024
1 parent 2104309 commit b0e2fbf
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/wrapper_utest/core_pkcs11_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,3 +947,63 @@ void test_IotPkcs11_xFindObjectWithLabelAndClassBadFunctionList( void )

TEST_ASSERT_EQUAL( CKR_FUNCTION_FAILED, xResult );
}

/*!
* @brief xFindObjectWithLabelAndClass no C_FindObjectsInit.
*
*/
void test_IotPkcs11_xFindObjectWithLabelAndClassNoC_FindObjectsInit( void )
{
CK_RV xResult = CKR_OK;
CK_SESSION_HANDLE xHandle = { 0 };
CK_OBJECT_HANDLE xPrivateKeyHandle = { 0 };

vCommonStubs();
prvP11FunctionList.C_FindObjectsInit = NULL;
xResult = xFindObjectWithLabelAndClass( xHandle,
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
strlen( pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS ),
CKO_PRIVATE_KEY, &xPrivateKeyHandle );
prvP11FunctionList.C_FindObjectsInit = C_FindObjectsInit;
TEST_ASSERT_EQUAL( CKR_FUNCTION_FAILED, xResult );
}

/*!
* @brief xFindObjectWithLabelAndClass no C_FindObjects.
*
*/
void test_IotPkcs11_xFindObjectWithLabelAndClassNoC_FindObjects( void )
{
CK_RV xResult = CKR_OK;
CK_SESSION_HANDLE xHandle = { 0 };
CK_OBJECT_HANDLE xPrivateKeyHandle = { 0 };

vCommonStubs();
prvP11FunctionList.C_FindObjects = NULL;
xResult = xFindObjectWithLabelAndClass( xHandle,
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
strlen( pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS ),
CKO_PRIVATE_KEY, &xPrivateKeyHandle );
prvP11FunctionList.C_FindObjects = C_FindObjects;
TEST_ASSERT_EQUAL( CKR_FUNCTION_FAILED, xResult );
}

/*!
* @brief xFindObjectWithLabelAndClass no C_FindObjectsFinal.
*
*/
void test_IotPkcs11_xFindObjectWithLabelAndClassNoC_FindObjectsFinal( void )
{
CK_RV xResult = CKR_OK;
CK_SESSION_HANDLE xHandle = { 0 };
CK_OBJECT_HANDLE xPrivateKeyHandle = { 0 };

vCommonStubs();
prvP11FunctionList.C_FindObjectsFinal = NULL;
xResult = xFindObjectWithLabelAndClass( xHandle,
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
strlen( pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS ),
CKO_PRIVATE_KEY, &xPrivateKeyHandle );
prvP11FunctionList.C_FindObjectsFinal = C_FindObjectsFinal;
TEST_ASSERT_EQUAL( CKR_FUNCTION_FAILED, xResult );
}

0 comments on commit b0e2fbf

Please sign in to comment.