Line data Source code
1 : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 : /* test-secret-test->collection.c: Test the test->collection keyring
3 :
4 : Copyright (C) 2009 Stefan Walter
5 :
6 : The Gnome Keyring Library is free software; you can redistribute it and/or
7 : modify it under the terms of the GNU Library General Public License as
8 : published by the Free Software Foundation; either version 2 of the
9 : License, or (at your option) any later version.
10 :
11 : The Gnome Keyring Library is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Library General Public License for more details.
15 :
16 : You should have received a copy of the GNU Library General Public
17 : License along with the Gnome Library; see the file COPYING.LIB. If not,
18 : <http://www.gnu.org/licenses/>.
19 :
20 : Author: Stef Walter <stef@memberwebs.com>
21 : */
22 :
23 : #include "config.h"
24 :
25 : #include "mock-secret-module.h"
26 :
27 : #include "secret-store/gkm-secret-data.h"
28 : #include "secret-store/gkm-secret-collection.h"
29 : #include "secret-store/gkm-secret-item.h"
30 :
31 : #include "gkm/gkm-credential.h"
32 : #include "gkm/gkm-session.h"
33 : #include "gkm/gkm-transaction.h"
34 :
35 : #include "pkcs11/pkcs11i.h"
36 :
37 : #include <glib.h>
38 :
39 : #include <stdlib.h>
40 : #include <stdio.h>
41 : #include <string.h>
42 :
43 : typedef struct {
44 : GkmModule *module;
45 : GkmSession *session;
46 : CK_OBJECT_HANDLE credential;
47 : CK_OBJECT_HANDLE credential2;
48 : GkmSecretCollection *collection;
49 : } Test;
50 :
51 : static void
52 20 : setup (Test *test, gconstpointer unused)
53 : {
54 20 : CK_OBJECT_CLASS klass = CKO_G_CREDENTIAL;
55 : GkmObject *cred;
56 :
57 20 : CK_ATTRIBUTE attrs[] = {
58 : { CKA_CLASS, &klass, sizeof (klass) },
59 : { CKA_VALUE, NULL, 0 }
60 : };
61 :
62 20 : test->module = test_secret_module_initialize_and_enter ();
63 20 : test->session = test_secret_module_open_session (TRUE);
64 :
65 20 : test->collection = g_object_new (GKM_TYPE_SECRET_COLLECTION,
66 : "module", test->module,
67 : "identifier", "test",
68 : NULL);
69 20 : g_assert (GKM_IS_SECRET_COLLECTION (test->collection));
70 :
71 : /* Make two credentials */
72 20 : cred = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_CREDENTIAL, NULL,
73 : attrs, G_N_ELEMENTS (attrs));
74 20 : g_assert (cred != NULL);
75 20 : test->credential = gkm_object_get_handle (GKM_OBJECT (cred));
76 20 : g_object_unref (cred);
77 :
78 20 : cred = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_CREDENTIAL, NULL,
79 : attrs, G_N_ELEMENTS (attrs));
80 20 : g_assert (cred != NULL);
81 20 : test->credential2 = gkm_object_get_handle (GKM_OBJECT (cred));
82 20 : g_object_unref (cred);
83 20 : }
84 :
85 : static void
86 20 : teardown (Test *test, gconstpointer unused)
87 : {
88 20 : if (test->collection)
89 20 : g_object_unref (test->collection);
90 20 : test->collection = NULL;
91 :
92 20 : test_secret_module_leave_and_finalize ();
93 20 : test->module = NULL;
94 20 : test->session = NULL;
95 20 : test->credential = 0;
96 20 : }
97 :
98 : static void
99 1 : test_is_locked (Test *test, gconstpointer unused)
100 : {
101 : gboolean locked;
102 :
103 : /* By default is locked */
104 1 : locked = gkm_secret_object_is_locked (GKM_SECRET_OBJECT (test->collection), test->session);
105 1 : g_assert (locked == TRUE);
106 1 : }
107 :
108 : static void
109 1 : test_unlocked_data (Test *test, gconstpointer unused)
110 : {
111 : GkmCredential *cred;
112 : GkmSecretData *sdata;
113 : CK_RV rv;
114 :
115 : /* Create test->credential, which unlocks test->collection */
116 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection), NULL, 0, &cred);
117 1 : g_assert (rv == CKR_OK);
118 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
119 1 : g_object_unref (cred);
120 :
121 : /* Collection should now be unlocked */
122 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
123 1 : g_assert (GKM_IS_SECRET_DATA (sdata));
124 1 : g_assert (!gkm_secret_object_is_locked (GKM_SECRET_OBJECT (test->collection), test->session));
125 1 : g_object_unref (sdata);
126 1 : }
127 :
128 : static void
129 1 : test_get_filename (Test *test, gconstpointer unused)
130 : {
131 : GkmSecretCollection *other;
132 : const gchar *filename;
133 :
134 1 : other = g_object_new (GKM_TYPE_SECRET_COLLECTION,
135 : "module", test->module,
136 : "identifier", "test",
137 : "filename", "/tmp/filename.keyring",
138 : NULL);
139 :
140 1 : filename = gkm_secret_collection_get_filename (other);
141 1 : g_assert_cmpstr (filename, ==, "/tmp/filename.keyring");
142 :
143 1 : g_object_unref (other);
144 1 : }
145 :
146 : static void
147 1 : test_set_filename (Test *test, gconstpointer unused)
148 : {
149 : const gchar *filename;
150 :
151 1 : gkm_secret_collection_set_filename (test->collection, "/tmp/filename.keyring");
152 :
153 1 : filename = gkm_secret_collection_get_filename (test->collection);
154 1 : g_assert_cmpstr (filename, ==, "/tmp/filename.keyring");
155 1 : }
156 :
157 : static void
158 1 : test_has_item (Test *test, gconstpointer unused)
159 : {
160 : GkmSecretItem *item;
161 :
162 1 : item = gkm_secret_collection_new_item (test->collection, "testo");
163 1 : g_assert (gkm_secret_collection_has_item (test->collection, item));
164 1 : }
165 :
166 : static void
167 1 : test_load_unlock_plain (Test *test, gconstpointer unused)
168 : {
169 : GkmCredential *cred;
170 : GkmSecretData *sdata;
171 : GkmDataResult res;
172 : CK_RV rv;
173 :
174 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/plain.keyring");
175 :
176 : /* Load the data in the file */
177 1 : res = gkm_secret_collection_load (test->collection);
178 1 : g_assert (res == GKM_DATA_SUCCESS);
179 :
180 : /* Unlock the keyring, which should load again */
181 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection), NULL, 0, &cred);
182 1 : g_assert (rv == CKR_OK);
183 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
184 1 : g_object_unref (cred);
185 :
186 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
187 1 : g_assert (sdata != NULL && GKM_IS_SECRET_DATA (sdata));
188 1 : test_secret_collection_validate (test->collection, sdata);
189 1 : g_object_unref (sdata);
190 1 : }
191 :
192 : static void
193 1 : test_load_unlock_encrypted (Test *test, gconstpointer unused)
194 : {
195 : GkmCredential *cred;
196 : GkmSecretData *sdata;
197 : GkmDataResult res;
198 : CK_RV rv;
199 :
200 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/encrypted.keyring");
201 :
202 : /* Load the data in the file */
203 1 : res = gkm_secret_collection_load (test->collection);
204 1 : g_assert (res == GKM_DATA_SUCCESS);
205 :
206 : /* Unlock the keyring, which should load again */
207 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
208 : (guchar*)"my-keyring-password", 19, &cred);
209 1 : g_assert (rv == CKR_OK);
210 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
211 1 : g_object_unref (cred);
212 :
213 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
214 1 : g_assert (sdata != NULL && GKM_IS_SECRET_DATA (sdata));
215 1 : test_secret_collection_validate (test->collection, sdata);
216 1 : g_object_unref (sdata);
217 1 : }
218 :
219 : static void
220 1 : test_load_unlock_bad_password (Test *test, gconstpointer unused)
221 : {
222 : GkmCredential *cred;
223 : GkmDataResult res;
224 : CK_RV rv;
225 :
226 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/encrypted.keyring");
227 :
228 : /* Load the data in the file */
229 1 : res = gkm_secret_collection_load (test->collection);
230 1 : g_assert (res == GKM_DATA_SUCCESS);
231 :
232 : /* Unlock the keyring, which should load again */
233 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
234 : (guchar*)"wrong", 5, &cred);
235 1 : g_assert (rv == CKR_PIN_INCORRECT);
236 1 : }
237 :
238 : static void
239 1 : test_unlock_without_load (Test *test, gconstpointer unused)
240 : {
241 : GkmCredential *cred;
242 : GkmSecretData *sdata;
243 : CK_RV rv;
244 :
245 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/encrypted.keyring");
246 :
247 : /* Unlock the keyring, which should load it */
248 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
249 : (guchar*)"my-keyring-password", 19, &cred);
250 1 : g_assert (rv == CKR_OK);
251 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
252 1 : g_object_unref (cred);
253 :
254 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
255 1 : g_assert (sdata != NULL && GKM_IS_SECRET_DATA (sdata));
256 1 : test_secret_collection_validate (test->collection, sdata);
257 1 : g_object_unref (sdata);
258 1 : }
259 :
260 : static void
261 1 : test_twice_unlock (Test *test, gconstpointer unused)
262 : {
263 : GkmCredential *cred;
264 : GkmSecretData *sdata;
265 : CK_RV rv;
266 :
267 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/encrypted.keyring");
268 :
269 : /* Unlock the keyring, which should load */
270 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
271 : (guchar*)"my-keyring-password", 19, &cred);
272 1 : g_assert (rv == CKR_OK);
273 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
274 1 : g_object_unref (cred);
275 :
276 : /* Unlock the keyring again, which should not reload */
277 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
278 : (guchar*)"my-keyring-password", 19, &cred);
279 1 : g_assert (rv == CKR_OK);
280 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
281 1 : g_object_unref (cred);
282 :
283 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
284 1 : g_assert (sdata != NULL && GKM_IS_SECRET_DATA (sdata));
285 1 : test_secret_collection_validate (test->collection, sdata);
286 1 : g_object_unref (sdata);
287 1 : }
288 :
289 : static void
290 1 : test_twice_unlock_bad_password (Test *test, gconstpointer unused)
291 : {
292 : GkmCredential *cred;
293 : GkmSecretData *sdata;
294 : CK_RV rv;
295 :
296 1 : gkm_secret_collection_set_filename (test->collection, SRCDIR "/pkcs11/secret-store/fixtures/encrypted.keyring");
297 :
298 : /* Unlock the keyring, which should load */
299 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
300 : (guchar*)"my-keyring-password", 19, &cred);
301 1 : g_assert (rv == CKR_OK);
302 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
303 1 : g_object_unref (cred);
304 :
305 : /* Unlock the keyring again, wrong password */
306 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
307 : (guchar*)"wrong", 5, &cred);
308 1 : g_assert (rv == CKR_PIN_INCORRECT);
309 :
310 1 : sdata = gkm_secret_collection_unlocked_use (test->collection, test->session);
311 1 : g_assert (sdata != NULL && GKM_IS_SECRET_DATA (sdata));
312 1 : test_secret_collection_validate (test->collection, sdata);
313 1 : g_object_unref (sdata);
314 1 : }
315 :
316 : static void
317 1 : test_memory_unlock (Test *test, gconstpointer unused)
318 : {
319 : GkmCredential *cred;
320 : GkmDataResult res;
321 : CK_RV rv;
322 :
323 : /* Load the data in the file */
324 1 : res = gkm_secret_collection_load (test->collection);
325 1 : g_assert (res == GKM_DATA_SUCCESS);
326 :
327 : /* Unlock the keyring, which should load again */
328 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
329 : NULL, 0, &cred);
330 1 : g_assert (rv == CKR_OK);
331 1 : gkm_session_add_session_object (test->session, NULL, GKM_OBJECT (cred));
332 1 : g_object_unref (cred);
333 1 : }
334 :
335 : static void
336 1 : test_memory_unlock_bad_password (Test *test, gconstpointer unused)
337 : {
338 : GkmCredential *cred;
339 : GkmDataResult res;
340 : CK_RV rv;
341 :
342 : /* Load the data in the file */
343 1 : res = gkm_secret_collection_load (test->collection);
344 1 : g_assert (res == GKM_DATA_SUCCESS);
345 :
346 : /* Unlock the keyring, which should load again */
347 1 : rv = gkm_credential_create (test->module, gkm_session_get_manager (test->session), GKM_OBJECT (test->collection),
348 : (guchar*)"wrong", 5, &cred);
349 1 : g_assert (rv == CKR_PIN_INCORRECT);
350 1 : }
351 :
352 : static void
353 1 : test_factory (Test *test, gconstpointer unused)
354 : {
355 1 : CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
356 : GkmObject *object;
357 :
358 1 : CK_ATTRIBUTE attrs[] = {
359 : { CKA_CLASS, &klass, sizeof (klass) },
360 : { CKA_LABEL, "blah", 4 },
361 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
362 : };
363 :
364 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
365 : attrs, G_N_ELEMENTS (attrs));
366 1 : g_assert (object != NULL);
367 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
368 :
369 1 : g_assert_cmpstr (gkm_secret_object_get_label (GKM_SECRET_OBJECT (object)), ==, "blah");
370 1 : g_object_unref (object);
371 1 : }
372 :
373 : static void
374 1 : test_factory_unnamed (Test *test, gconstpointer unused)
375 : {
376 1 : CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
377 : const gchar *identifier;
378 : GkmObject *object;
379 :
380 1 : CK_ATTRIBUTE attrs[] = {
381 : { CKA_CLASS, &klass, sizeof (klass) },
382 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
383 : };
384 :
385 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
386 : attrs, G_N_ELEMENTS (attrs));
387 1 : g_assert (object != NULL);
388 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
389 :
390 1 : identifier = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
391 1 : g_assert_cmpstr (identifier, !=, "");
392 1 : g_object_unref (object);
393 1 : }
394 :
395 : static void
396 1 : test_factory_token (Test *test, gconstpointer unused)
397 : {
398 1 : CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
399 : const gchar *identifier;
400 : GkmObject *object;
401 1 : CK_BBOOL token = CK_TRUE;
402 :
403 1 : CK_ATTRIBUTE attrs[] = {
404 : { CKA_CLASS, &klass, sizeof (klass) },
405 : { CKA_TOKEN, &token, sizeof (token) },
406 : { CKA_LABEL, "blah", 4 },
407 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
408 : };
409 :
410 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
411 : attrs, G_N_ELEMENTS (attrs));
412 1 : g_assert (object != NULL);
413 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
414 :
415 1 : identifier = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
416 1 : g_assert (strstr (identifier, "blah"));
417 1 : g_object_unref (object);
418 1 : }
419 :
420 : static void
421 1 : test_factory_duplicate (Test *test, gconstpointer unused)
422 : {
423 1 : CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
424 : const gchar *identifier1, *identifier2;
425 : GkmObject *object;
426 :
427 1 : CK_ATTRIBUTE attrs[] = {
428 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
429 : { CKA_CLASS, &klass, sizeof (klass) },
430 : { CKA_LABEL, "blah", 4 },
431 : };
432 :
433 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
434 : attrs, G_N_ELEMENTS (attrs));
435 1 : g_assert (object != NULL);
436 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
437 :
438 1 : identifier1 = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
439 1 : g_assert (strstr (identifier1, "blah"));
440 1 : g_object_unref (object);
441 :
442 : /* Use second test->credential for second object */
443 1 : attrs[0].pValue = &test->credential2;
444 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
445 : attrs, G_N_ELEMENTS (attrs));
446 1 : g_assert (object != NULL);
447 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
448 :
449 1 : identifier2 = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
450 1 : g_assert (strstr (identifier2, "blah"));
451 1 : g_object_unref (object);
452 :
453 1 : g_assert_cmpstr (identifier1, !=, identifier2);
454 1 : }
455 :
456 : static void
457 1 : test_factory_item (Test *test, gconstpointer unused)
458 : {
459 1 : CK_OBJECT_CLASS c_klass = CKO_G_COLLECTION;
460 1 : CK_OBJECT_CLASS i_klass = CKO_SECRET_KEY;
461 : const gchar *identifier;
462 : GkmObject *object;
463 1 : CK_BBOOL token = CK_TRUE;
464 :
465 1 : CK_ATTRIBUTE c_attrs[] = {
466 : { CKA_CLASS, &c_klass, sizeof (c_klass) },
467 : { CKA_TOKEN, &token, sizeof (token) },
468 : { CKA_LABEL, "three", 5 },
469 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
470 : };
471 :
472 1 : CK_ATTRIBUTE i_attrs[] = {
473 : { CKA_G_COLLECTION, NULL, 0 }, /* Filled below */
474 : { CKA_CLASS, &i_klass, sizeof (i_klass) },
475 : { CKA_TOKEN, &token, sizeof (token) },
476 : { CKA_LABEL, "Item", 4 },
477 : };
478 :
479 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
480 : c_attrs, G_N_ELEMENTS (c_attrs));
481 1 : g_assert (object != NULL);
482 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
483 1 : identifier = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
484 1 : g_object_unref (object);
485 :
486 1 : i_attrs[0].pValue = (gpointer)identifier;
487 1 : i_attrs[0].ulValueLen = strlen (identifier);
488 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_ITEM, NULL,
489 : i_attrs, G_N_ELEMENTS (i_attrs));
490 1 : g_assert (object != NULL);
491 1 : g_assert (GKM_IS_SECRET_ITEM (object));
492 1 : g_object_unref (object);
493 1 : }
494 :
495 : static void
496 1 : test_token_remove (Test *test, gconstpointer unused)
497 : {
498 1 : CK_OBJECT_CLASS klass = CKO_G_COLLECTION;
499 : GkmTransaction *transaction;
500 : GkmObject *object;
501 1 : CK_BBOOL token = CK_TRUE;
502 :
503 1 : CK_ATTRIBUTE attrs[] = {
504 : { CKA_CLASS, &klass, sizeof (klass) },
505 : { CKA_TOKEN, &token, sizeof (token) },
506 : { CKA_LABEL, "blah", 4 },
507 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
508 : };
509 :
510 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
511 : attrs, G_N_ELEMENTS (attrs));
512 1 : g_assert (object != NULL);
513 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
514 :
515 1 : transaction = gkm_transaction_new ();
516 1 : gkm_module_remove_token_object (test->module, transaction, object);
517 1 : g_assert (!gkm_transaction_get_failed (transaction));
518 1 : gkm_transaction_complete (transaction);
519 1 : g_object_unref (transaction);
520 1 : g_object_unref (object);
521 1 : }
522 :
523 : static void
524 1 : test_token_item_remove (Test *test, gconstpointer unused)
525 : {
526 1 : CK_OBJECT_CLASS c_klass = CKO_G_COLLECTION;
527 1 : CK_OBJECT_CLASS i_klass = CKO_SECRET_KEY;
528 : GkmTransaction *transaction;
529 : const gchar *identifier;
530 : GkmObject *object;
531 1 : CK_BBOOL token = CK_TRUE;
532 :
533 1 : CK_ATTRIBUTE c_attrs[] = {
534 : { CKA_CLASS, &c_klass, sizeof (c_klass) },
535 : { CKA_TOKEN, &token, sizeof (token) },
536 : { CKA_LABEL, "three", 5 },
537 1 : { CKA_G_CREDENTIAL, &test->credential, sizeof (test->credential) },
538 : };
539 :
540 1 : CK_ATTRIBUTE i_attrs[] = {
541 : { CKA_G_COLLECTION, NULL, 0 }, /* Filled below */
542 : { CKA_CLASS, &i_klass, sizeof (i_klass) },
543 : { CKA_TOKEN, &token, sizeof (token) },
544 : { CKA_LABEL, "Item", 4 },
545 : };
546 :
547 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_COLLECTION, NULL,
548 : c_attrs, G_N_ELEMENTS (c_attrs));
549 1 : g_assert (object != NULL);
550 1 : g_assert (GKM_IS_SECRET_COLLECTION (object));
551 1 : identifier = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (object));
552 1 : g_object_unref (object);
553 :
554 1 : i_attrs[0].pValue = (gpointer)identifier;
555 1 : i_attrs[0].ulValueLen = strlen (identifier);
556 1 : object = gkm_session_create_object_for_factory (test->session, GKM_FACTORY_SECRET_ITEM, NULL,
557 : i_attrs, G_N_ELEMENTS (i_attrs));
558 1 : g_assert (object != NULL);
559 1 : g_assert (GKM_IS_SECRET_ITEM (object));
560 :
561 1 : transaction = gkm_transaction_new ();
562 1 : gkm_module_remove_token_object (test->module, transaction, object);
563 1 : g_assert (!gkm_transaction_get_failed (transaction));
564 1 : gkm_transaction_complete (transaction);
565 1 : g_object_unref (transaction);
566 1 : g_object_unref (object);
567 1 : }
568 :
569 : int
570 1 : main (int argc, char **argv)
571 : {
572 : #if !GLIB_CHECK_VERSION(2,35,0)
573 : g_type_init ();
574 : #endif
575 1 : g_test_init (&argc, &argv, NULL);
576 :
577 1 : g_test_add ("/secret-store/collection/is_locked", Test, NULL, setup, test_is_locked, teardown);
578 1 : g_test_add ("/secret-store/collection/unlocked_data", Test, NULL, setup, test_unlocked_data, teardown);
579 1 : g_test_add ("/secret-store/collection/get_filename", Test, NULL, setup, test_get_filename, teardown);
580 1 : g_test_add ("/secret-store/collection/set_filename", Test, NULL, setup, test_set_filename, teardown);
581 1 : g_test_add ("/secret-store/collection/has_item", Test, NULL, setup, test_has_item, teardown);
582 1 : g_test_add ("/secret-store/collection/load_unlock_plain", Test, NULL, setup, test_load_unlock_plain, teardown);
583 1 : g_test_add ("/secret-store/collection/load_unlock_encrypted", Test, NULL, setup, test_load_unlock_encrypted, teardown);
584 1 : g_test_add ("/secret-store/collection/load_unlock_bad_password", Test, NULL, setup, test_load_unlock_bad_password, teardown);
585 1 : g_test_add ("/secret-store/collection/unlock_without_load", Test, NULL, setup, test_unlock_without_load, teardown);
586 1 : g_test_add ("/secret-store/collection/twice_unlock", Test, NULL, setup, test_twice_unlock, teardown);
587 1 : g_test_add ("/secret-store/collection/twice_unlock_bad_password", Test, NULL, setup, test_twice_unlock_bad_password, teardown);
588 1 : g_test_add ("/secret-store/collection/memory_unlock", Test, NULL, setup, test_memory_unlock, teardown);
589 1 : g_test_add ("/secret-store/collection/memory_unlock_bad_password", Test, NULL, setup, test_memory_unlock_bad_password, teardown);
590 1 : g_test_add ("/secret-store/collection/factory", Test, NULL, setup, test_factory, teardown);
591 1 : g_test_add ("/secret-store/collection/factory_unnamed", Test, NULL, setup, test_factory_unnamed, teardown);
592 1 : g_test_add ("/secret-store/collection/factory_token", Test, NULL, setup, test_factory_token, teardown);
593 1 : g_test_add ("/secret-store/collection/factory_duplicate", Test, NULL, setup, test_factory_duplicate, teardown);
594 1 : g_test_add ("/secret-store/collection/factory_item", Test, NULL, setup, test_factory_item, teardown);
595 1 : g_test_add ("/secret-store/collection/token_remove", Test, NULL, setup, test_token_remove, teardown);
596 1 : g_test_add ("/secret-store/collection/token_item_remove", Test, NULL, setup, test_token_item_remove, teardown);
597 :
598 1 : return g_test_run ();
599 : }
|