CASA/c_test/unx_testcases/cache_ss_fns.c
2005-10-11 19:51:00 +00:00

392 lines
10 KiB
C

/* This file contains all the test cases for all the generic
* Cachelib functions.
*/
#include "testcases.h"
/* Callback for testing CacheOpenSecretStore.
*/
void TestCacheOpenSecretStore_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
uint32_t ssFlags = 0;
int32_t retVal = 0;
/* sscs_CacheOpenSecretStore_Valid */
DECORATE
printf("INPUT: {0x00040000, SecretStore}\n");
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID,ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
/* sscs_CacheOpenSecretStore_Valid */
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheOpenSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestCacheOpenSecretStore_Invalid_Input(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
/* sscs_CacheOpenSecretStore_Invalid */
DECORATE
printf("INPUT: {0x00000000, A}\n");
secID.version = 0x00000000;
strcpy((char *)secID.ssName,"A");
ssHandle = sscs_CacheOpenSecretStore(&secID,ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
retVal = sscs_CacheCloseSecretStore(ssHandle,ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheOpenSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestCacheCloseSecretStore_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE
printf("INPUT: {0x00040000, SecretStore}\n");
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
printf("INPUT: Valid SSHandle\n");
retVal = sscs_CacheCloseSecretStore(ssHandle,ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
else
{
printf("sscs_CacheCloseSecretStore succeeded.\n");
}
DECORATE;
}
void TestCacheCloseSecretStore_CloseAfterClose(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE
printf("INPUT: {0x00040000, SecretStore}\n");
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
printf("INPUT: Valid SSHandle\n");
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags,NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
/* Closing SecretStore after a valid close.
* Cachelib must return an appropriate error and must
* not write the request to SSCS.
*/
printf("INPUT: Valid SSHandle\n");
printf("Closing SecretStore after a valid close.\n");
retVal = sscs_CacheCloseSecretStore(ssHandle,ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
DECORATE
}
void TestCacheCloseSecretStore_Invalid_Handle(void)
{
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE
/* Passing a NULL SSHandle */
printf("INPUT: Invalid SSHandle\n");
ssHandle = NULL;
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestCacheCloseSecretStore_WithoutOpen(void)
{
SSCS_SECRETSTORE_HANDLE_T ssHandle;
int32_t retVal = 0;
int socketFd = FAKE_SOCK_FD;
uint32_t ssFlags = 0;
DECORATE
/* Passing a cookedup SSHandle */
printf("INPUT: Cookedup SSHandle\n");
ssHandle.platformID = 1;
ssHandle.platHandle = (int*)&socketFd;
retVal = sscs_CacheCloseSecretStore(&ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
}
void TestCacheGetSecretStoreInfo_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
SSCS_SECRETSTORE_INFO_T ssInfo;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE;
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
retVal = sscs_CacheGetSecretStoreInfo( ssHandle, ssFlags, &ssInfo, NULL);
if(retVal != 0)
{
printf("sscs_CacheGetSecretStoreInfo failed: %d\n",retVal);
}
else
{
printf("ssInfo.numKeychains :%d\n",ssInfo.numKeyChains);
printf("ssInfo.enumBufsize :%d\n",ssInfo.enumBufsize);
}
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestCacheGetKeychainInfo_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
SSCS_KEYCHAIN_INFO_T kcInfo;
SSCS_KEYCHAIN_ID_T keychainID;
memset(&keychainID,0,sizeof(keychainID));
strcpy(keychainID.keychainID,"MyKeychain");
keychainID.len = strlen("MyKeychain") + 1;
uint32_t ssFlags = 0;
int32_t retVal = 0;
DECORATE;
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
printf("Adding %S\n",keychainID.keychainID);
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
if(retVal != 0)
{
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
}
retVal = sscs_CacheGetKeychainInfo(ssHandle, ssFlags, &keychainID, &kcInfo, NULL);
if(retVal != 0)
{
printf("sscs_CacheGetKeychainInfo failed: %d\n",retVal);
}
else
{
printf("kcInfo.numSecrets:%d\n",kcInfo.numSecrets);
}
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestLockCache_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE;
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
retVal = sscs_LockCache(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_LockCache failed: %d\n",retVal);
}
else
{
printf("LockCache Successful\n");
}
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
DECORATE;
}
void TestUnlockCache_Valid(void)
{
SSCS_SECRETSTORE_T secID;
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
int32_t retVal = 0;
uint32_t ssFlags = 0;
DECORATE;
secID.version = 0x00040000;
strcpy((char *)secID.ssName,"SecretStore");
ssHandle = sscs_CacheOpenSecretStore(&secID,ssFlags, NULL);
if(!ssHandle)
{
printf("sscs_CacheOpenSecretStore failed\n");
}
else
{
printf("sscs_CacheOpenSecretStore succeeded\n");
}
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
*(int*)ssHandle->platHandle);
retVal = sscs_UnlockCache(ssHandle,ssFlags, NULL, NULL);
if(retVal != 0)
{
printf("sscs_UnlockCache failed: %d\n",retVal);
}
else
{
printf("sscs_UnlockCache Successful\n");
}
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
if(retVal != 0)
{
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
}
DECORATE;
}