CASA/c_test/unx_testcases/cache_ss_fns.c
2006-01-31 22:01:47 +00:00

413 lines
11 KiB
C

/***********************************************************************
*
* Copyright (C) 2005-2006 Novell, Inc. Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
***********************************************************************/
/* 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;
}