summaryrefslogtreecommitdiff
path: root/pkcs11/wrap-layer
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2010-06-08 20:38:10 +0000
committerStef Walter <stef@memberwebs.com>2010-06-08 20:38:10 +0000
commitf6e4268ef31f1d8f70e9963dfa436a8ef685d7af (patch)
treeb53f414c4698981753fea735cbe9c8f1b83f7c1e /pkcs11/wrap-layer
parent41a78ce2a9ef32f31b335afd7795d79557c8914c (diff)
downloadgnome-keyring-f6e4268ef31f1d8f70e9963dfa436a8ef685d7af.tar.gz
Implement some testing of creating credentials.
Diffstat (limited to 'pkcs11/wrap-layer')
-rw-r--r--pkcs11/wrap-layer/tests/Makefile.am1
-rw-r--r--pkcs11/wrap-layer/tests/test-create-credential.c153
-rw-r--r--pkcs11/wrap-layer/tests/test-login-specific.c4
3 files changed, 156 insertions, 2 deletions
diff --git a/pkcs11/wrap-layer/tests/Makefile.am b/pkcs11/wrap-layer/tests/Makefile.am
index 621384ac..ae531a65 100644
--- a/pkcs11/wrap-layer/tests/Makefile.am
+++ b/pkcs11/wrap-layer/tests/Makefile.am
@@ -1,5 +1,6 @@
TESTING_FILES = \
+ test-create-credential.c \
test-login-user.c \
test-login-specific.c
diff --git a/pkcs11/wrap-layer/tests/test-create-credential.c b/pkcs11/wrap-layer/tests/test-create-credential.c
new file mode 100644
index 00000000..a84097f2
--- /dev/null
+++ b/pkcs11/wrap-layer/tests/test-create-credential.c
@@ -0,0 +1,153 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2010 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "test-suite.h"
+
+#include "gkm/gkm-test.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;
+
+DEFINE_SETUP (create_credential)
+{
+ CK_FUNCTION_LIST_PTR funcs;
+ CK_SLOT_ID slot_id;
+ CK_ULONG n_slots = 1;
+ CK_ULONG count;
+ CK_RV rv;
+
+ CK_BBOOL always = TRUE;
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_ALWAYS_AUTHENTICATE, &always, sizeof (always) }
+ };
+
+ /* Always start off with test functions */
+ rv = gkm_test_C_GetFunctionList (&funcs);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ 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 ();
+
+ gku_prompt_dummy_prepare_response ();
+
+ /* Open a session */
+ rv = (module->C_Initialize) (NULL);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ rv = (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);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ /* Find the always authenticate object */
+ rv = (module->C_FindObjectsInit) (session, attrs, 1);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ rv = (module->C_FindObjects) (session, &object, 1, &count);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ gkm_assert_cmpulong (count, ==, 1);
+ gkm_assert_cmpulong (object, !=, 0);
+
+ rv = (module->C_FindObjectsFinal) (session);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+}
+
+DEFINE_TEARDOWN (create_credential)
+{
+ CK_RV rv;
+
+ object = 0;
+
+ rv = (module->C_CloseSession) (session);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ session = 0;
+
+ rv = (module->C_Finalize) (NULL);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ module = NULL;
+}
+
+DEFINE_TEST (create_credential_ok_password)
+{
+ CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_VALUE, NULL, 0 }
+ };
+
+ CK_OBJECT_HANDLE cred = 0;
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_ok_password ("booo");
+
+ rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ gkm_assert_cmpulong (cred, !=, 0);
+}
+
+DEFINE_TEST (create_credential_bad_password_then_cancel)
+{
+ CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_VALUE, NULL, 0 }
+ };
+
+ CK_OBJECT_HANDLE cred = 0;
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_ok_password ("bad password");
+ gku_prompt_dummy_queue_no ();
+
+ rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
+
+DEFINE_TEST (create_credentiaol_cancel_immediately)
+{
+ CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_G_OBJECT, &object, sizeof (object) },
+ { CKA_VALUE, NULL, 0 }
+ };
+
+ CK_OBJECT_HANDLE cred = 0;
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_no ();
+
+ rv = (module->C_CreateObject) (session, attrs, G_N_ELEMENTS (attrs), &cred);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
diff --git a/pkcs11/wrap-layer/tests/test-login-specific.c b/pkcs11/wrap-layer/tests/test-login-specific.c
index ce97e38e..c436d070 100644
--- a/pkcs11/wrap-layer/tests/test-login-specific.c
+++ b/pkcs11/wrap-layer/tests/test-login-specific.c
@@ -76,8 +76,8 @@ DEFINE_SETUP (login_specific)
rv = (module->C_FindObjects) (session, &key, 1, &count);
gkm_assert_cmprv (rv, ==, CKR_OK);
- g_assert (count == 1);
- g_assert (key != 0);
+ gkm_assert_cmpulong (count, ==, 1);
+ gkm_assert_cmpulong (key, !=, 0);
rv = (module->C_FindObjectsFinal) (session);
gkm_assert_cmprv (rv, ==, CKR_OK);