summaryrefslogtreecommitdiff
path: root/pkcs11/wrap-layer
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-04-24 00:19:42 +0200
committerStef Walter <stefw@collabora.co.uk>2011-04-24 10:23:19 +0200
commit24983752cb3e452b255306695fd7217256add905 (patch)
tree87dc294d879dd565a250ed1e3b7cf7181c8b4a50 /pkcs11/wrap-layer
parenteedfc9755323f68a26c39ff2374a11dbc18ada32 (diff)
downloadgnome-keyring-24983752cb3e452b255306695fd7217256add905.tar.gz
Modernize the remainder of the tests.
* Bring up to date with gtester running and individual binaries. * Make the tests run in make distcheck
Diffstat (limited to 'pkcs11/wrap-layer')
-rw-r--r--pkcs11/wrap-layer/tests/Makefile.am52
-rw-r--r--pkcs11/wrap-layer/tests/mock-secret-store.c4
-rw-r--r--pkcs11/wrap-layer/tests/test-create-credential.c88
-rw-r--r--pkcs11/wrap-layer/tests/test-init-pin.c60
-rw-r--r--pkcs11/wrap-layer/tests/test-login-auto.c129
-rw-r--r--pkcs11/wrap-layer/tests/test-login-hints.c19
-rw-r--r--pkcs11/wrap-layer/tests/test-login-keyring.c92
-rw-r--r--pkcs11/wrap-layer/tests/test-login-specific.c74
-rw-r--r--pkcs11/wrap-layer/tests/test-login-user.c94
-rw-r--r--pkcs11/wrap-layer/tests/test-set-pin.c58
10 files changed, 433 insertions, 237 deletions
diff --git a/pkcs11/wrap-layer/tests/Makefile.am b/pkcs11/wrap-layer/tests/Makefile.am
index fb3ee7b6..bf4ab927 100644
--- a/pkcs11/wrap-layer/tests/Makefile.am
+++ b/pkcs11/wrap-layer/tests/Makefile.am
@@ -1,24 +1,40 @@
-TESTING_SOURCES = \
- mock-secret-store.c
-
-TESTING_FILES = \
- test-create-credential.c \
- test-init-pin.c \
- test-login-auto.c \
- test-login-hints.c \
- test-login-keyring.c \
- test-login-specific.c \
- test-login-user.c \
- test-set-pin.c
-
-TESTING_LIBS = \
+INCLUDES = \
+ -I$(top_builddir) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/pkcs11 \
+ -DSRCDIR="\"$(srcdir)\"" \
+ $(GLIB_CFLAGS) \
+ -DWITH_TESTABLE
+
+LDADD = \
$(top_builddir)/pkcs11/wrap-layer/libgkm-wrap-layer.la \
+ libgkm-mock-secret-store.a \
$(top_builddir)/pkcs11/gkm/libgkm.la \
$(top_builddir)/ui/libgku-prompt-testable.la \
- $(top_builddir)/egg/libegg.la
+ $(top_builddir)/egg/libegg.la \
+ $(GLIB_LIBS)
-TESTING_FLAGS = \
- -DWITH_TESTABLE
+TEST_PROGS = \
+ test-create-credential \
+ test-init-pin \
+ test-login-auto \
+ test-login-hints \
+ test-login-keyring \
+ test-login-specific \
+ test-login-user \
+ test-set-pin
+
+check_PROGRAMS = $(TEST_PROGS)
+
+test: $(TEST_PROGS) $(CHECK_PROGS)
+ gtester -k --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
+
+check-local: test
+
+all-local: $(check_PROGRAMS)
+
+noinst_LIBRARIES = libgkm-mock-secret-store.a
-include $(top_srcdir)/testing/testing.make \ No newline at end of file
+libgkm_mock_secret_store_a_SOURCES = \
+ mock-secret-store.c \ No newline at end of file
diff --git a/pkcs11/wrap-layer/tests/mock-secret-store.c b/pkcs11/wrap-layer/tests/mock-secret-store.c
index d724919f..cb57b7f3 100644
--- a/pkcs11/wrap-layer/tests/mock-secret-store.c
+++ b/pkcs11/wrap-layer/tests/mock-secret-store.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-secure-memory.h"
#include "gkm/gkm-attributes.h"
#include "gkm/gkm-mock.h"
@@ -33,6 +33,8 @@
static guint secret_identifier = 8800;
+EGG_SECURE_GLIB_DEFINITIONS ();
+
static CK_RV
mock_secret_C_Initialize (CK_VOID_PTR pInitArgs)
{
diff --git a/pkcs11/wrap-layer/tests/test-create-credential.c b/pkcs11/wrap-layer/tests/test-create-credential.c
index c4e7bd6a..5a3b7c9a 100644
--- a/pkcs11/wrap-layer/tests/test-create-credential.c
+++ b/pkcs11/wrap-layer/tests/test-create-credential.c
@@ -21,21 +21,26 @@
#include "config.h"
-#include "test-suite.h"
-
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
+#include "egg/egg-testing.h"
+
#include "wrap-layer/gkm-wrap-layer.h"
#include "ui/gku-prompt.h"
-static CK_FUNCTION_LIST test_functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
-static CK_OBJECT_HANDLE object = 0;
+#include <string.h>
+
+typedef struct {
+ CK_FUNCTION_LIST functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+ CK_OBJECT_HANDLE object;
+} Test;
-TESTING_SETUP (create_credential)
+static void
+setup (Test *test, gconstpointer unused)
{
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
@@ -51,60 +56,58 @@ TESTING_SETUP (create_credential)
/* Always start off with test functions */
rv = gkm_mock_C_GetFunctionList (&funcs);
gkm_assert_cmprv (rv, ==, CKR_OK);
- memcpy (&test_functions, funcs, sizeof (test_functions));
+ memcpy (&test->functions, funcs, sizeof (test->functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&test_functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- /* Find the always authenticate object */
- rv = (module->C_FindObjectsInit) (session, attrs, 1);
+ /* Find the always authenticate test->object */
+ rv = (test->module->C_FindObjectsInit) (test->session, attrs, 1);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_FindObjects) (session, &object, 1, &count);
+ rv = (test->module->C_FindObjects) (test->session, &test->object, 1, &count);
gkm_assert_cmprv (rv, ==, CKR_OK);
gkm_assert_cmpulong (count, ==, 1);
- gkm_assert_cmpulong (object, !=, 0);
+ gkm_assert_cmpulong (test->object, !=, 0);
- rv = (module->C_FindObjectsFinal) (session);
+ rv = (test->module->C_FindObjectsFinal) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (create_credential)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- object = 0;
-
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
}
-TESTING_TEST (create_credential_ok_password)
+static void
+test_ok_password (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
- { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_G_OBJECT, &test->object, sizeof (test->object) },
{ CKA_VALUE, NULL, 0 }
};
@@ -113,17 +116,18 @@ TESTING_TEST (create_credential_ok_password)
gku_prompt_dummy_queue_ok_password ("booo");
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_OK);
gkm_assert_cmpulong (cred, !=, 0);
}
-TESTING_TEST (create_credential_bad_password_then_cancel)
+static void
+test_bad_password_then_cancel (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
- { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_G_OBJECT, &test->object, sizeof (test->object) },
{ CKA_VALUE, NULL, 0 }
};
@@ -133,16 +137,17 @@ TESTING_TEST (create_credential_bad_password_then_cancel)
gku_prompt_dummy_queue_ok_password ("bad password");
gku_prompt_dummy_queue_no ();
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (create_credentiaol_cancel_immediately)
+static void
+test_cancel_immediately (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
- { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_G_OBJECT, &test->object, sizeof (test->object) },
{ CKA_VALUE, NULL, 0 }
};
@@ -151,6 +156,19 @@ TESTING_TEST (create_credentiaol_cancel_immediately)
gku_prompt_dummy_queue_no ();
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/create-credential/ok_password", Test, NULL, setup, test_ok_password, teardown);
+ g_test_add ("/wrap-layer/create-credential/bad_password_then_cancel", Test, NULL, setup, test_bad_password_then_cancel, teardown);
+ g_test_add ("/wrap-layer/create-credential/cancel_immediately", Test, NULL, setup, test_cancel_immediately, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-init-pin.c b/pkcs11/wrap-layer/tests/test-init-pin.c
index 58b02c58..1f9e7a15 100644
--- a/pkcs11/wrap-layer/tests/test-init-pin.c
+++ b/pkcs11/wrap-layer/tests/test-init-pin.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
@@ -30,63 +30,81 @@
#include "ui/gku-prompt.h"
-static CK_FUNCTION_LIST functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
+#include <string.h>
-TESTING_SETUP (init_pin)
+typedef struct {
+ CK_FUNCTION_LIST functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
{
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
CK_RV rv;
- /* Always start off with test functions */
+ /* Always start off with test test->functions */
rv = gkm_mock_C_GetFunctionList (&funcs);
gkm_assert_cmprv (rv, ==, CKR_OK);
- memcpy (&functions, funcs, sizeof (functions));
+ memcpy (&test->functions, funcs, sizeof (test->functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (init_pin)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
+ test->session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (init_pin_ok_password)
+static void
+test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_password ("new");
- rv = (module->C_InitPIN) (session, NULL, 0);
+ rv = (test->module->C_InitPIN) (test->session, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_Login) (session, CKU_USER, (guchar*)"new", 3);
+ rv = (test->module->C_Login) (test->session, CKU_USER, (guchar*)"new", 3);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/init-pin/ok_password", Test, NULL, setup, test_ok_password, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-auto.c b/pkcs11/wrap-layer/tests/test-login-auto.c
index 56bcfc21..8ab80d9e 100644
--- a/pkcs11/wrap-layer/tests/test-login-auto.c
+++ b/pkcs11/wrap-layer/tests/test-login-auto.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
@@ -30,15 +30,21 @@
#include "ui/gku-prompt.h"
+#include <string.h>
+
extern CK_FUNCTION_LIST mock_secret_store;
-static CK_FUNCTION_LIST functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
-static CK_OBJECT_HANDLE key = 0;
-static CK_OBJECT_HANDLE collection = 0;
-static CK_MECHANISM mech = { CKM_MOCK_PREFIX, NULL, 0 };
-
-TESTING_SETUP (login_auto)
+
+typedef struct {
+ CK_FUNCTION_LIST functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+ CK_OBJECT_HANDLE key;
+ CK_OBJECT_HANDLE collection;
+ CK_MECHANISM mech;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
{
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
@@ -56,115 +62,120 @@ TESTING_SETUP (login_auto)
{ CKA_ID, "other", 5 },
};
- /* Always start off with test functions */
- memcpy (&functions, &mock_secret_store, sizeof (functions));
+ test->mech.mechanism = CKM_MOCK_PREFIX;
+
+ /* Always start off with test test->functions */
+ memcpy (&test->functions, &mock_secret_store, sizeof (test->functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Find keyring object */
- rv = (module->C_FindObjectsInit) (session, fattrs, 1);
+ rv = (test->module->C_FindObjectsInit) (test->session, fattrs, 1);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_FindObjects) (session, &collection, 1, &count);
+ rv = (test->module->C_FindObjects) (test->session, &test->collection, 1, &count);
gkm_assert_cmprv (rv, ==, CKR_OK);
gkm_assert_cmpulong (count, ==, 1);
- gkm_assert_cmpulong (collection, !=, 0);
- rv = (module->C_FindObjectsFinal) (session);
+ gkm_assert_cmpulong (test->collection, !=, 0);
+ rv = (test->module->C_FindObjectsFinal) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- /* Find the key object */
- rv = (module->C_FindObjectsInit) (session, kattrs, 1);
+ /* Find the test->key object */
+ rv = (test->module->C_FindObjectsInit) (test->session, kattrs, 1);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_FindObjects) (session, &key, 1, &count);
+ rv = (test->module->C_FindObjects) (test->session, &test->key, 1, &count);
gkm_assert_cmprv (rv, ==, CKR_OK);
gkm_assert_cmpulong (count, ==, 1);
- gkm_assert_cmpulong (key, !=, 0);
- rv = (module->C_FindObjectsFinal) (session);
+ gkm_assert_cmpulong (test->key, !=, 0);
+ rv = (test->module->C_FindObjectsFinal) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Start a signing operation, that needs to be authenticated */
- rv = (module->C_SignInit) (session, &mech, key);
+ rv = (test->module->C_SignInit) (test->session, &test->mech, test->key);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (login_auto)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- key = 0;
- collection = 0;
+ test->key = 0;
+ test->collection = 0;
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
+ test->session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (login_auto_specific)
+static void
+test_specific (Test *test, gconstpointer unused)
{
CK_RV rv;
/* Login with prompt */
gku_prompt_dummy_queue_auto_password ("booo");
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Start a signing operation, that needs to be authenticated */
- rv = (module->C_SignInit) (session, &mech, key);
+ rv = (test->module->C_SignInit) (test->session, &test->mech, test->key);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
gku_prompt_dummy_prepare_response ();
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Change the password */
gkm_mock_module_set_pin ("other");
/* Start a signing operation, that needs to be authenticated */
- rv = (module->C_SignInit) (session, &mech, key);
+ rv = (test->module->C_SignInit) (test->session, &test->mech, test->key);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* This should prompt again, as stored password is now wrong */
gku_prompt_dummy_queue_ok_password ("other");
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEST (login_auto_user_token)
+static void
+test_user_token (Test *test, gconstpointer unused)
{
CK_RV rv;
/* Login with prompt */
gku_prompt_dummy_queue_auto_password ("booo");
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_Logout) (session);
+ rv = (test->module->C_Logout) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
gku_prompt_dummy_prepare_response ();
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_Logout) (session);
+ rv = (test->module->C_Logout) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Change the password */
@@ -172,11 +183,12 @@ TESTING_TEST (login_auto_user_token)
/* This should prompt again, as stored password is now wrong */
gku_prompt_dummy_queue_ok_password ("other");
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEST (login_auto_unlock_keyring)
+static void
+test_unlock_keyring (Test *test, gconstpointer unused)
{
CK_OBJECT_HANDLE credential;
CK_RV rv;
@@ -185,19 +197,19 @@ TESTING_TEST (login_auto_unlock_keyring)
CK_ATTRIBUTE attrs[] = {
{ CKA_CLASS, &klass, sizeof (klass) },
{ CKA_VALUE, NULL, 0 },
- { CKA_G_OBJECT, &collection, sizeof (collection) },
+ { CKA_G_OBJECT, &test->collection, sizeof (test->collection) },
};
/* Create credential with prompt */
gku_prompt_dummy_queue_auto_password ("booo");
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &credential);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_DestroyObject) (session, credential);
+ rv = (test->module->C_DestroyObject) (test->session, credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
gku_prompt_dummy_prepare_response ();
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &credential);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Change the password */
@@ -205,6 +217,19 @@ TESTING_TEST (login_auto_unlock_keyring)
/* This should prompt again, as stored password is now wrong */
gku_prompt_dummy_queue_ok_password ("other");
- rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &credential);
+ rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/login-auto/specific", Test, NULL, setup, test_specific, teardown);
+ g_test_add ("/wrap-layer/login-auto/user_token", Test, NULL, setup, test_user_token, teardown);
+ g_test_add ("/wrap-layer/login-auto/unlock_keyring", Test, NULL, setup, test_unlock_keyring, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-hints.c b/pkcs11/wrap-layer/tests/test-login-hints.c
index eb8d1359..48bb8309 100644
--- a/pkcs11/wrap-layer/tests/test-login-hints.c
+++ b/pkcs11/wrap-layer/tests/test-login-hints.c
@@ -21,14 +21,16 @@
#include "config.h"
-#include "test-suite.h"
-
#include "egg/egg-secure-memory.h"
+#include "egg/egg-testing.h"
#include "wrap-layer/gkm-wrap-layer.h"
#include "wrap-layer/gkm-wrap-login.h"
-TESTING_TEST (login_did_unlock_fail)
+#include <glib-object.h>
+
+static void
+test_did_unlock_fail (void)
{
gchar *password;
gboolean ret;
@@ -49,3 +51,14 @@ TESTING_TEST (login_did_unlock_fail)
ret = gkm_wrap_login_did_unlock_fail ();
g_assert (ret == FALSE);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/wrap-layer/login-hints/did_unlock_fail", test_did_unlock_fail);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-keyring.c b/pkcs11/wrap-layer/tests/test-login-keyring.c
index ad430018..3c8fe5b6 100644
--- a/pkcs11/wrap-layer/tests/test-login-keyring.c
+++ b/pkcs11/wrap-layer/tests/test-login-keyring.c
@@ -21,9 +21,8 @@
#include "config.h"
-#include "test-suite.h"
-
#include "egg/egg-secure-memory.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-attributes.h"
#include "gkm/gkm-mock.h"
@@ -32,35 +31,43 @@
#include "wrap-layer/gkm-wrap-layer.h"
#include "wrap-layer/gkm-wrap-login.h"
+#include <glib-object.h>
+
extern CK_FUNCTION_LIST mock_secret_store;
-static CK_FUNCTION_LIST functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-TESTING_SETUP (login_keyring)
+typedef struct {
+ CK_FUNCTION_LIST functions;
+ CK_FUNCTION_LIST_PTR module;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
{
CK_RV rv;
- /* Always start off with test functions */
- memcpy (&functions, &mock_secret_store, sizeof (functions));
+ /* Always start off with test test->functions */
+ memcpy (&test->functions, &mock_secret_store, sizeof (test->functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->functions);
+ test->module = gkm_wrap_layer_get_functions ();
/* Initialize */
- rv = (module->C_Initialize) (NULL);
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (login_keyring)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (login_is_usable)
+static void
+test_is_usable (Test *test, gconstpointer unused)
{
gboolean ret;
@@ -68,16 +75,18 @@ TESTING_TEST (login_is_usable)
g_assert (ret == TRUE);
}
-TESTING_TEST (login_usable_fail_open_session)
+static void
+test_usable_fail_open_session (Test *test, gconstpointer unused)
{
gboolean ret;
- functions.C_OpenSession = gkm_mock_fail_C_OpenSession;
+ test->functions.C_OpenSession = gkm_mock_fail_C_OpenSession;
ret = gkm_wrap_login_is_usable ();
g_assert (ret == FALSE);
}
-TESTING_TEST (login_usable_fail_not_trusted)
+static void
+test_usable_fail_not_trusted (Test *test, gconstpointer unused)
{
CK_OBJECT_HANDLE object;
CK_ATTRIBUTE attr;
@@ -107,7 +116,8 @@ TESTING_TEST (login_usable_fail_not_trusted)
g_assert (ret == FALSE);
}
-TESTING_TEST (login_usable_fail_locked)
+static void
+test_usable_fail_locked (Test *test, gconstpointer unused)
{
CK_OBJECT_HANDLE object;
CK_ATTRIBUTE attr;
@@ -137,7 +147,8 @@ TESTING_TEST (login_usable_fail_locked)
g_assert (ret == FALSE);
}
-TESTING_TEST (login_lookup_secret_no_match)
+static void
+test_lookup_secret_no_match (Test *test, gconstpointer unused)
{
gchar *password;
@@ -146,7 +157,8 @@ TESTING_TEST (login_lookup_secret_no_match)
g_assert_cmpstr (password, ==, NULL);
}
-TESTING_TEST (login_lookup_secret_and_match)
+static void
+test_lookup_secret_and_match (Test *test, gconstpointer unused)
{
gchar *password;
@@ -158,7 +170,8 @@ TESTING_TEST (login_lookup_secret_and_match)
egg_secure_free (password);
}
-TESTING_TEST (login_lookup_store_secret)
+static void
+test_lookup_store_secret (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
CK_BBOOL tval = CK_TRUE;
@@ -182,7 +195,8 @@ TESTING_TEST (login_lookup_store_secret)
gkm_assert_cmpulong (object, !=, 0);
}
-TESTING_TEST (login_lookup_store_secret_overwrite)
+static void
+test_lookup_store_secret_overwrite (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
CK_BBOOL tval = CK_TRUE;
@@ -220,7 +234,8 @@ TESTING_TEST (login_lookup_store_secret_overwrite)
gkm_assert_cmpulong (object1, ==, object2);
}
-TESTING_TEST (login_lookup_store_null_secret)
+static void
+test_lookup_store_null_secret (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
CK_BBOOL tval = CK_TRUE;
@@ -243,7 +258,8 @@ TESTING_TEST (login_lookup_store_null_secret)
gkm_assert_cmpulong (object, !=, 0);
}
-TESTING_TEST (login_lookup_store_no_attributes_not_stored)
+static void
+test_lookup_store_no_attributes_not_stored (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
CK_BBOOL tval = CK_TRUE;
@@ -265,7 +281,8 @@ TESTING_TEST (login_lookup_store_no_attributes_not_stored)
}
-TESTING_TEST (login_lookup_remove_present)
+static void
+test_lookup_remove_present (Test *test, gconstpointer unused)
{
CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
CK_BBOOL tval = CK_TRUE;
@@ -291,7 +308,8 @@ TESTING_TEST (login_lookup_remove_present)
gkm_assert_cmpulong (object, ==, 0);
}
-TESTING_TEST (login_lookup_remove_no_attributes)
+static void
+test_lookup_remove_no_attributes (Test *test, gconstpointer unused)
{
guint n_objects, check;
@@ -304,3 +322,25 @@ TESTING_TEST (login_lookup_remove_no_attributes)
check = gkm_mock_module_count_objects (0);
g_assert_cmpuint (check, ==, n_objects);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/login-keyring/is_usable", Test, NULL, setup, test_is_usable, teardown);
+ g_test_add ("/wrap-layer/login-keyring/usable_fail_open_session", Test, NULL, setup, test_usable_fail_open_session, teardown);
+ g_test_add ("/wrap-layer/login-keyring/usable_fail_not_trusted", Test, NULL, setup, test_usable_fail_not_trusted, teardown);
+ g_test_add ("/wrap-layer/login-keyring/usable_fail_locked", Test, NULL, setup, test_usable_fail_locked, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_secret_no_match", Test, NULL, setup, test_lookup_secret_no_match, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_secret_and_match", Test, NULL, setup, test_lookup_secret_and_match, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_store_secret", Test, NULL, setup, test_lookup_store_secret, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_store_secret_overwrite", Test, NULL, setup, test_lookup_store_secret_overwrite, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_store_null_secret", Test, NULL, setup, test_lookup_store_null_secret, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_store_no_attributes_not_stored", Test, NULL, setup, test_lookup_store_no_attributes_not_stored, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_remove_present", Test, NULL, setup, test_lookup_remove_present, teardown);
+ g_test_add ("/wrap-layer/login-keyring/lookup_remove_no_attributes", Test, NULL, setup, test_lookup_remove_no_attributes, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-specific.c b/pkcs11/wrap-layer/tests/test-login-specific.c
index 3957404c..a91480e5 100644
--- a/pkcs11/wrap-layer/tests/test-login-specific.c
+++ b/pkcs11/wrap-layer/tests/test-login-specific.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
@@ -30,11 +30,14 @@
#include "ui/gku-prompt.h"
-static CK_FUNCTION_LIST prompt_login_functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
+typedef struct {
+ CK_FUNCTION_LIST prompt_login_functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+} Test;
-TESTING_SETUP (login_specific)
+static void
+setup (Test *test, gconstpointer unused)
{
CK_FUNCTION_LIST_PTR funcs;
CK_OBJECT_HANDLE key;
@@ -53,83 +56,100 @@ TESTING_SETUP (login_specific)
/* Always start off with test functions */
rv = gkm_mock_C_GetFunctionList (&funcs);
gkm_assert_cmprv (rv, ==, CKR_OK);
- memcpy (&prompt_login_functions, funcs, sizeof (prompt_login_functions));
+ memcpy (&test->prompt_login_functions, funcs, sizeof (test->prompt_login_functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&prompt_login_functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->prompt_login_functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Find the always authenticate object */
- rv = (module->C_FindObjectsInit) (session, attrs, 1);
+ rv = (test->module->C_FindObjectsInit) (test->session, attrs, 1);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_FindObjects) (session, &key, 1, &count);
+ rv = (test->module->C_FindObjects) (test->session, &key, 1, &count);
gkm_assert_cmprv (rv, ==, CKR_OK);
gkm_assert_cmpulong (count, ==, 1);
gkm_assert_cmpulong (key, !=, 0);
- rv = (module->C_FindObjectsFinal) (session);
+ rv = (test->module->C_FindObjectsFinal) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* Start a signing operation, that needs to be authenticated */
- rv = (module->C_SignInit) (session, &mech, key);
+ rv = (test->module->C_SignInit) (test->session, &mech, key);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (login_specific)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
+ test->session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (login_specific_ok_password)
+static void
+test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_password ("booo");
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEST (login_specific_bad_password_then_cancel)
+static void
+test_bad_password_then_cancel (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_password ("bad password");
gku_prompt_dummy_queue_no ();
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (login_specific_cancel_immediately)
+static void
+test_cancel_immediately (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_no ();
- rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/login-specific/ok_password", Test, NULL, setup, test_ok_password, teardown);
+ g_test_add ("/wrap-layer/login-specific/bad_password_then_cancel", Test, NULL, setup, test_bad_password_then_cancel, teardown);
+ g_test_add ("/wrap-layer/login-specific/cancel_immediately", Test, NULL, setup, test_cancel_immediately, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-user.c b/pkcs11/wrap-layer/tests/test-login-user.c
index d2d47c4f..61bd34cc 100644
--- a/pkcs11/wrap-layer/tests/test-login-user.c
+++ b/pkcs11/wrap-layer/tests/test-login-user.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
@@ -30,11 +30,14 @@
#include "ui/gku-prompt.h"
-static CK_FUNCTION_LIST prompt_login_functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
+typedef struct {
+ CK_FUNCTION_LIST prompt_login_functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+} Test;
-TESTING_SETUP (login_user)
+static void
+setup (Test *test, gconstpointer unused)
{
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
@@ -44,101 +47,126 @@ TESTING_SETUP (login_user)
/* Always start off with test functions */
rv = gkm_mock_C_GetFunctionList (&funcs);
gkm_assert_cmprv (rv, ==, CKR_OK);
- memcpy (&prompt_login_functions, funcs, sizeof (prompt_login_functions));
+ memcpy (&test->prompt_login_functions, funcs, sizeof (test->prompt_login_functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&prompt_login_functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->prompt_login_functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (login_user)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
+ test->session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (login_fail_unsupported_so)
+static void
+test_fail_unsupported_so (Test *test, gconstpointer unused)
{
CK_RV rv;
- rv = (module->C_Login) (session, CKU_SO, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_SO, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (login_skip_prompt_because_pin)
+static void
+test_skip_prompt_because_pin (Test *test, gconstpointer unused)
{
CK_RV rv;
- rv = (module->C_Login) (session, CKU_USER, (guchar*)"booo", 4);
+ rv = (test->module->C_Login) (test->session, CKU_USER, (guchar*)"booo", 4);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEST (login_user_ok_password)
+static void
+test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_password ("booo");
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEST (login_user_bad_password_then_cancel)
+static void
+test_bad_password_then_cancel (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_password ("bad password");
gku_prompt_dummy_queue_no ();
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (login_user_cancel_immediately)
+static void
+test_cancel_immediately (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_no ();
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (login_user_fail_get_session_info)
+static void
+test_fail_get_session_info (Test *test, gconstpointer unused)
{
CK_RV rv;
- prompt_login_functions.C_GetSessionInfo = gkm_mock_fail_C_GetSessionInfo;
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ test->prompt_login_functions.C_GetSessionInfo = gkm_mock_fail_C_GetSessionInfo;
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
-TESTING_TEST (login_user_fail_get_token_info)
+static void
+test_fail_get_token_info (Test *test, gconstpointer unused)
{
CK_RV rv;
- prompt_login_functions.C_GetTokenInfo = gkm_mock_fail_C_GetTokenInfo;
- rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ test->prompt_login_functions.C_GetTokenInfo = gkm_mock_fail_C_GetTokenInfo;
+ rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/login-user/fail_unsupported_so", Test, NULL, setup, test_fail_unsupported_so, teardown);
+ g_test_add ("/wrap-layer/login-user/skip_prompt_because_pin", Test, NULL, setup, test_skip_prompt_because_pin, teardown);
+ g_test_add ("/wrap-layer/login-user/ok_password", Test, NULL, setup, test_ok_password, teardown);
+ g_test_add ("/wrap-layer/login-user/bad_password_then_cancel", Test, NULL, setup, test_bad_password_then_cancel, teardown);
+ g_test_add ("/wrap-layer/login-user/cancel_immediately", Test, NULL, setup, test_cancel_immediately, teardown);
+ g_test_add ("/wrap-layer/login-user/fail_get_session_info", Test, NULL, setup, test_fail_get_session_info, teardown);
+ g_test_add ("/wrap-layer/login-user/fail_get_token_info", Test, NULL, setup, test_fail_get_token_info, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}
diff --git a/pkcs11/wrap-layer/tests/test-set-pin.c b/pkcs11/wrap-layer/tests/test-set-pin.c
index 766f8b89..164bde1c 100644
--- a/pkcs11/wrap-layer/tests/test-set-pin.c
+++ b/pkcs11/wrap-layer/tests/test-set-pin.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "test-suite.h"
+#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
@@ -30,63 +30,79 @@
#include "ui/gku-prompt.h"
-static CK_FUNCTION_LIST functions;
-static CK_FUNCTION_LIST_PTR module = NULL;
-static CK_SESSION_HANDLE session = 0;
+typedef struct {
+ CK_FUNCTION_LIST functions;
+ CK_FUNCTION_LIST_PTR module;
+ CK_SESSION_HANDLE session;
+} Test;
-TESTING_SETUP (set_pin)
+static void
+setup (Test *test, gconstpointer unused)
{
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
CK_RV rv;
- /* Always start off with test functions */
+ /* Always start off with test test->functions */
rv = gkm_mock_C_GetFunctionList (&funcs);
gkm_assert_cmprv (rv, ==, CKR_OK);
- memcpy (&functions, funcs, sizeof (functions));
+ memcpy (&test->functions, funcs, sizeof (test->functions));
gkm_wrap_layer_reset_modules ();
- gkm_wrap_layer_add_module (&functions);
- module = gkm_wrap_layer_get_functions ();
+ gkm_wrap_layer_add_module (&test->functions);
+ test->module = gkm_wrap_layer_get_functions ();
gku_prompt_dummy_prepare_response ();
- /* Open a session */
- rv = (module->C_Initialize) (NULL);
+ /* Open a test->session */
+ rv = (test->module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-TESTING_TEARDOWN (set_pin)
+static void
+teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
g_assert (!gku_prompt_dummy_have_response ());
- rv = (module->C_CloseSession) (session);
+ rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
- session = 0;
+ test->session = 0;
- rv = (module->C_Finalize) (NULL);
+ rv = (test->module->C_Finalize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
- module = NULL;
+ test->module = NULL;
}
-TESTING_TEST (set_pin_ok_passwords)
+static void
+test_ok_passwords (Test *test, gconstpointer unused)
{
CK_RV rv;
gku_prompt_dummy_queue_ok_passwords ("booo", "new");
- rv = (module->C_SetPIN) (session, NULL, 0, NULL, 0);
+ rv = (test->module->C_SetPIN) (test->session, NULL, 0, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
- rv = (module->C_Login) (session, CKU_USER, (guchar*)"new", 3);
+ rv = (test->module->C_Login) (test->session, CKU_USER, (guchar*)"new", 3);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/wrap-layer/set-pin/ok_passwords", Test, NULL, setup, test_ok_passwords, teardown);
+
+ return egg_tests_run_in_thread_with_loop ();
+}