diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2008-05-07 19:30:12 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2008-05-07 19:30:12 +0000 |
commit | 5434b4b675b53ed41436bccc9ef70d76d199a081 (patch) | |
tree | 34bb81c9a68d59648a71bf8312bbef44bc868511 /src/kim/test | |
parent | c59402909451704c36f862fb2968f6c8e717df4c (diff) | |
download | krb5-5434b4b675b53ed41436bccc9ef70d76d199a081.tar.gz krb5-5434b4b675b53ed41436bccc9ef70d76d199a081.tar.xz krb5-5434b4b675b53ed41436bccc9ef70d76d199a081.zip |
Move KIM implementation to the krb5 repository
Moved sources and headers.
ticket: new
status: open
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20314 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kim/test')
-rw-r--r-- | src/kim/test/main.c | 82 | ||||
-rw-r--r-- | src/kim/test/test_kim_common.c | 159 | ||||
-rw-r--r-- | src/kim/test/test_kim_common.h | 78 | ||||
-rw-r--r-- | src/kim/test/test_kim_identity.c | 559 | ||||
-rw-r--r-- | src/kim/test/test_kim_identity.h | 50 | ||||
-rw-r--r-- | src/kim/test/test_kim_preferences.c | 298 | ||||
-rw-r--r-- | src/kim/test/test_kim_preferences.h | 42 | ||||
-rw-r--r-- | src/kim/test/test_kim_selection_hints.c | 469 | ||||
-rw-r--r-- | src/kim/test/test_kim_selection_hints.h | 46 |
9 files changed, 1783 insertions, 0 deletions
diff --git a/src/kim/test/main.c b/src/kim/test/main.c new file mode 100644 index 000000000..c1c5bd19e --- /dev/null +++ b/src/kim/test/main.c @@ -0,0 +1,82 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "test_kim_identity.h" +#include "test_kim_preferences.h" +#include "test_kim_selection_hints.h" + +int main (int argc, const char * argv[]) +{ + kim_test_state_t state = NULL; + + if (test_init (&state)) { + return 1; + } + + test_kim_identity_create_from_krb5_principal (state); + + test_kim_identity_create_from_string (state); + + test_kim_identity_copy (state); + + test_kim_identity_compare (state); + + test_kim_identity_get_display_string (state); + + test_kim_identity_get_realm (state); + + test_kim_identity_get_number_of_components (state); + + test_kim_identity_get_component_at_index (state); + + test_kim_identity_get_krb5_principal (state); + + test_kim_preferences_create (state); + + test_kim_preferences_copy (state); + + test_kim_preferences_set_options (state); + + test_kim_preferences_set_remember_options (state); + + test_kim_preferences_set_client_identity (state); + + test_kim_selection_hints_set_service_identity_hint (state); + + test_kim_selection_hints_set_client_realm_hint (state); + + test_kim_selection_hints_set_user_hint (state); + + test_kim_selection_hints_set_service_realm_hint (state); + + test_kim_selection_hints_set_service_hint (state); + + test_kim_selection_hints_set_server_hint (state); + + test_kim_selection_hints_remember_identity (state); + + return test_cleanup (state); +} diff --git a/src/kim/test/test_kim_common.c b/src/kim/test/test_kim_common.c new file mode 100644 index 000000000..1e3b9673e --- /dev/null +++ b/src/kim/test/test_kim_common.c @@ -0,0 +1,159 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include <test_kim_common.h> + +const char *k_no_test_name = "No test name set"; + +/* ------------------------------------------------------------------------ */ + +int test_init (kim_test_state_t *out_state) +{ + kim_test_state_t state = NULL; + + printf ("Initializing tests... "); + + state = malloc (sizeof (*state)); + if (!state) { + printf ("out of memory.\n\n"); + return 1; + } + + state->test_name = k_no_test_name; + state->global_fail_count = 0; + state->test_fail_count = 0; + + *out_state = state; + + printf ("done.\n\n"); + + return 0; +} + +/* ------------------------------------------------------------------------ */ + +int test_cleanup (kim_test_state_t io_state) +{ + int global_fail_count = io_state->global_fail_count; + + printf ("Exiting. %d total failures.", global_fail_count); + free (io_state); + + return global_fail_count; +} + +/* ------------------------------------------------------------------------ */ + +void start_test (kim_test_state_t in_state, + const char *in_test_name) +{ + in_state->test_name = in_test_name; + in_state->test_fail_count = 0; + + printf ("Testing %s...\n", in_state->test_name); +} + +/* ------------------------------------------------------------------------ */ + +void end_test (kim_test_state_t in_state) +{ + printf ("Finished testing %s. %d failures.\n\n", + in_state->test_name, in_state->test_fail_count); + + in_state->test_name = k_no_test_name; + in_state->global_fail_count += in_state->test_fail_count; + in_state->test_fail_count = 0; +} + +/* ------------------------------------------------------------------------ */ + +void fail_if_error (kim_test_state_t in_state, + const char *in_function, + kim_error_t in_err, + const char *in_format, + ...) +{ + if (in_err) { + va_list args; + + printf ("\tFAILURE: "); + printf ("%s() got %d (%s) ", + in_function, kim_error_get_code (in_err), + kim_error_get_display_string (in_err)); + + va_start (args, in_format); + vprintf (in_format, args); + va_end (args); + + printf ("\n"); + + in_state->test_fail_count++; + } +} + +/* ------------------------------------------------------------------------ */ + +void fail_if_error_code (kim_test_state_t in_state, + const char *in_function, + kim_error_code_t in_code, + const char *in_format, + ...) +{ + if (in_code) { + va_list args; + + printf ("\tFAILURE: "); + printf ("%s() got %d (%s) ", + in_function, in_code, error_message (in_code)); + + va_start (args, in_format); + vprintf (in_format, args); + va_end (args); + + printf ("\n"); + + in_state->test_fail_count++; + } +} + +/* ------------------------------------------------------------------------ */ + +void log_failure (kim_test_state_t in_state, + const char *in_format, + ...) +{ + va_list args; + + printf ("\tFAILURE: "); + + va_start (args, in_format); + vprintf (in_format, args); + va_end (args); + + printf ("\n"); + + in_state->test_fail_count++; +} diff --git a/src/kim/test/test_kim_common.h b/src/kim/test/test_kim_common.h new file mode 100644 index 000000000..161224239 --- /dev/null +++ b/src/kim/test/test_kim_common.h @@ -0,0 +1,78 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef TEST_KIM_COMMON_H +#define TEST_KIM_COMMON_H + +#include <kim/kim.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct kim_test_state_d { + const char *test_name; + int global_fail_count; + int test_fail_count; +} *kim_test_state_t; + +int test_init (kim_test_state_t *out_state); + +int test_cleanup (kim_test_state_t io_state); + +void start_test (kim_test_state_t in_state, + const char *in_test_name); + +void end_test (kim_test_state_t in_state); + +void fail_if_error (kim_test_state_t in_state, + const char *in_function, + kim_error_t in_err, + const char *in_format, + ...) +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +__attribute__ ((__format__ (__printf__, 4, 5))) +#endif +; + +void fail_if_error_code (kim_test_state_t in_state, + const char *in_function, + kim_error_code_t in_code, + const char *in_format, + ...) +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +__attribute__ ((__format__ (__printf__, 4, 5))) +#endif +; + +void log_failure (kim_test_state_t in_state, + const char *in_format, + ...) +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +__attribute__ ((__format__ (__printf__, 2, 3))) +#endif +; + +#endif /* TEST_KIM_COMMON_H */ diff --git a/src/kim/test/test_kim_identity.c b/src/kim/test/test_kim_identity.c new file mode 100644 index 000000000..be97726a7 --- /dev/null +++ b/src/kim/test/test_kim_identity.c @@ -0,0 +1,559 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "test_kim_identity.h" + +typedef struct test_identity_d { + const char *string; + const char *display_string; + kim_boolean_t is_tgt_service; + const char *realm; + kim_count_t component_count; + const char *components[5]; +} test_identity_t; + + +test_identity_t test_identities[] = { + {"a@B", "a@B", 0, "B", 1, { "a", NULL, NULL, NULL, NULL } }, + {"user@EXAMPLE.COM", "user@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "user", NULL, NULL, NULL, NULL } }, + {"krbtgt@EXAMPLE.COM", "krbtgt@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "krbtgt", NULL, NULL, NULL, NULL } }, + {"krbtgt/EXAMPLE.COM@EXAMPLE.COM", "krbtgt/EXAMPLE.COM@EXAMPLE.COM", 1, "EXAMPLE.COM", 2, { "krbtgt", "EXAMPLE.COM", NULL, NULL, NULL } }, + {"krbtgt/OTHER.COM@EXAMPLE.COM", "krbtgt/OTHER.COM@EXAMPLE.COM", 1, "EXAMPLE.COM", 2, { "krbtgt", "OTHER.COM", NULL, NULL, NULL } }, + {"a space@EXAMPLE.COM", "a space@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "a space", NULL, NULL, NULL, NULL } }, + {"üñîçödé@EXAMPLE.COM", "üñîçödé@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "üñîçödé", NULL, NULL, NULL, NULL } }, + {"user.name@EXAMPLE.COM", "user.name@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "user.name", NULL, NULL, NULL, NULL } }, + {"user\\/instance@EXAMPLE.COM", "user/instance@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "user\/instance", NULL, NULL, NULL, NULL } }, + {"user\\@instance@EXAMPLE.COM", "user@instance@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "user\@instance", NULL, NULL, NULL, NULL } }, + {"user/instance@EXAMPLE.COM", "user/instance@EXAMPLE.COM", 0, "EXAMPLE.COM", 2, { "user", "instance", NULL, NULL, NULL } }, + {"user/i1/i2@EXAMPLE.COM", "user/i1/i2@EXAMPLE.COM", 0, "EXAMPLE.COM", 3, { "user", "i1", "i2", NULL, NULL } }, + {"user/i1/i2/i3/i4@EXAMPLE.COM", "user/i1/i2/i3/i4@EXAMPLE.COM", 0, "EXAMPLE.COM", 5, { "user", "i1", "i2", "i3", "i4" } }, + {"an insanely long principal for testing icky hex key principals/an insanely long instance for testing icky hex key principals@AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", + "an insanely long principal for testing icky hex key principals/an insanely long instance for testing icky hex key principals@AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", + 0, "AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", + 2, { "an insanely long principal for testing icky hex key principals", "an insanely long instance for testing icky hex key principals", NULL, NULL, NULL } }, + { NULL, NULL, 0, NULL, 0, { NULL, NULL, NULL, NULL, NULL } }, +}; + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_create_from_krb5_principal (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_create_from_krb5_principal"); + + for (i = 0; test_identities[i].string; i++) { + krb5_error_code code = 0; + kim_error_t err = NULL; + krb5_context context = NULL; + krb5_principal principal = NULL; + kim_identity_t identity = NULL; + kim_string_t string = NULL; + + printf ("."); + + code = krb5_init_context (&context); + fail_if_error_code (state, "krb5_init_context", code, + "while initializing context"); + + if (!code) { + code = krb5_parse_name (context, test_identities[i].string, &principal); + fail_if_error_code (state, "krb5_parse_name", code, + "while creating krb5_principal for %s", + test_identities[i].string); + } + + if (!code && !err) { + err = kim_identity_create_from_krb5_principal (&identity, context, principal); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!code && !err) { + err = kim_identity_get_string (identity, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for %s", + test_identities[i].string); + } + + if (!code && !err && strcmp (string, test_identities[i].string)) { + log_failure (state, "Unexpected string (got '%s', expected '%s')", + string, test_identities[i].string); + } + + kim_string_free (&string); + kim_identity_free (&identity); + if (principal) { krb5_free_principal (context, principal); } + if (context ) { krb5_free_context (context); } + + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_create_from_string (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_create_from_string"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_string_t string = NULL; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_get_string (identity, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for %s", + test_identities[i].string); + } + + if (!err && strcmp (string, test_identities[i].string)) { + log_failure (state, "Unexpected string (got '%s', expected '%s')", + string, test_identities[i].string); + } + + kim_string_free (&string); + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_copy (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_copy"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_identity_t identity_copy = NULL; + kim_string_t string = NULL; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_copy (&identity_copy, identity); + fail_if_error (state, "kim_identity_copy", err, + "while copying %s", test_identities[i].string); + } + + if (!err) { + err = kim_identity_get_string (identity_copy, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for the copy of %s", + test_identities[i].string); + } + + if (!err && strcmp (string, test_identities[i].string)) { + log_failure (state, "Unexpected string (got '%s', expected '%s')", + string, test_identities[i].string); + } + + kim_string_free (&string); + kim_identity_free (&identity_copy); + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_compare (kim_test_state_t state) +{ + kim_count_t i, j = 0; + + start_test (state, "kim_identity_create_from_string"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + + printf ("."); + + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + + for (j = 0; !err && test_identities[j].string; j++) { + kim_identity_t compare_to_identity = NULL; + kim_comparison_t comparison = 0; + + err = kim_identity_create_from_string (&compare_to_identity, test_identities[j].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[j].string); + + if (!err) { + err = kim_identity_compare (identity, compare_to_identity, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s and %s", + test_identities[i].string, test_identities[j].string); + } + + if (!err) { + if (i == j && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Expected %s and %s to be equal but kim_identity_compare returned %d", + test_identities[i].string, test_identities[j].string, comparison); + + } else if (i != j && kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Expected %s and %s to be NOT equal but kim_identity_compare returned %d", + test_identities[i].string, test_identities[j].string, comparison); + } + } + + kim_identity_free (&compare_to_identity); + } + + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_get_display_string (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_get_display_string"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_string_t string = NULL; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_get_display_string (identity, &string); + fail_if_error (state, "kim_identity_get_display_string", err, + "while getting the display string for %s", + test_identities[i].string); + } + + if (!err && strcmp (string, test_identities[i].display_string)) { + log_failure (state, "Unexpected display string for %s (got '%s', expected '%s')", + test_identities[i].string, string, test_identities[i].display_string); + } + + kim_string_free (&string); + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_get_realm (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_get_realm"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_string_t realm = NULL; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_get_realm (identity, &realm); + fail_if_error (state, "kim_identity_get_realm", err, + "while getting the realm for %s", test_identities[i].string); + } + + if (!err && strcmp (realm, test_identities[i].realm)) { + log_failure (state, "Unexpected realm string (got '%s', expected '%s')", + realm, test_identities[i].realm); + } + + kim_string_free (&realm); + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_get_number_of_components (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_get_number_of_components"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_count_t count = 0; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_get_number_of_components (identity, &count); + fail_if_error (state, "kim_identity_get_number_of_components", err, + "while getting number of components of %s", + test_identities[i].string); + } + + if (!err && (count != test_identities[i].component_count)) { + log_failure (state, "Unexpected component count of %s (got %d, expected %d)", + test_identities[i].string, (int) count, (int) test_identities[i].component_count); + } + + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_get_component_at_index (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_get_component_at_index"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_count_t c = 0; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + for (c = 0; !err && c < test_identities[i].component_count; c++) { + kim_string_t component = NULL; + + err = kim_identity_get_component_at_index (identity, c, &component); + fail_if_error (state, "kim_identity_get_component_at_index", err, + "while getting component %d of %s", (int) c, + test_identities[i].string); + + if (!err && strcmp (component, test_identities[i].components[c])) { + log_failure (state, "Unexpected component %d of %s (got '%s', expected '%s')", + (int) c, test_identities[i].string, + component, test_identities[i].components[c]); + } + + kim_string_free (&component); + } + + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_identity_get_krb5_principal (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_get_krb5_principal"); + + for (i = 0; test_identities[i].string; i++) { + krb5_error_code code = 0; + kim_error_t err = NULL; + krb5_context context = NULL; + krb5_principal principal = NULL; + krb5_principal identity_principal = NULL; + kim_identity_t identity = NULL; + + printf ("."); + + code = krb5_init_context (&context); + fail_if_error_code (state, "krb5_init_context", code, + "while initializing context"); + + if (!code) { + code = krb5_parse_name (context, test_identities[i].string, &principal); + fail_if_error_code (state, "krb5_parse_name", code, + "while creating krb5_principal for %s", + test_identities[i].string); + } + + if (!code && !err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!code && !err) { + err = kim_identity_get_krb5_principal (identity, context, &identity_principal); + fail_if_error (state, "kim_identity_get_krb5_principal", err, + "while getting the krb5_principal for %s", + test_identities[i].string); + } + + if (!code && !err) { + if (!krb5_principal_compare (context, principal, identity_principal)) { + log_failure (state, "Principal and identity principal for %s do not match", + test_identities[i].string); + } + } + + kim_identity_free (&identity); + if (identity_principal) { krb5_free_principal (context, identity_principal); } + if (principal ) { krb5_free_principal (context, principal); } + if (context ) { krb5_free_context (context); } + + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ +/* +void test_kim_identity_is_tgt_service (kim_test_state_t state) +{ + kim_count_t i = 0; + + start_test (state, "kim_identity_is_tgt_service"); + + for (i = 0; test_identities[i].string; i++) { + kim_error_t err = NULL; + kim_identity_t identity = NULL; + kim_boolean_t is_tgt_service = 0; + + printf ("."); + + if (!err) { + err = kim_identity_create_from_string (&identity, test_identities[i].string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", + test_identities[i].string); + } + + if (!err) { + err = kim_identity_is_tgt_service (identity, &is_tgt_service); + fail_if_error (state, "kim_identity_is_tgt_service", err, + "while determining if %s is a tgt service", + test_identities[i].string); + } + + if (!err && (is_tgt_service != test_identities[i].is_tgt_service)) { + log_failure (state, "Unexpected result from kim_identity_is_tgt_service for %s (got %d, expected %d)", + test_identities[i].string, is_tgt_service, test_identities[i].is_tgt_service); + } + + kim_identity_free (&identity); + kim_error_free (&err); + } + + printf ("\n"); + + end_test (state); +} +*/ diff --git a/src/kim/test/test_kim_identity.h b/src/kim/test/test_kim_identity.h new file mode 100644 index 000000000..a294c2c3d --- /dev/null +++ b/src/kim/test/test_kim_identity.h @@ -0,0 +1,50 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef TEST_KIM_IDENTITY_H +#define TEST_KIM_IDENTITY_H + +#include "test_kim_common.h" + +void test_kim_identity_create_from_krb5_principal (kim_test_state_t state); + +void test_kim_identity_create_from_string (kim_test_state_t state); + +void test_kim_identity_copy (kim_test_state_t state); + +void test_kim_identity_compare (kim_test_state_t state); + +void test_kim_identity_get_display_string (kim_test_state_t state); + +void test_kim_identity_get_realm (kim_test_state_t state); + +void test_kim_identity_get_number_of_components (kim_test_state_t state); + +void test_kim_identity_get_component_at_index (kim_test_state_t state); + +void test_kim_identity_get_krb5_principal (kim_test_state_t state); + +#endif /* TEST_KIM_IDENTITY_H */ diff --git a/src/kim/test/test_kim_preferences.c b/src/kim/test/test_kim_preferences.c new file mode 100644 index 000000000..6cf0ba76d --- /dev/null +++ b/src/kim/test/test_kim_preferences.c @@ -0,0 +1,298 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "test_kim_preferences.h" + +/* ------------------------------------------------------------------------ */ + +void test_kim_preferences_create (kim_test_state_t state) +{ + + start_test (state, "kim_preferences_create"); + + { + kim_error_t err = NULL; + kim_preferences_t prefs = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + kim_preferences_free (&prefs); + kim_error_free (&err); + } + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_preferences_copy (kim_test_state_t state) +{ + + start_test (state, "test_kim_preferences_copy"); + + { + kim_error_t err = NULL; + kim_preferences_t prefs = NULL; + kim_preferences_t prefs_copy = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + if (!err) { + err = kim_preferences_copy (&prefs_copy, prefs); + fail_if_error (state, "kim_preferences_copy", err, + "while copying preferences"); + } + + kim_preferences_free (&prefs_copy); + kim_preferences_free (&prefs); + kim_error_free (&err); + } + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_preferences_set_options (kim_test_state_t state) +{ + + start_test (state, "kim_preferences_set_options"); + + { + kim_error_t err = NULL; + kim_preferences_t prefs = NULL; + kim_options_t old_options = NULL; + kim_options_t new_options = NULL; + kim_options_t verify_options = NULL; + const char *custom_data = "Some custom data"; + const char *verify_custom_data = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + if (!err) { + err = kim_preferences_get_options (prefs, &old_options); + fail_if_error (state, "kim_preferences_get_options", err, + "while getting old options"); + } + + if (!err) { + err = kim_options_create (&new_options); + fail_if_error (state, "kim_options_create", err, + "while creating options"); + } + + if (!err) { + err = kim_options_set_data (new_options, custom_data); + fail_if_error (state, "kim_options_set_data", err, + "while setting the custom data to %s", custom_data); + } + + if (!err) { + err = kim_preferences_set_options (prefs, new_options); + fail_if_error (state, "kim_preferences_set_options", err, + "while setting the new options"); + } + + if (!err) { + err = kim_preferences_get_options (prefs, &verify_options); + fail_if_error (state, "kim_preferences_get_options", err, + "while getting options for verification"); + } + + if (!err) { + err = kim_options_get_data (verify_options, (const void **)&verify_custom_data); + fail_if_error (state, "kim_options_get_data", err, + "while getting the custom data of the verify options"); + } + + if (!err && custom_data != verify_custom_data) { + log_failure (state, "Unexpected custom data in options (got %p, expected %p)", + verify_custom_data, custom_data); + } + + if (!err) { + err = kim_preferences_set_options (prefs, old_options); + fail_if_error (state, "kim_preferences_set_options", err, + "while restoring the options"); + } + + kim_options_free (&old_options); + kim_options_free (&new_options); + kim_options_free (&verify_options); + kim_preferences_free (&prefs); + kim_error_free (&err); + } + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_preferences_set_remember_options (kim_test_state_t state) +{ + + start_test (state, "kim_preferences_set_remember_options"); + + { + kim_error_t err = NULL; + kim_preferences_t prefs = NULL; + kim_boolean_t remember_options = FALSE; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + if (!err) { + err = kim_preferences_set_remember_options (prefs, TRUE); + fail_if_error (state, "kim_preferences_set_remember_options", err, + "while setting the preference to remember options"); + } + + if (!err) { + err = kim_preferences_get_remember_options (prefs, &remember_options); + fail_if_error (state, "kim_preferences_get_remember_options", err, + "while getting the preference to remember options"); + } + + if (!err && !remember_options) { + log_failure (state, "Unexpected remember options preference (got %d, expected TRUE)", + remember_options); + } + + if (!err) { + err = kim_preferences_set_remember_options (prefs, FALSE); + fail_if_error (state, "kim_preferences_set_remember_options", err, + "while setting the preference to remember options"); + } + + if (!err) { + err = kim_preferences_get_remember_options (prefs, &remember_options); + fail_if_error (state, "kim_preferences_get_remember_options", err, + "while getting the preference to remember options"); + } + + if (!err && remember_options) { + log_failure (state, "Unexpected remember options preference (got %d, expected 0)", + remember_options); + } + + kim_preferences_free (&prefs); + kim_error_free (&err); + } + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_preferences_set_client_identity (kim_test_state_t state) +{ + + start_test (state, "kim_preferences_set_client_identity"); + + { + kim_error_t err = NULL; + kim_preferences_t prefs = NULL; + kim_string_t test_string = "user@EXAMPLE.COM"; + kim_identity_t test_identity = KIM_IDENTITY_ANY; + kim_string_t string = NULL; + kim_identity_t identity = KIM_IDENTITY_ANY; + kim_comparison_t comparison = 0; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + if (!err) { + err = kim_identity_create_from_string (&test_identity, test_string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_string); + } + + if (!err) { + err = kim_preferences_set_client_identity (prefs, KIM_IDENTITY_ANY); + fail_if_error (state, "kim_preferences_set_client_identity", err, + "while setting the identity to KIM_IDENTITY_ANY"); + } + + if (!err) { + err = kim_preferences_get_client_identity (prefs, &identity); + fail_if_error (state, "kim_preferences_get_client_identity", err, + "while getting the client identity preference"); + } + + if (!err && identity != KIM_IDENTITY_ANY) { + log_failure (state, "Unexpected client identity preference (got %p, expected %p)", + identity, KIM_IDENTITY_ANY); + kim_identity_free (&identity); + } + + if (!err) { + err = kim_preferences_set_client_identity (prefs, test_identity); + fail_if_error (state, "kim_preferences_set_client_identity", err, + "while setting the identity to %s", test_string); + } + + if (!err) { + err = kim_preferences_get_client_identity (prefs, &identity); + fail_if_error (state, "kim_preferences_get_client_identity", err, + "while getting the client identity preference"); + } + + if (!err && identity) { + err = kim_identity_get_string (identity, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for client identity preference"); + } + + if (!err) { + err = kim_identity_compare (identity, test_identity, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the identity preference %s", + test_string, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected client identity preference (got %s, expected %s)", + string ? string : "NULL", test_string); + kim_identity_free (&identity); + } + + kim_string_free (&string); + kim_identity_free (&identity); + kim_identity_free (&test_identity); + kim_preferences_free (&prefs); + kim_error_free (&err); + } + + end_test (state); +} diff --git a/src/kim/test/test_kim_preferences.h b/src/kim/test/test_kim_preferences.h new file mode 100644 index 000000000..e86f11f2f --- /dev/null +++ b/src/kim/test/test_kim_preferences.h @@ -0,0 +1,42 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef TEST_KIM_PREFERENCES_H +#define TEST_KIM_PREFERENCES_H + +#include "test_kim_common.h" + +void test_kim_preferences_create (kim_test_state_t state); + +void test_kim_preferences_copy (kim_test_state_t state); + +void test_kim_preferences_set_options (kim_test_state_t state); + +void test_kim_preferences_set_remember_options (kim_test_state_t state); + +void test_kim_preferences_set_client_identity (kim_test_state_t state); + +#endif /* TEST_KIM_PREFERENCES_H */ diff --git a/src/kim/test/test_kim_selection_hints.c b/src/kim/test/test_kim_selection_hints.c new file mode 100644 index 000000000..d2bc51151 --- /dev/null +++ b/src/kim/test/test_kim_selection_hints.c @@ -0,0 +1,469 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "test_kim_selection_hints.h" + +#define KSH_TEST_ID "edu.mit.Kerberos.test_kim" +#define KSH_SERVICE_IDENTITY "service/server.example.com@EXAMPLE.COM" +#define KSH_SERVICE "service" +#define KSH_SERVER "server.example.com" +#define KSH_SERVICE_REALM "EXAMPLE.COM" +#define KSH_USER "jdoe" +#define KSH_CLIENT_REALM "USERS.EXAMPLE.COM" + +#define KSH_IDENTITY "jdoe@USERS.EXAMPLE.COM" + + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_service_identity_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_identity_t service_identity = NULL; + kim_identity_t identity = KIM_IDENTITY_ANY; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_service_identity_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_identity_create_from_string (&service_identity, + KSH_SERVICE_IDENTITY); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating an identity for %s", + KSH_SERVICE_IDENTITY); + } + + if (!err) { + err = kim_selection_hints_set_service_identity_hint (hints, service_identity); + fail_if_error (state, "kim_selection_hints_set_service_identity_hint", + err, "while setting service identity to %s", + KSH_SERVICE_IDENTITY); + } + + if (!err) { + err = kim_selection_hints_get_service_identity_hint (hints, &identity); + fail_if_error (state, "kim_selection_hints_get_service_identity_hint", + err, "while getting service identity %s", + KSH_SERVICE_IDENTITY); + } + + if (!err && identity) { + err = kim_identity_get_string (identity, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for the service identity hint"); + } + + if (!err) { + err = kim_identity_compare (service_identity, identity, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the identity hint %s", + KSH_SERVICE_IDENTITY, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected service identity hint (got %s, expected %s)", + string ? string : "NULL", KSH_SERVICE_IDENTITY); + kim_identity_free (&identity); + } + + kim_string_free (&string); + kim_identity_free (&service_identity); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_client_realm_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_client_realm_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_selection_hints_set_client_realm_hint (hints, KSH_CLIENT_REALM); + fail_if_error (state, "kim_selection_hints_set_client_realm_hint", + err, "while setting client realm hint to %s", + KSH_CLIENT_REALM); + } + + if (!err) { + err = kim_selection_hints_get_client_realm_hint (hints, &string); + fail_if_error (state, "kim_selection_hints_get_client_realm_hint", + err, "while getting the client realm %s", + KSH_CLIENT_REALM); + } + + if (!err) { + err = kim_string_compare (KSH_CLIENT_REALM, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the client realm hint %s", + KSH_CLIENT_REALM, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected client realm hint (got %s, expected %s)", + string ? string : "NULL", KSH_CLIENT_REALM); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_user_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_user_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_selection_hints_set_user_hint (hints, KSH_USER); + fail_if_error (state, "kim_selection_hints_set_user_hint", + err, "while setting user hint to %s", + KSH_USER); + } + + if (!err) { + err = kim_selection_hints_get_user_hint (hints, &string); + fail_if_error (state, "kim_selection_hints_get_user_hint", + err, "while getting the user hint %s", + KSH_USER); + } + + if (!err) { + err = kim_string_compare (KSH_USER, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the user hint %s", + KSH_USER, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected user hint (got %s, expected %s)", + string ? string : "NULL", KSH_USER); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_service_realm_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_service_realm_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_selection_hints_set_service_realm_hint (hints, KSH_SERVICE_REALM); + fail_if_error (state, "kim_selection_hints_set_service_realm_hint", + err, "while setting service realm to %s", + KSH_SERVICE_REALM); + } + + if (!err) { + err = kim_selection_hints_get_service_realm_hint (hints, &string); + fail_if_error (state, "kim_selection_hints_get_service_realm_hint", + err, "while getting the service realm hint %s", + KSH_SERVICE_REALM); + } + + if (!err) { + err = kim_string_compare (KSH_SERVICE_REALM, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the service realm hint %s", + KSH_SERVICE_REALM, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected service realm hint (got %s, expected %s)", + string ? string : "NULL", KSH_SERVICE_REALM); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_service_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_service_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_selection_hints_set_service_hint (hints, KSH_SERVICE); + fail_if_error (state, "kim_selection_hints_set_service_hint", + err, "while setting service hint to %s", + KSH_SERVICE); + } + + if (!err) { + err = kim_selection_hints_get_service_hint (hints, &string); + fail_if_error (state, "kim_selection_hints_get_service_hint", + err, "while getting the service hint %s", + KSH_SERVICE); + } + + if (!err) { + err = kim_string_compare (KSH_SERVICE, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the service hint %s", + KSH_SERVICE, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected service hint (got %s, expected %s)", + string ? string : "NULL", KSH_SERVICE); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_set_server_hint (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_string_t string = NULL; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_set_server_hint"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_selection_hints_set_server_hint (hints, KSH_SERVER); + fail_if_error (state, "kim_selection_hints_set_server_hint", + err, "while setting server hint to %s", + KSH_SERVER); + } + + if (!err) { + err = kim_selection_hints_get_server_hint (hints, &string); + fail_if_error (state, "kim_selection_hints_get_server_hint", + err, "while getting the server hint %s", + KSH_SERVER); + } + + if (!err) { + err = kim_string_compare (KSH_SERVER, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the server hint %s", + KSH_SERVER, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected server hint (got %s, expected %s)", + string ? string : "NULL", KSH_SERVER); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); + + end_test (state); +} + +/* ------------------------------------------------------------------------ */ + +void test_kim_selection_hints_remember_identity (kim_test_state_t state) +{ + kim_error_t err = NULL; + kim_selection_hints_t hints = NULL; + kim_identity_t service_identity = NULL; + kim_identity_t client_identity = NULL; + kim_string_t string = NULL; + kim_identity_t identity = KIM_IDENTITY_ANY; + kim_comparison_t comparison = 0; + + start_test (state, "kim_selection_hints_remember_identity"); + + if (!err) { + err = kim_selection_hints_create (&hints, KSH_TEST_ID); + fail_if_error (state, "kim_selection_hints_create", err, + "while creating selection hints for %s", KSH_TEST_ID); + } + + if (!err) { + err = kim_identity_create_from_string (&service_identity, + KSH_SERVICE_IDENTITY); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating an identity for %s", + KSH_SERVICE_IDENTITY); + } + + if (!err) { + err = kim_identity_create_from_string (&client_identity, + KSH_IDENTITY); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating an identity for %s", + KSH_IDENTITY); + } + + if (!err) { + err = kim_selection_hints_set_service_identity_hint (hints, service_identity); + fail_if_error (state, "kim_selection_hints_set_service_identity_hint", + err, "while setting service identity to %s", + KSH_SERVICE_IDENTITY); + } + + if (!err) { + err = kim_selection_hints_set_client_realm_hint (hints, KSH_CLIENT_REALM); + fail_if_error (state, "kim_selection_hints_set_client_realm_hint", + err, "while setting client realm to %s", + KSH_CLIENT_REALM); + } + + if (!err) { + err = kim_selection_hints_set_user_hint (hints, KSH_USER); + fail_if_error (state, "kim_selection_hints_set_user_hint", + err, "while setting user to %s", + KSH_USER); + } + + if (!err) { + err = kim_selection_hints_set_service_realm_hint (hints, KSH_SERVICE_REALM); + fail_if_error (state, "kim_selection_hints_set_service_realm_hint", + err, "while setting service realm to %s", + KSH_SERVICE_REALM); + } + + if (!err) { + err = kim_selection_hints_set_service_hint (hints, KSH_SERVICE); + fail_if_error (state, "kim_selection_hints_set_service_hint", + err, "while setting service to %s", + KSH_SERVICE); + } + + if (!err) { + err = kim_selection_hints_set_server_hint (hints, KSH_SERVER); + fail_if_error (state, "kim_selection_hints_set_server_hint", + err, "while setting server to %s", + KSH_SERVER); + } + + if (!err) { + err = kim_selection_hints_remember_identity (hints, client_identity); + fail_if_error (state, "kim_selection_hints_remember_identity", + err, "while remembering identity %s", + KSH_IDENTITY); + } + + if (!err) { + err = kim_selection_hints_get_identity (hints, &identity); + fail_if_error (state, "kim_selection_hints_get_identity", + err, "while checking if identity is %s", + KSH_IDENTITY); + } + + if (!err && identity) { + err = kim_identity_get_string (identity, &string); + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for the client identity hint"); + } + + if (!err) { + err = kim_identity_compare (client_identity, identity, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the identity hint %s", + KSH_IDENTITY, string ? string : "NULL"); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected client identity hint (got %s, expected %s)", + string ? string : "NULL", KSH_IDENTITY); + } + + kim_string_free (&string); + kim_identity_free (&identity); + kim_identity_free (&client_identity); + kim_identity_free (&service_identity); + kim_selection_hints_free (&hints); + + end_test (state); +} diff --git a/src/kim/test/test_kim_selection_hints.h b/src/kim/test/test_kim_selection_hints.h new file mode 100644 index 000000000..fac9a3d5d --- /dev/null +++ b/src/kim/test/test_kim_selection_hints.h @@ -0,0 +1,46 @@ +/* + * $Header$ + * + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef TEST_KIM_SELECTION_HINTS_H +#define TEST_KIM_SELECTION_HINTS_H + +#include "test_kim_common.h" + +void test_kim_selection_hints_set_service_identity_hint (kim_test_state_t state); + +void test_kim_selection_hints_set_client_realm_hint (kim_test_state_t state); + +void test_kim_selection_hints_set_user_hint (kim_test_state_t state); + +void test_kim_selection_hints_set_service_realm_hint (kim_test_state_t state); + +void test_kim_selection_hints_set_service_hint (kim_test_state_t state); + +void test_kim_selection_hints_set_server_hint (kim_test_state_t state); + +void test_kim_selection_hints_remember_identity (kim_test_state_t state); + +#endif /* TEST_KIM_SELECTION_HINTS_H */ |