53
60
/* Always start off with test functions */
54
61
rv = gkm_mock_C_GetFunctionList (&funcs);
55
62
gkm_assert_cmprv (rv, ==, CKR_OK);
56
memcpy (&prompt_login_functions, funcs, sizeof (prompt_login_functions));
63
memcpy (&test->prompt_login_functions, funcs, sizeof (test->prompt_login_functions));
58
65
gkm_wrap_layer_reset_modules ();
59
gkm_wrap_layer_add_module (&prompt_login_functions);
60
module = gkm_wrap_layer_get_functions ();
62
gku_prompt_dummy_prepare_response ();
65
rv = (module->C_Initialize) (NULL);
66
gkm_assert_cmprv (rv, ==, CKR_OK);
68
rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
69
gkm_assert_cmprv (rv, ==, CKR_OK);
71
rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
66
gkm_wrap_layer_add_module (&test->prompt_login_functions);
67
test->module = gkm_wrap_layer_get_functions ();
69
prompter = gcr_mock_prompter_start ();
70
gkm_wrap_prompt_set_prompter_name (prompter);
72
/* Open a test->session */
73
rv = (test->module->C_Initialize) (NULL);
74
gkm_assert_cmprv (rv, ==, CKR_OK);
76
rv = (test->module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
77
gkm_assert_cmprv (rv, ==, CKR_OK);
79
rv = (test->module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &test->session);
72
80
gkm_assert_cmprv (rv, ==, CKR_OK);
74
82
/* Find the always authenticate object */
75
rv = (module->C_FindObjectsInit) (session, attrs, 1);
83
rv = (test->module->C_FindObjectsInit) (test->session, attrs, 1);
76
84
gkm_assert_cmprv (rv, ==, CKR_OK);
78
rv = (module->C_FindObjects) (session, &key, 1, &count);
86
rv = (test->module->C_FindObjects) (test->session, &key, 1, &count);
79
87
gkm_assert_cmprv (rv, ==, CKR_OK);
80
88
gkm_assert_cmpulong (count, ==, 1);
81
89
gkm_assert_cmpulong (key, !=, 0);
83
rv = (module->C_FindObjectsFinal) (session);
91
rv = (test->module->C_FindObjectsFinal) (test->session);
84
92
gkm_assert_cmprv (rv, ==, CKR_OK);
86
94
/* Start a signing operation, that needs to be authenticated */
87
rv = (module->C_SignInit) (session, &mech, key);
88
gkm_assert_cmprv (rv, ==, CKR_OK);
91
TESTING_TEARDOWN (login_specific)
95
g_assert (!gku_prompt_dummy_have_response ());
97
rv = (module->C_CloseSession) (session);
98
gkm_assert_cmprv (rv, ==, CKR_OK);
101
rv = (module->C_Finalize) (NULL);
102
gkm_assert_cmprv (rv, ==, CKR_OK);
106
TESTING_TEST (login_specific_ok_password)
110
gku_prompt_dummy_queue_ok_password ("booo");
112
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
113
gkm_assert_cmprv (rv, ==, CKR_OK);
116
TESTING_TEST (login_specific_bad_password_then_cancel)
120
gku_prompt_dummy_queue_ok_password ("bad password");
121
gku_prompt_dummy_queue_no ();
123
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
124
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
127
TESTING_TEST (login_specific_cancel_immediately)
131
gku_prompt_dummy_queue_no ();
133
rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
134
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
95
rv = (test->module->C_SignInit) (test->session, &mech, key);
96
gkm_assert_cmprv (rv, ==, CKR_OK);
100
teardown (Test *test, gconstpointer unused)
104
g_assert (!gcr_mock_prompter_is_expecting ());
105
gcr_mock_prompter_stop ();
107
rv = (test->module->C_CloseSession) (test->session);
108
gkm_assert_cmprv (rv, ==, CKR_OK);
111
rv = (test->module->C_Finalize) (NULL);
112
gkm_assert_cmprv (rv, ==, CKR_OK);
117
test_ok_password (Test *test, gconstpointer unused)
121
gcr_mock_prompter_expect_password_ok ("booo", NULL);
123
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
124
gkm_assert_cmprv (rv, ==, CKR_OK);
128
test_bad_password_then_cancel (Test *test, gconstpointer unused)
132
gcr_mock_prompter_expect_password_ok ("bad password", NULL);
133
gcr_mock_prompter_expect_password_cancel ();
135
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
136
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
140
test_cancel_immediately (Test *test, gconstpointer unused)
144
gcr_mock_prompter_expect_password_cancel ();
146
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
147
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
151
main (int argc, char **argv)
154
g_test_init (&argc, &argv, NULL);
156
g_test_add ("/wrap-layer/login-specific/ok_password", Test, NULL, setup, test_ok_password, teardown);
157
g_test_add ("/wrap-layer/login-specific/bad_password_then_cancel", Test, NULL, setup, test_bad_password_then_cancel, teardown);
158
g_test_add ("/wrap-layer/login-specific/cancel_immediately", Test, NULL, setup, test_cancel_immediately, teardown);
160
return egg_tests_run_in_thread_with_loop ();