SCRIPT_NAME = test_ccapi.sh
-_OBJECTS = test_ccapi_ccache test_ccapi_check test_ccapi_constants test_ccapi_context test_ccapi_globals test_ccapi_iterators test_ccapi_log test_ccapi_util
+_OBJECTS = test_ccapi_ccache \
+ test_ccapi_check \
+ test_ccapi_constants \
+ test_ccapi_context \
+ test_ccapi_globals \
+ test_ccapi_iterators \
+ test_ccapi_log \
+ test_ccapi_util \
+ test_ccapi_v2
OBJECTS = $(patsubst %,$(OBJDIR)/%.o,$(_OBJECTS))
-TEST_NAMES = test_constants test_cc_initialize test_cc_context_release test_cc_context_get_change_time test_cc_context_get_default_ccache_name test_cc_context_open_ccache test_cc_context_open_default_ccache test_cc_context_create_ccache test_cc_context_create_default_ccache test_cc_context_create_new_ccache test_cc_context_new_ccache_iterator test_cc_context_compare test_cc_ccache_release test_cc_ccache_destroy test_cc_ccache_set_default test_cc_ccache_get_credentials_version test_cc_ccache_get_name test_cc_ccache_get_principal test_cc_ccache_set_principal test_cc_ccache_store_credentials test_cc_ccache_remove_credentials test_cc_ccache_new_credentials_iterator test_cc_ccache_get_change_time test_cc_ccache_get_last_default_time test_cc_ccache_move test_cc_ccache_compare test_cc_ccache_get_kdc_time_offset test_cc_ccache_set_kdc_time_offset test_cc_ccache_clear_kdc_time_offset test_cc_ccache_iterator_next test_cc_credentials_iterator_next
+TEST_NAMES = test_constants \
+ test_cc_initialize \
+ test_cc_context_release \
+ test_cc_context_get_change_time \
+ test_cc_context_get_default_ccache_name \
+ test_cc_context_open_ccache \
+ test_cc_context_open_default_ccache \
+ test_cc_context_create_ccache \
+ test_cc_context_create_default_ccache \
+ test_cc_context_create_new_ccache \
+ test_cc_context_new_ccache_iterator \
+ test_cc_context_compare \
+ test_cc_ccache_release \
+ test_cc_ccache_destroy \
+ test_cc_ccache_set_default \
+ test_cc_ccache_get_credentials_version \
+ test_cc_ccache_get_name \
+ test_cc_ccache_get_principal \
+ test_cc_ccache_set_principal \
+ test_cc_ccache_store_credentials \
+ test_cc_ccache_remove_credentials \
+ test_cc_ccache_new_credentials_iterator \
+ test_cc_ccache_get_change_time \
+ test_cc_ccache_get_last_default_time \
+ test_cc_ccache_move \
+ test_cc_ccache_compare \
+ test_cc_ccache_get_kdc_time_offset \
+ test_cc_ccache_set_kdc_time_offset \
+ test_cc_ccache_clear_kdc_time_offset \
+ test_cc_ccache_iterator_next \
+ test_cc_credentials_iterator_next\
+ test_cc_shutdown \
+ test_cc_get_change_time \
+ test_cc_open \
+ test_cc_create \
+ test_cc_close \
+ test_cc_destroy \
+ test_cc_get_cred_version \
+ test_cc_get_name \
+ test_cc_get_principal \
+ test_cc_set_principal \
+ test_cc_store \
+ test_cc_remove_cred \
+ test_cc_seq_fetch_NCs_begin \
+ test_cc_seq_fetch_NCs_next \
+ test_cc_seq_fetch_creds_begin \
+ test_cc_seq_fetch_creds_next \
+ test_cc_get_NC_info
+
TEST_OBJECTS = $(patsubst %,$(OBJDIR)/%.o,$(TEST_NAMES))
$(CC) -o $(TESTDIR)/$@ $(OBJDIR)/$@.o $(OBJECTS) $(LIBS)
simple_lock_test:
- $(CC) -o $(TESTDIR)/simple_lock_test simple_lock_test.c $(LIBS)
+ $(CC) -o $(TESTDIR)/simple_lock_test simple_lock_test.c test_ccapi_log.c $(LIBS)
copy-script:
cp $(SCRIPT_NAME) $(DSTDIR)/$(SCRIPT_NAME)
$(OUTPRE)test_ccapi_check.$(OBJEXT) \
$(OUTPRE)test_ccapi_constants.$(OBJEXT) \
$(OUTPRE)test_ccapi_context.$(OBJEXT) \
+ $(OUTPRE)test_ccapi_v2.$(OBJEXT) \
$(OUTPRE)test_ccapi_globals.$(OBJEXT) \
$(OUTPRE)test_ccapi_iterators.$(OBJEXT) \
$(OUTPRE)test_ccapi_log.$(OBJEXT) \
TEST_NAMES = test_cc_ccache_iterator_next \
test_constants \
test_cc_initialize \
- test_cc_context_get_version \
test_cc_credentials_iterator_next
MORE_TESTS = test_cc_context_release \
test_cc_ccache_compare \
test_cc_ccache_get_kdc_time_offset \
test_cc_ccache_set_kdc_time_offset \
- test_cc_ccache_clear_kdc_time_offset
+ test_cc_ccache_clear_kdc_time_offset \
+ test_cc_shutdown \
+ test_cc_get_change_time \
+ test_cc_open \
+ test_cc_create \
+ test_cc_close \
+ test_cc_destroy \
+ test_cc_get_cred_version \
+ test_cc_get_name \
+ test_cc_get_principal \
+ test_cc_set_principal \
+ test_cc_store \
+ test_cc_remove_cred \
+ test_cc_seq_fetch_NCs_begin \
+ test_cc_seq_fetch_NCs_next \
+ test_cc_seq_fetch_creds_begin \
+ test_cc_seq_fetch_creds_next \
+ test_cc_get_NC_info
+
##### Linker
LINK = link
err = check_cc_set_principal();
err = check_cc_store();
err = check_cc_remove_cred();
- //err = check_cc_seq_fetch_NCs_begin();
- //err = check_cc_seq_fetch_NCs_next();
- //err = check_cc_seq_fetch_creds_begin();
- //err = check_cc_seq_fetch_creds_next();
- //err = check_cc_get_NC_info();
+ err = check_cc_seq_fetch_NCs_begin();
+ err = check_cc_seq_fetch_NCs_next();
+ err = check_cc_seq_fetch_creds_begin();
+ err = check_cc_seq_fetch_creds_next();
+ err = check_cc_get_NC_info();
err = check_constants();
#include <stdio.h>
#include <stdarg.h>
-#include "cci_debugging.h"
+#include "test_ccapi_log.h"
+
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
+#include <TargetConditionals.h>
+#endif
#ifdef TARGET_OS_MAC
#include <stdlib.h>
+#include <pthread.h>
#include <Kerberos/CredentialsCache.h>
#else
#include "CredentialsCache.h"
#endif
-void * other_thread (void) {
+void *other_thread (void) {
cc_int32 err;
cc_context_t context = NULL;
err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
- cci_debug_printf("thread: attempting lock. may hang. err == %d", err);
+ log_error("thread: attempting lock. may hang. err == %d", err);
if (!err) {
// hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately
err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
- }
+ }
if (context) {
cc_context_unlock(context);
cc_context_release(context);
context = NULL;
- }
- cci_debug_printf("thread: return. err == %d", err);
}
+ log_error("thread: return. err == %d", err);
+}
int main (int argc, char *argv[]) {
err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
if (!err) {
err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
- }
+ }
- cci_debug_printf("main: initialized and read locked context. err == %d", err);
+ log_error("main: initialized and read locked context. err == %d", err);
#ifdef TARGET_OS_MAC
status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);
if (status != 0) {
- cci_debug_printf("Create error!");
+ log_error("pthread_create() returned %d", status);
exit(-1);
}
#endif
- cci_debug_printf("main: unlocking and releasing context. err == %d", err);
+ log_error("main: unlocking and releasing context. err == %d", err);
if (context) {
- cci_debug_printf("main: calling cc_context_unlock");
+ log_error("main: calling cc_context_unlock");
cc_context_unlock(context);
- cci_debug_printf("main: calling cc_context_release");
+ log_error("main: calling cc_context_release");
cc_context_release(context);
context = NULL;
- }
+ }
- cci_debug_printf("main: return. err == %d", err);
+ log_error("main: return. err == %d", err);
- UNREFERENCED_PARAMETER(status); // no whining!
+#if defined(_WIN32)
+ UNREFERENCED_PARAMETER(status); // no whining!
+#endif
return 0;
- }
\ No newline at end of file
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_close();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_create();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_destroy();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_get_NC_info();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_get_change_time();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_get_cred_version();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_get_name();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_get_principal();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_open();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_remove_cred();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_seq_fetch_NCs_begin();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_seq_fetch_NCs_next();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_seq_fetch_creds_begin();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_seq_fetch_creds_next();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_set_principal();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_shutdown();
+ return err;
+}
--- /dev/null
+#include <stdio.h>
+#include <limits.h>
+
+#include "test_ccapi_check.h"
+#include "test_ccapi_constants.h"
+#include "test_ccapi_v2.h"
+
+int main (int argc, const char * argv[]) {
+
+ cc_int32 err = ccNoError;
+ T_CCAPI_INIT;
+ err = check_cc_store();
+ return err;
+}
run_test test_cc_credentials_iterator_next
+run_test test_cc_shutdown
+run_test test_cc_get_change_time
+run_test test_cc_open
+run_test test_cc_create
+run_test test_cc_close
+run_test test_cc_destroy
+run_test test_cc_get_cred_version
+run_test test_cc_get_name
+run_test test_cc_get_principal
+run_test test_cc_set_principal
+run_test test_cc_store
+run_test test_cc_remove_cred
+run_test test_cc_seq_fetch_NCs_begin
+run_test test_cc_seq_fetch_NCs_next
+run_test test_cc_seq_fetch_creds_begin
+run_test test_cc_seq_fetch_creds_next
+run_test test_cc_get_NC_info
+
printf "\nFinished testing CCAPI. $failure_count failures in total.\n"
exit 0
\ No newline at end of file
// ---------------------------------------------------------------------------
-int check_cc_ccache_destroy() {
+int check_cc_ccache_destroy(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_set_default() {
+int check_cc_ccache_set_default(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_credentials_version() {
+int check_cc_ccache_get_credentials_version(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_name() {
+int check_cc_ccache_get_name(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_principal() {
+int check_cc_ccache_get_principal(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_set_principal() {
+int check_cc_ccache_set_principal(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_store_credentials() {
+int check_cc_ccache_store_credentials(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_remove_credentials() {
+int check_cc_ccache_remove_credentials(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_new_credentials_iterator() {
+int check_cc_ccache_new_credentials_iterator(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_change_time() {
+int check_cc_ccache_get_change_time(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t dummy_ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_last_default_time() {
+int check_cc_ccache_get_last_default_time(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache_1 = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_move() {
+int check_cc_ccache_move(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t source = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_compare() {
+int check_cc_ccache_compare(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache_a = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_get_kdc_time_offset() {
+int check_cc_ccache_get_kdc_time_offset(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_set_kdc_time_offset() {
+int check_cc_ccache_set_kdc_time_offset(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
// ---------------------------------------------------------------------------
-int check_cc_ccache_clear_kdc_time_offset() {
+int check_cc_ccache_clear_kdc_time_offset(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
#include <krb5.h> // gets us TARGET_OS_MAC
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
+#include <TargetConditionals.h>
+#endif
+
#ifdef TARGET_OS_MAC
#include <Kerberos/CredentialsCache.h>
#else
#include "test_ccapi_iterators.h"
#include "test_ccapi_check.h"
#include "test_ccapi_util.h"
-#include "cci_debugging.h"
-
// ---------------------------------------------------------------------------
-int check_cc_ccache_iterator_next() {
+int check_cc_ccache_iterator_next(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
}
for(i = 0; !err && (i < 1000); i++)
{
- if (i%10 == 0) cci_debug_printf("%s loop: %d", __FUNCTION__, i);
+ if (i%100 == 0) fprintf(stdout, ".");
err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
if (ccache) {
cc_ccache_release(ccache);
// ---------------------------------------------------------------------------
-int check_cc_credentials_iterator_next() {
+int check_cc_credentials_iterator_next(void) {
cc_int32 err = 0;
cc_context_t context = NULL;
cc_ccache_t ccache = NULL;
err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
}
for(i = 0; !err && (i < 1000); i++) {
- if (i%10 == 0) cci_debug_printf("%s loop: %d", __FUNCTION__, i);
- new_v5_creds_union(&creds_union, "BAR.ORG");
+ if (i%100 == 0) fprintf(stdout, ".");
+ new_v5_creds_union(&creds_union, "BAR.ORG");
err = cc_ccache_store_credentials(ccache, &creds_union);
release_v5_creds_union(&creds_union);
}
_log_error(__FILE__, __LINE__, format , ## __VA_ARGS__)
void _log_error_v(const char *file, int line, const char *format, va_list ap);
-// void _log_error(const char *file, int line, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
-void _log_error(const char *file, int line, const char *format, ...);
-
+void _log_error(const char *file, int line, const char *format, ...)
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+__attribute__ ((__format__ (__printf__, 3, 4)))
+#endif
+;
void test_header(const char *msg);
void test_footer(const char *msg, int err);
#include <stdarg.h>
#include <stdlib.h>
-#include "k5-platform.h"
#include "test_ccapi_util.h"
// ---------------------------------------------------------------------------
static cc_result destroy_all_ccaches_v2(apiCB *context) {
- cc_result err = ccNoError;
+ cc_result err = CC_NOERROR;
infoNC **info = NULL;
int i = 0;
if (!err) {
v5creds = malloc (sizeof (*v5creds));
if (!v5creds) {
- err = ccErrNoMem;
+ err = CC_NOMEM;
}
}
asprintf(&client, "client@%s", realm);
asprintf(&server, "host/%d%s@%s", num_runs++, realm, realm);
if (!client || !server) {
- err = ccErrNoMem;
+ err = CC_NOMEM;
}
}
creds_union->cred_type = CC_CRED_V5;
creds_union->cred.pV5Cred = v5creds;
} else {
- err = ccErrNoMem;
+ err = CC_NOMEM;
}
}
if (!err) {
check_once_cc_get_change_time(context, &last_change_time, CC_NOERROR, "after creating a new ccache");
if (!err) {
- // change principal (fails with ccErrBadInternalMessage)
+ // change principal
err = cc_set_principal(context, ccache, CC_CRED_V5, "foo@BAR.ORG");
if (err) {
log_error("failed to change ccache's principal - %s (%d)", translate_ccapi_error(err), err);
if (creds) { cc_free_creds(context, &creds); }
}
- if (err == ccIteratorEnd) {
+ if (err == CC_END) {
check_if(found, "stored credentials not found in ccache");
- err = ccNoError;
+ err = CC_NOERROR;
}
if (iterator) { cc_seq_fetch_creds_end(context, &iterator); }
creds_array[i] = NULL;
err = cc_seq_fetch_creds_next(context, &creds_array[i], iterator);
}
- if (err == ccIteratorEnd) { err = ccNoError; }
+ if (err == CC_END) { err = CC_NOERROR; }
// remove 10 valid creds
for (i = 0; !err && (i < 10); i++) {
if (creds) { cc_free_creds(context, &creds); }
}
- if (err == ccIteratorEnd) {
- check_if(!found, "credentials not removed from ccache");
- err = ccNoError;
+ if (err == CC_END) {
+ check_if(found, "credentials not removed from ccache");
+ err = CC_NOERROR;
}
if (iterator) { cc_seq_fetch_creds_end(context, &iterator); }
return err;
}
+
+// ---------------------------------------------------------------------------
+
+int check_cc_seq_fetch_NCs_begin(void) {
+ cc_result err = 0;
+ apiCB *context = NULL;
+ ccache_p *ccache = NULL;
+ ccache_cit *iterator = NULL;
+
+ BEGIN_TEST("cc_seq_fetch_NCs_begin");
+
+ err = cc_initialize(&context, ccapi_version_2, NULL, NULL);
+ if (!err) {
+ err = destroy_all_ccaches_v2(context);
+ }
+ if (!err) {
+ // try making when there are no existing ccaches (shouldn't make a difference, but just in case)
+ check_once_cc_seq_fetch_NCs_begin(context, &iterator, CC_NOERROR, "when there are no existing ccaches");
+
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_NCS_BEGIN", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ if (!err) {
+ // try making when at least one ccache already exists (just to cover all our bases)
+ check_once_cc_seq_fetch_NCs_begin(context, &iterator, CC_NOERROR, "when at least one ccache already exists");
+
+ // try bad parameters
+ check_once_cc_seq_fetch_NCs_begin(context, NULL, CC_BAD_PARM, "NULL param"); // NULL iterator
+ }
+ // we'll do a comprehensive test of cc_ccache_iterator related functions later in the test suite
+
+ if (ccache ) { cc_close(context, &ccache); }
+ if (context) { cc_shutdown(&context); }
+
+ END_TEST_AND_RETURN
+}
+
+// ---------------------------------------------------------------------------
+
+cc_result check_once_cc_seq_fetch_NCs_begin(apiCB *context, ccache_cit **iterator, cc_result expected_err, const char *description) {
+ cc_result err = CC_NOERROR;
+
+ cc_result possible_return_values[4] = {
+ CC_NOERROR,
+ CC_BAD_PARM,
+ CC_NOMEM,
+ CC_NO_EXIST
+ };
+
+ BEGIN_CHECK_ONCE(description);
+
+#define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
+
+ err = cc_seq_fetch_NCs_begin(context, iterator);
+
+ // check returned error
+ check_err(err, expected_err, possible_return_values);
+
+ // we'll do a comprehensive test of cc_ccache_iterator related functions later
+
+ return err;
+}
+
+// ---------------------------------------------------------------------------
+
+int check_cc_seq_fetch_NCs_next(void) {
+ cc_result err = 0;
+ apiCB *context = NULL;
+ ccache_p *ccache = NULL;
+ ccache_cit *iterator = NULL;
+ unsigned int i;
+
+ BEGIN_TEST("cc_seq_fetch_NCs_next");
+
+ err = cc_initialize(&context, ccapi_version_2, NULL, NULL);
+
+ if (!err) {
+ err = destroy_all_ccaches_v2(context);
+ }
+
+ // iterate with no ccaches
+ if (!err) {
+ err = cc_seq_fetch_NCs_begin(context, &iterator);
+ }
+ check_once_cc_seq_fetch_NCs_next(context, iterator, 0, CC_NOERROR, "iterating over an empty collection");
+ if (iterator) {
+ cc_seq_fetch_creds_end(context, &iterator);
+ iterator = NULL;
+ }
+
+ // iterate with one ccache
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_NCS_NEXT", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+ if (!err) {
+ err = cc_seq_fetch_NCs_begin(context, &iterator);
+ }
+ check_once_cc_seq_fetch_NCs_next(context, iterator, 1, CC_NOERROR, "iterating over a collection of 1 ccache");
+ if (iterator) {
+ cc_seq_fetch_creds_end(context, &iterator);
+ iterator = NULL;
+ }
+
+ // iterate with several ccaches
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ }
+ for(i = 0; !err && (i < 1000); i++)
+ {
+ char *name = NULL;
+
+ if (i%100 == 0) fprintf(stdout, ".");
+ asprintf (&name, "TEST_CC_SEQ_FETCH_NCS_NEXT_%d", i);
+ err = cc_create(context, name, "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+ free (name);
+ }
+ if (!err) {
+ err = cc_seq_fetch_NCs_begin(context, &iterator);
+ }
+ check_once_cc_seq_fetch_NCs_next(context, iterator, 1000, CC_NOERROR, "iterating over a collection of 1000 ccache");
+ if (iterator) {
+ cc_seq_fetch_creds_end(context, &iterator);
+ iterator = NULL;
+ }
+
+
+ if (ccache) { cc_close(context, &ccache); }
+ if (iterator) { cc_seq_fetch_creds_end(context, &iterator); }
+ if (context) {
+ destroy_all_ccaches_v2(context);
+ cc_shutdown(&context);
+ }
+
+ END_TEST_AND_RETURN
+}
+
+// ---------------------------------------------------------------------------
+
+cc_result check_once_cc_seq_fetch_NCs_next(apiCB *context, ccache_cit *iterator, cc_uint32 expected_count, cc_result expected_err, const char *description) {
+ cc_result err = CC_NOERROR;
+
+ BEGIN_CHECK_ONCE(description);
+
+ cc_result possible_return_values[5] = {
+ CC_NOERROR,
+ CC_END,
+ CC_BAD_PARM,
+ CC_NOMEM,
+ CC_NO_EXIST
+ };
+#define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
+
+ ccache_p *ccache = NULL;
+ cc_uint32 actual_count = 0;
+
+ while (!err) {
+ err = cc_seq_fetch_NCs_next(context, &ccache, iterator);
+ if (ccache) {
+ actual_count++;
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+ }
+ if (err == CC_END) {
+ err = CC_NOERROR;
+ }
+
+ // check returned error
+ check_err(err, expected_err, possible_return_values);
+
+ check_if(actual_count != expected_count, "iterator didn't iterate over all ccaches");
+
+ END_CHECK_ONCE;
+
+ return err;
+}
+
+// ---------------------------------------------------------------------------
+
+int check_cc_get_NC_info(void) {
+ cc_result err = 0;
+ apiCB *context = NULL;
+ ccache_p *ccache = NULL;
+ unsigned int i;
+
+ BEGIN_TEST("cc_get_NC_info");
+
+ err = cc_initialize(&context, ccapi_version_2, NULL, NULL);
+
+ if (!err) {
+ err = destroy_all_ccaches_v2(context);
+ }
+
+ // iterate with no ccaches
+ check_once_cc_get_NC_info(context, "", "", CC_CRED_MAX, 0, CC_NOERROR, "iterating over an empty collection");
+
+ // iterate with one ccache
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ err = cc_create(context, "TEST_CC_GET_NC_INFO", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+ check_once_cc_get_NC_info(context, "TEST_CC_GET_NC_INFO", "foo@BAR.ORG", CC_CRED_V5, 1, CC_NOERROR, "iterating over a collection of 1 ccache");
+
+ // iterate with several ccaches
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ }
+ for(i = 0; !err && (i < 1000); i++)
+ {
+ char *name = NULL;
+
+ if (i%100 == 0) fprintf(stdout, ".");
+ asprintf (&name, "TEST_CC_GET_NC_INFO_%d", i);
+ err = cc_create(context, name, "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+ free (name);
+ }
+ check_once_cc_get_NC_info(context, "TEST_CC_GET_NC_INFO", "foo@BAR.ORG", CC_CRED_V5, 1000, CC_NOERROR, "iterating over a collection of 1000 ccache");
+
+ if (ccache) { cc_close(context, &ccache); }
+ if (context) {
+ destroy_all_ccaches_v2(context);
+ cc_shutdown(&context);
+ }
+
+ END_TEST_AND_RETURN
+}
+
+// ---------------------------------------------------------------------------
+
+cc_result check_once_cc_get_NC_info(apiCB *context,
+ const char *expected_name_prefix,
+ const char *expected_principal,
+ cc_int32 expected_version,
+ cc_uint32 expected_count,
+ cc_result expected_err,
+ const char *description) {
+ cc_result err = CC_NOERROR;
+ infoNC **info = NULL;
+
+ BEGIN_CHECK_ONCE(description);
+
+ cc_result possible_return_values[4] = {
+ CC_NOERROR,
+ CC_BAD_PARM,
+ CC_NOMEM,
+ CC_NO_EXIST
+ };
+#define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
+
+ cc_uint32 actual_count = 0;
+
+ err = cc_get_NC_info(context, &info);
+
+ for (actual_count = 0; !err && info[actual_count]; actual_count++) {
+ check_if(strncmp(info[actual_count]->name, expected_name_prefix, strlen(expected_name_prefix)), "got incorrect ccache name");
+ check_if(strcmp(info[actual_count]->principal, expected_principal), "got incorrect principal name");
+ check_if(info[actual_count]->vers != expected_version, "got incorrect cred version");
+ }
+
+ // check returned error
+ check_err(err, expected_err, possible_return_values);
+
+ check_if(actual_count != expected_count, "NC info didn't list all ccaches");
+
+ if (info) { cc_free_NC_info (context, &info); }
+ END_CHECK_ONCE;
+
+ return err;
+}
+
+// ---------------------------------------------------------------------------
+
+int check_cc_seq_fetch_creds_begin(void) {
+ cc_result err = 0;
+ apiCB *context = NULL;
+ ccache_p *ccache = NULL;
+ ccache_p *dup_ccache = NULL;
+ ccache_cit *creds_iterator = NULL;
+ char *name = NULL;
+
+ BEGIN_TEST("cc_seq_fetch_creds_begin");
+
+ err = cc_initialize(&context, ccapi_version_2, NULL, NULL);
+
+ if (!err) {
+ err = destroy_all_ccaches_v2(context);
+ }
+
+ if (!err) {
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_CREDS_BEGIN", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+
+ // valid params
+ if (!err) {
+ check_once_cc_seq_fetch_creds_begin(context, ccache, &creds_iterator, CC_NOERROR, "valid params");
+ }
+ if (creds_iterator) {
+ cc_seq_fetch_creds_end(context, &creds_iterator);
+ creds_iterator = NULL;
+ }
+
+ // NULL out param
+ if (!err) {
+ check_once_cc_seq_fetch_creds_begin(context, ccache, NULL, CC_BAD_PARM, "NULL out iterator param");
+ }
+ if (creds_iterator) {
+ cc_seq_fetch_creds_end(context, &creds_iterator);
+ creds_iterator = NULL;
+ }
+
+ // non-existent ccache
+ if (ccache) {
+ err = cc_get_name(context, ccache, &name);
+ if (!err) {
+ err = cc_open(context, name, CC_CRED_V5, 0, &dup_ccache);
+ }
+ if (name) { cc_free_name(context, &name); }
+ if (dup_ccache) { cc_destroy(context, &dup_ccache); }
+ }
+
+ if (!err) {
+ check_once_cc_seq_fetch_creds_begin(context, ccache, &creds_iterator, CC_NO_EXIST, "invalid ccache");
+ }
+
+ if (creds_iterator) {
+ cc_seq_fetch_creds_end(context, &creds_iterator);
+ creds_iterator = NULL;
+ }
+ if (ccache) { cc_close(context, &ccache); }
+ if (context) {
+ destroy_all_ccaches_v2(context);
+ cc_shutdown(&context);
+ }
+
+ END_TEST_AND_RETURN
+}
+
+// ---------------------------------------------------------------------------
+
+cc_result check_once_cc_seq_fetch_creds_begin(apiCB *context, ccache_p *ccache, ccache_cit **iterator, cc_result expected_err, const char *description) {
+ cc_result err = CC_NOERROR;
+
+ cc_result possible_return_values[5] = {
+ CC_NOERROR,
+ CC_BAD_PARM,
+ CC_NOMEM,
+ CC_NO_EXIST
+ };
+
+ BEGIN_CHECK_ONCE(description);
+
+#define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
+
+ err = cc_seq_fetch_creds_begin(context, ccache, iterator);
+
+ // check returned error
+ check_err(err, expected_err, possible_return_values);
+
+ END_CHECK_ONCE;
+
+ return err;
+}
+
+// ---------------------------------------------------------------------------
+
+int check_cc_seq_fetch_creds_next(void) {
+ cc_result err = 0;
+ apiCB *context = NULL;
+ ccache_p *ccache = NULL;
+ cred_union creds_union;
+ ccache_cit *iterator = NULL;
+ unsigned int i;
+
+ BEGIN_TEST("cc_seq_fetch_creds_next");
+
+ err = cc_initialize(&context, ccapi_version_2, NULL, NULL);
+
+ if (!err) {
+ err = destroy_all_ccaches_v2(context);
+ }
+
+ // iterate with no creds
+ if (!err) {
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_CREDS_NEXT", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ if (!err) {
+ err = cc_seq_fetch_creds_begin(context, ccache, &iterator);
+ }
+ check_once_cc_seq_fetch_creds_next(context, iterator, 0, CC_NOERROR, "iterating over an empty ccache");
+ if (iterator) {
+ cc_seq_fetch_creds_end(context, &iterator);
+ iterator = NULL;
+ }
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+
+ // iterate with one cred
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_CREDS_NEXT", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ if (!err) {
+ new_v5_creds_union_compat(&creds_union, "BAR.ORG");
+ err = cc_store(context, ccache, creds_union);
+ release_v5_creds_union_compat(&creds_union);
+ }
+ if (!err) {
+ err = cc_seq_fetch_creds_begin(context, ccache, &iterator);
+ }
+ check_once_cc_seq_fetch_creds_next(context, iterator, 1, CC_NOERROR, "iterating over a ccache with 1 cred");
+ if (iterator) {
+ cc_seq_fetch_creds_end(context, &iterator);
+ iterator = NULL;
+ }
+ if (ccache) {
+ cc_close(context, &ccache);
+ ccache = NULL;
+ }
+
+ // iterate with several creds
+ if (!err) {
+ destroy_all_ccaches_v2(context);
+ err = cc_create(context, "TEST_CC_SEQ_FETCH_CREDS_NEXT", "foo@BAR.ORG", CC_CRED_V5, 0, &ccache);
+ }
+ for(i = 0; !err && (i < 1000); i++) {
+ if (i%100 == 0) fprintf(stdout, ".");
+ new_v5_creds_union_compat(&creds_union, "BAR.ORG");
+ err = cc_store(context, ccache, creds_union);
+ release_v5_creds_union_compat(&creds_union);
+ }
+ if (!err) {
+ err = cc_seq_fetch_creds_begin(context, ccache, &iterator);
+ }
+ check_once_cc_seq_fetch_creds_next(context, iterator, 1000, CC_NOERROR, "iterating over a ccache with 1000 creds");
+
+ if (ccache) { cc_close(context, &ccache); }
+ if (iterator) { cc_seq_fetch_creds_end(context, &iterator); }
+ if (context) {
+ destroy_all_ccaches_v2(context);
+ cc_shutdown(&context);
+ }
+
+ END_TEST_AND_RETURN
+}
+
+// ---------------------------------------------------------------------------
+
+cc_result check_once_cc_seq_fetch_creds_next(apiCB *context, ccache_cit *iterator, cc_uint32 expected_count, cc_result expected_err, const char *description) {
+ cc_result err = CC_NOERROR;
+ cred_union *creds = NULL;
+ cc_uint32 actual_count = 0;
+
+ cc_result possible_return_values[5] = {
+ CC_NOERROR,
+ CC_END,
+ CC_BAD_PARM,
+ CC_NOMEM,
+ CC_NO_EXIST,
+ };
+
+ BEGIN_CHECK_ONCE(description);
+
+#define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
+
+ while (!err) {
+ err = cc_seq_fetch_creds_next(context, &creds, iterator);
+ if (creds) {
+ actual_count++;
+ cc_free_creds(context, &creds);
+ creds = NULL;
+ }
+ }
+ if (err == CC_END) {
+ err = CC_NOERROR;
+ }
+
+ // check returned error
+ check_err(err, expected_err, possible_return_values);
+
+ check_if(actual_count != expected_count, "iterator didn't iterate over all ccaches");
+
+ END_CHECK_ONCE;
+
+ return err;
+}
+
int check_cc_remove_cred(void);
cc_result check_once_cc_remove_cred(apiCB *context, ccache_p *ccache, cred_union in_creds, cc_int32 expected_err, const char *description);
+
+int check_cc_seq_fetch_NCs_begin(void);
+cc_result check_once_cc_seq_fetch_NCs_begin(apiCB *context, ccache_cit **iterator, cc_result expected_err, const char *description);
+
+int check_cc_seq_fetch_NCs_next(void);
+cc_result check_once_cc_seq_fetch_NCs_next(apiCB *context, ccache_cit *iterator, cc_uint32 expected_count, cc_result expected_err, const char *description);
+
+int check_cc_get_NC_info(void);
+cc_result check_once_cc_get_NC_info(apiCB *context,
+ const char *expected_name,
+ const char *expected_principal,
+ cc_int32 expected_version,
+ cc_uint32 expected_count,
+ cc_result expected_err,
+ const char *description);
+
+int check_cc_seq_fetch_creds_begin(void);
+cc_result check_once_cc_seq_fetch_creds_begin(apiCB *context, ccache_p *ccache, ccache_cit **iterator, cc_result expected_err, const char *description);
+
+int check_cc_seq_fetch_creds_next(void);
+cc_result check_once_cc_seq_fetch_creds_next(apiCB *context, ccache_cit *iterator, cc_uint32 expected_count, cc_result expected_err, const char *description);
+
#endif /* _TEST_CCAPI_V2_H_ */