diff options
author | Stef Walter <stef@memberwebs.com> | 2010-08-01 11:34:29 +0200 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2010-08-01 11:34:29 +0200 |
commit | 0813c5ac6710daa2f5f1518bc53c221e8f1866da (patch) | |
tree | 1f96f4b510820b6a3c1ae79e02010c94a3fdbaad /gck/tests | |
parent | edcaa16713a12ab158580a20cc792655663984c7 (diff) | |
download | gcr-0813c5ac6710daa2f5f1518bc53c221e8f1866da.tar.gz |
[gck] Make various objects pretty much immutable.
* Except for certain flags used during destruction, which we
use atomically internally.
Diffstat (limited to 'gck/tests')
-rw-r--r-- | gck/tests/test-gck-crypto.c | 27 | ||||
-rw-r--r-- | gck/tests/test-gck-module.c | 8 | ||||
-rw-r--r-- | gck/tests/test-gck-object.c | 2 | ||||
-rw-r--r-- | gck/tests/test-gck-session.c | 37 | ||||
-rw-r--r-- | gck/tests/test-gck-slot.c | 4 |
5 files changed, 44 insertions, 34 deletions
diff --git a/gck/tests/test-gck-crypto.c b/gck/tests/test-gck-crypto.c index e0232d2..315f629 100644 --- a/gck/tests/test-gck-crypto.c +++ b/gck/tests/test-gck-crypto.c @@ -9,33 +9,42 @@ #include "gck-test.h" static GckModule *module = NULL; -static GckSlot *slot = NULL; +static GckModule *module_with_auth = NULL; static GckSession *session = NULL; +static GckSession *session_with_auth = NULL; DEFINE_SETUP(crypto_session) { GError *err = NULL; GList *slots; + GckSlot *slot; /* Successful load */ - module = gck_module_initialize (".libs/libgck-test-module.so", NULL, &err); + module = gck_module_initialize (".libs/libgck-test-module.so", NULL, 0, &err); SUCCESS_RES (module, err); slots = gck_module_get_slots (module, TRUE); g_assert (slots != NULL); - slot = GCK_SLOT (slots->data); - g_object_ref (slot); - gck_list_unref_free (slots); - - session = gck_slot_open_session (slot, 0, &err); + session = gck_slot_open_session (slots->data, 0, &err); SUCCESS_RES(session, err); + + module_with_auth = gck_module_new (gck_module_get_functions (module), GCK_AUTHENTICATE_OBJECTS); + g_assert (module_with_auth); + + slot = gck_slot_from_handle (module_with_auth, gck_slot_get_handle (slots->data)); + g_assert (slot); + + session_with_auth = gck_session_from_handle (slot, gck_session_get_handle (session)); + g_assert (session_with_auth); + + g_object_unref (slot); + gck_list_unref_free (slots); } DEFINE_TEARDOWN(crypto_session) { g_object_unref (session); - g_object_unref (slot); g_object_unref (module); } @@ -261,7 +270,6 @@ DEFINE_TEST(sign) mech = gck_mechanism_new_with_param (CKM_PREFIX, "my-prefix:", 10); /* Enable auto-login on this session, see previous test */ - gck_module_set_options (module, GCK_AUTHENTICATE_OBJECTS); g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL); /* Find the right key */ @@ -311,7 +319,6 @@ DEFINE_TEST(verify) mech = gck_mechanism_new_with_param (CKM_PREFIX, "my-prefix:", 10); /* Enable auto-login on this session, shouldn't be needed */ - gck_module_set_options (module, GCK_AUTHENTICATE_OBJECTS); g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL); /* Find the right key */ diff --git a/gck/tests/test-gck-module.c b/gck/tests/test-gck-module.c index 955ae49..67b2be3 100644 --- a/gck/tests/test-gck-module.c +++ b/gck/tests/test-gck-module.c @@ -12,7 +12,7 @@ DEFINE_SETUP(load_module) GError *err = NULL; /* Successful load */ - module = gck_module_initialize (".libs/libgck-test-module.so", NULL, &err); + module = gck_module_initialize (".libs/libgck-test-module.so", NULL, 0, &err); SUCCESS_RES (module, err); } @@ -27,11 +27,11 @@ DEFINE_TEST(invalid_modules) GError *err = NULL; /* Shouldn't be able to load modules */ - invalid = gck_module_initialize ("blah-blah-non-existant", NULL, &err); + invalid = gck_module_initialize ("blah-blah-non-existant", NULL, 0, &err); FAIL_RES (invalid, err); /* Shouldn't be able to load any file successfully */ - invalid = gck_module_initialize ("/usr/lib/libm.so", NULL, &err); + invalid = gck_module_initialize ("/usr/lib/libm.so", NULL, 0, &err); FAIL_RES (invalid, err); } @@ -46,7 +46,7 @@ DEFINE_TEST(module_equals_hash) g_assert (gck_module_equal (module, module)); - other = gck_module_new (gck_module_get_functions (module)); + other = gck_module_new (gck_module_get_functions (module), 0); obj = g_object_new (G_TYPE_OBJECT, NULL); g_assert (gck_module_equal (module, other)); diff --git a/gck/tests/test-gck-object.c b/gck/tests/test-gck-object.c index c6e5da4..10f4ef0 100644 --- a/gck/tests/test-gck-object.c +++ b/gck/tests/test-gck-object.c @@ -19,7 +19,7 @@ DEFINE_SETUP(prep_object) GList *slots; /* Successful load */ - module = gck_module_initialize (".libs/libgck-test-module.so", NULL, &err); + module = gck_module_initialize (".libs/libgck-test-module.so", NULL, 0, &err); SUCCESS_RES (module, err); slots = gck_module_get_slots (module, TRUE); diff --git a/gck/tests/test-gck-session.c b/gck/tests/test-gck-session.c index d60931d..3cf535d 100644 --- a/gck/tests/test-gck-session.c +++ b/gck/tests/test-gck-session.c @@ -18,7 +18,7 @@ DEFINE_SETUP(load_session) GList *slots; /* Successful load */ - module = gck_module_initialize (".libs/libgck-test-module.so", NULL, &err); + module = gck_module_initialize (".libs/libgck-test-module.so", NULL, 0, &err); SUCCESS_RES (module, err); slots = gck_module_get_slots (module, TRUE); @@ -195,6 +195,8 @@ authenticate_token (GckModule *module, GckSlot *slot, gchar *label, gchar **pass DEFINE_TEST(auto_login) { GckObject *object; + GckModule *module_with_auth; + GckSlot *slot_with_auth; GckSession *new_session; GAsyncResult *result = NULL; GError *err = NULL; @@ -208,56 +210,57 @@ DEFINE_TEST(auto_login) gck_attributes_add_boolean (attrs, CKA_PRIVATE, CK_TRUE); /* Try to do something that requires a login */ + g_assert_cmpuint (gck_module_get_options (module), ==, 0); object = gck_session_create_object (session, attrs, NULL, &err); g_assert (!object); g_assert (err && err->code == CKR_USER_NOT_LOGGED_IN); g_clear_error (&err); /* Setup for auto login */ - g_assert (gck_module_get_options (module) == 0); - gck_module_set_options (module, GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS); - g_assert (gck_module_get_options (module) == (GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS)); - g_object_get (module, "options", &value, NULL); - g_assert (value == (GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS)); + module_with_auth = gck_module_new (gck_module_get_functions (module), GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS); + g_assert (gck_module_get_options (module_with_auth) == (GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS)); + g_object_get (module_with_auth, "options", &value, NULL); + g_assert_cmpuint (value, ==, (GCK_AUTHENTICATE_TOKENS | GCK_AUTHENTICATE_OBJECTS)); - g_signal_connect (module, "authenticate-slot", G_CALLBACK (authenticate_token), GUINT_TO_POINTER (35)); + g_signal_connect (module_with_auth, "authenticate-slot", G_CALLBACK (authenticate_token), GUINT_TO_POINTER (35)); /* Create a new session */ - new_session = gck_slot_open_session (slot, CKF_RW_SESSION, &err); + slot_with_auth = g_object_new (GCK_TYPE_SLOT, "module", module_with_auth, "handle", gck_slot_get_handle (slot), NULL); + new_session = gck_slot_open_session (slot_with_auth, CKF_RW_SESSION, &err); SUCCESS_RES (new_session, err); g_object_unref (new_session); /* Try again to do something that requires a login */ - object = gck_session_create_object (session, attrs, NULL, &err); + object = gck_session_create_object (new_session, attrs, NULL, &err); SUCCESS_RES (object, err); g_object_unref (object); /* We should now be logged in, try to log out */ - ret = gck_session_logout (session, &err); + ret = gck_session_logout (new_session, &err); SUCCESS_RES (ret, err); /* Now try the same thing, but asyncronously */ - gck_slot_open_session_async (slot, CKF_RW_SESSION, NULL, NULL, NULL, fetch_async_result, &result); + gck_slot_open_session_async (slot_with_auth, CKF_RW_SESSION, NULL, NULL, NULL, fetch_async_result, &result); testing_wait_until (500); g_assert (result != NULL); - new_session = gck_slot_open_session_finish (slot, result, &err); + new_session = gck_slot_open_session_finish (slot_with_auth, result, &err); SUCCESS_RES (new_session, err); g_object_unref (result); g_object_unref (new_session); result = NULL; - gck_session_create_object_async (session, attrs, NULL, fetch_async_result, &result); + gck_session_create_object_async (new_session, attrs, NULL, fetch_async_result, &result); testing_wait_until (500); g_assert (result != NULL); - object = gck_session_create_object_finish (session, result, &err); + object = gck_session_create_object_finish (new_session, result, &err); SUCCESS_RES (object, err); g_object_unref (result); g_object_unref (object); /* We should now be logged in, try to log out */ - ret = gck_session_logout (session, &err); + ret = gck_session_logout (new_session, &err); SUCCESS_RES (ret, err); - g_object_set (module, "options", 0, NULL); - g_assert_cmpuint (gck_module_get_options (module), ==, 0); + g_object_unref (slot_with_auth); + g_object_unref (module_with_auth); } diff --git a/gck/tests/test-gck-slot.c b/gck/tests/test-gck-slot.c index 6743508..3e4bd64 100644 --- a/gck/tests/test-gck-slot.c +++ b/gck/tests/test-gck-slot.c @@ -14,7 +14,7 @@ DEFINE_SETUP(load_slots) GList *slots; /* Successful load */ - module = gck_module_initialize (".libs/libgck-test-module.so", NULL, &err); + module = gck_module_initialize (".libs/libgck-test-module.so", NULL, 0, &err); SUCCESS_RES (module, err); slots = gck_module_get_slots (module, TRUE); @@ -111,7 +111,7 @@ DEFINE_TEST(slot_equals_hash) g_assert (gck_slot_equal (slot, slot)); - other_mod = gck_module_new (gck_module_get_functions (module)); + other_mod = gck_module_new (gck_module_get_functions (module), 0); other_slot = g_object_new (GCK_TYPE_SLOT, "module", other_mod, "handle", gck_slot_get_handle (slot), NULL); g_assert (gck_slot_equal (slot, other_slot)); g_object_unref (other_mod); |