1 /* libsecret - GLib wrapper for Secret Service
3 * Copyright 2012 Red Hat Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2 of the licence or (at
8 * your option) any later version.
10 * See the included COPYING file for more information.
12 * Author: Stef Walter <stefw@gnome.org>
18 #include "secret-collection.h"
19 #include "secret-service.h"
20 #include "secret-paths.h"
21 #include "secret-private.h"
23 #include "mock-service.h"
25 #include "egg/egg-testing.h"
33 SecretService *service;
36 static const SecretSchema MOCK_SCHEMA = {
40 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
41 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
42 { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
51 const gchar *mock_script = data;
53 mock_service_start (mock_script, &error);
54 g_assert_no_error (error);
56 test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
57 g_assert_no_error (error);
58 g_object_add_weak_pointer (G_OBJECT (test->service), (gpointer *)&test->service);
65 g_object_unref (test->service);
66 secret_service_disconnect ();
67 g_assert (test->service == NULL);
73 on_async_result (GObject *source,
77 GAsyncResult **ret = user_data;
78 g_assert (ret != NULL);
79 g_assert (*ret == NULL);
80 *ret = g_object_ref (result);
81 egg_test_wait_stop ();
85 on_notify_stop (GObject *obj,
89 guint *sigs = user_data;
90 g_assert (sigs != NULL);
93 egg_test_wait_stop ();
97 test_new_sync (Test *test,
100 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
101 GError *error = NULL;
102 SecretCollection *collection;
104 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
105 SECRET_COLLECTION_NONE, NULL, &error);
106 g_assert_no_error (error);
107 g_object_add_weak_pointer (G_OBJECT (collection), (gpointer *)&collection);
109 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), ==, collection_path);
111 g_object_unref (collection);
112 g_assert (collection == NULL);
116 test_new_async (Test *test,
117 gconstpointer unused)
119 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
120 GError *error = NULL;
121 SecretCollection *collection;
122 GAsyncResult *result = NULL;
124 secret_collection_new_for_dbus_path (test->service, collection_path,
125 SECRET_COLLECTION_NONE, NULL, on_async_result, &result);
126 g_assert (result == NULL);
130 collection = secret_collection_new_for_dbus_path_finish (result, &error);
131 g_assert_no_error (error);
132 g_object_unref (result);
133 g_object_add_weak_pointer (G_OBJECT (collection), (gpointer *)&collection);
135 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), ==, collection_path);
137 g_object_unref (collection);
138 g_assert (collection == NULL);
142 test_new_sync_noexist (Test *test,
143 gconstpointer unused)
145 const gchar *collection_path = "/org/freedesktop/secrets/collection/nonexistant";
146 GError *error = NULL;
147 SecretCollection *collection;
149 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
150 SECRET_COLLECTION_NONE, NULL, &error);
151 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
152 g_assert (collection == NULL);
156 test_new_async_noexist (Test *test,
157 gconstpointer unused)
159 const gchar *collection_path = "/org/freedesktop/secrets/collection/nonexistant";
160 GError *error = NULL;
161 SecretCollection *collection;
162 GAsyncResult *result = NULL;
164 secret_collection_new_for_dbus_path (test->service, collection_path,
165 SECRET_COLLECTION_NONE, NULL, on_async_result, &result);
166 g_assert (result == NULL);
170 collection = secret_collection_new_for_dbus_path_finish (result, &error);
171 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
172 g_assert (collection == NULL);
173 g_object_unref (result);
178 test_for_alias_sync (Test *test,
181 const gchar *collection_path;
182 SecretCollection *collection;
183 GError *error = NULL;
185 collection = secret_collection_for_alias_sync (test->service, "default",
186 SECRET_COLLECTION_NONE, NULL, &error);
187 g_assert_no_error (error);
189 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
190 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
191 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_NONE);
192 g_assert (secret_collection_get_items (collection) == NULL);
193 g_object_unref (collection);
195 collection = secret_collection_for_alias_sync (test->service, "unknown",
196 SECRET_COLLECTION_NONE, NULL, &error);
197 g_assert_no_error (error);
198 g_assert (collection == NULL);
202 test_for_alias_async (Test *test,
205 const gchar *collection_path;
206 SecretCollection *collection;
207 GAsyncResult *result = NULL;
208 GError *error = NULL;
210 secret_collection_for_alias (test->service, "default",
211 SECRET_COLLECTION_NONE,
212 NULL, on_async_result, &result);
213 g_assert (result == NULL);
216 collection = secret_collection_for_alias_finish (result, &error);
217 g_assert_no_error (error);
218 g_object_unref (result);
220 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
221 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
222 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_NONE);
223 g_assert (secret_collection_get_items (collection) == NULL);
224 g_object_unref (collection);
227 secret_collection_for_alias (test->service, "unknown",
228 SECRET_COLLECTION_NONE,
229 NULL, on_async_result, &result);
230 g_assert (result == NULL);
233 collection = secret_collection_for_alias_finish (result, &error);
234 g_assert_no_error (error);
235 g_assert (collection == NULL);
236 g_object_unref (result);
240 test_for_alias_load_sync (Test *test,
243 const gchar *collection_path;
244 SecretCollection *collection;
245 GError *error = NULL;
248 collection = secret_collection_for_alias_sync (test->service, "default",
249 SECRET_COLLECTION_LOAD_ITEMS,
251 g_assert_no_error (error);
253 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
254 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
255 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_LOAD_ITEMS);
256 items = secret_collection_get_items (collection);
257 g_assert (items != NULL);
258 g_list_free_full (items, g_object_unref);
259 g_object_unref (collection);
263 test_for_alias_load_async (Test *test,
266 const gchar *collection_path;
267 SecretCollection *collection;
268 GAsyncResult *result = NULL;
269 GError *error = NULL;
272 secret_collection_for_alias (test->service, "default",
273 SECRET_COLLECTION_LOAD_ITEMS,
274 NULL, on_async_result, &result);
275 g_assert (result == NULL);
278 collection = secret_collection_for_alias_finish (result, &error);
279 g_assert_no_error (error);
280 g_object_unref (result);
282 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
283 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
284 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_LOAD_ITEMS);
285 items = secret_collection_get_items (collection);
286 g_assert (items != NULL);
287 g_list_free_full (items, g_object_unref);
288 g_object_unref (collection);
293 test_create_sync (Test *test,
294 gconstpointer unused)
296 GError *error = NULL;
297 SecretCollection *collection;
299 collection = secret_collection_create_sync (test->service, "Train", NULL,
300 SECRET_COLLECTION_CREATE_NONE, NULL, &error);
301 g_assert_no_error (error);
302 g_object_add_weak_pointer (G_OBJECT (collection), (gpointer *)&collection);
304 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
305 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
306 g_assert (secret_collection_get_locked (collection) == FALSE);
308 g_object_unref (collection);
309 g_assert (collection == NULL);
313 test_create_async (Test *test,
314 gconstpointer unused)
316 GError *error = NULL;
317 SecretCollection *collection;
318 GAsyncResult *result = NULL;
320 secret_collection_create (test->service, "Train", NULL,
321 SECRET_COLLECTION_CREATE_NONE,
322 NULL, on_async_result, &result);
323 g_assert (result == NULL);
327 collection = secret_collection_create_finish (result, &error);
328 g_assert_no_error (error);
329 g_object_unref (result);
330 g_object_add_weak_pointer (G_OBJECT (collection), (gpointer *)&collection);
332 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
333 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
334 g_assert (secret_collection_get_locked (collection) == FALSE);
336 g_object_unref (collection);
337 g_assert (collection == NULL);
341 test_properties (Test *test,
342 gconstpointer unused)
344 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
345 SecretCollection *collection;
346 SecretService *service;
347 GError *error = NULL;
353 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
354 SECRET_COLLECTION_NONE, NULL, &error);
355 g_assert_no_error (error);
357 g_assert (secret_collection_get_locked (collection) == FALSE);
358 g_assert_cmpuint (secret_collection_get_created (collection), <=, time (NULL));
359 g_assert_cmpuint (secret_collection_get_modified (collection), <=, time (NULL));
361 label = secret_collection_get_label (collection);
362 g_assert_cmpstr (label, ==, "Collection One");
365 g_object_get (collection,
368 "modified", &modified,
373 g_assert (locked == FALSE);
374 g_assert_cmpuint (created, <=, time (NULL));
375 g_assert_cmpuint (modified, <=, time (NULL));
377 g_assert_cmpstr (label, ==, "Collection One");
380 g_assert (service == test->service);
381 g_object_unref (service);
383 g_object_unref (collection);
387 check_items_equal (GList *items,
397 va_start (va, items);
398 paths = g_hash_table_new (g_str_hash, g_str_equal);
399 while ((path = va_arg (va, gchar *)) != NULL)
400 g_hash_table_insert (paths, (gpointer)path, (gpointer)path);
403 num_items = g_hash_table_size (paths);
404 g_assert_cmpuint (num_items, ==, g_list_length (items));
406 for (l = items; l != NULL; l = g_list_next (l)) {
407 path = g_dbus_proxy_get_object_path (l->data);
408 have_item = g_hash_table_remove (paths, path);
409 g_assert (have_item);
412 g_hash_table_destroy (paths);
416 test_items (Test *test,
417 gconstpointer unused)
419 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
420 SecretCollection *collection;
421 GError *error = NULL;
424 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
425 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
426 g_assert_no_error (error);
428 items = secret_collection_get_items (collection);
429 check_items_equal (items,
430 "/org/freedesktop/secrets/collection/english/1",
431 "/org/freedesktop/secrets/collection/english/2",
432 "/org/freedesktop/secrets/collection/english/3",
434 g_list_free_full (items, g_object_unref);
436 g_object_get (collection, "items", &items, NULL);
437 check_items_equal (items,
438 "/org/freedesktop/secrets/collection/english/1",
439 "/org/freedesktop/secrets/collection/english/2",
440 "/org/freedesktop/secrets/collection/english/3",
442 g_list_free_full (items, g_object_unref);
444 g_object_unref (collection);
448 test_items_empty (Test *test,
449 gconstpointer unused)
451 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
452 SecretCollection *collection;
453 GError *error = NULL;
456 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
457 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
458 g_assert_no_error (error);
460 items = secret_collection_get_items (collection);
461 check_items_equal (items, NULL);
462 g_list_free_full (items, g_object_unref);
464 g_object_get (collection, "items", &items, NULL);
465 check_items_equal (items, NULL);
466 g_list_free_full (items, g_object_unref);
468 g_object_unref (collection);
472 test_items_empty_async (Test *test,
473 gconstpointer unused)
475 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
476 SecretCollection *collection;
477 GAsyncResult *result = NULL;
478 GError *error = NULL;
481 secret_collection_new_for_dbus_path (test->service, collection_path,
482 SECRET_COLLECTION_LOAD_ITEMS,
483 NULL, on_async_result, &result);
484 g_assert (result == NULL);
488 collection = secret_collection_new_for_dbus_path_finish (result, &error);
489 g_assert_no_error (error);
490 g_object_unref (result);
492 items = secret_collection_get_items (collection);
493 check_items_equal (items, NULL);
494 g_list_free_full (items, g_object_unref);
496 g_object_get (collection, "items", &items, NULL);
497 check_items_equal (items, NULL);
498 g_list_free_full (items, g_object_unref);
500 g_object_unref (collection);
504 test_set_label_sync (Test *test,
505 gconstpointer unused)
507 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
508 GError *error = NULL;
509 SecretCollection *collection;
513 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
514 SECRET_COLLECTION_NONE, NULL, &error);
515 g_assert_no_error (error);
517 label = secret_collection_get_label (collection);
518 g_assert_cmpstr (label, ==, "Collection One");
521 ret = secret_collection_set_label_sync (collection, "Another label", NULL, &error);
522 g_assert_no_error (error);
523 g_assert (ret == TRUE);
525 label = secret_collection_get_label (collection);
526 g_assert_cmpstr (label, ==, "Another label");
529 g_object_unref (collection);
533 test_set_label_async (Test *test,
534 gconstpointer unused)
536 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
537 GAsyncResult *result = NULL;
538 GError *error = NULL;
539 SecretCollection *collection;
543 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
544 SECRET_COLLECTION_NONE, NULL, &error);
545 g_assert_no_error (error);
547 label = secret_collection_get_label (collection);
548 g_assert_cmpstr (label, ==, "Collection One");
551 secret_collection_set_label (collection, "Another label", NULL, on_async_result, &result);
552 g_assert (result == NULL);
556 ret = secret_collection_set_label_finish (collection, result, &error);
557 g_assert_no_error (error);
558 g_assert (ret == TRUE);
559 g_object_unref (result);
561 label = secret_collection_get_label (collection);
562 g_assert_cmpstr (label, ==, "Another label");
565 g_object_unref (collection);
569 test_set_label_prop (Test *test,
570 gconstpointer unused)
572 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
573 GAsyncResult *result = NULL;
574 GError *error = NULL;
575 SecretCollection *collection;
579 secret_collection_new_for_dbus_path (test->service, collection_path, SECRET_COLLECTION_NONE,
580 NULL, on_async_result, &result);
581 g_assert (result == NULL);
583 collection = secret_collection_new_for_dbus_path_finish (result, &error);
584 g_assert_no_error (error);
585 g_object_unref (result);
587 label = secret_collection_get_label (collection);
588 g_assert_cmpstr (label, ==, "Collection One");
591 g_signal_connect (collection, "notify::label", G_CALLBACK (on_notify_stop), &sigs);
592 g_object_set (collection, "label", "Blah blah", NULL);
594 /* Wait for the property to actually 'take' */
597 label = secret_collection_get_label (collection);
598 g_assert_cmpstr (label, ==, "Blah blah");
601 g_object_unref (collection);
605 test_delete_sync (Test *test,
606 gconstpointer unused)
608 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
609 SecretCollection *collection;
610 GError *error = NULL;
613 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
614 SECRET_COLLECTION_NONE, NULL, &error);
615 g_assert_no_error (error);
617 ret = secret_collection_delete_sync (collection, NULL, &error);
618 g_assert_no_error (error);
619 g_assert (ret == TRUE);
621 g_object_unref (collection);
623 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
624 SECRET_COLLECTION_NONE, NULL, &error);
625 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
626 g_assert (collection == NULL);
630 test_delete_async (Test *test,
631 gconstpointer unused)
633 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
634 SecretCollection *collection;
635 GAsyncResult *result = NULL;
636 GError *error = NULL;
639 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
640 SECRET_COLLECTION_NONE, NULL, &error);
641 g_assert_no_error (error);
643 secret_collection_delete (collection, NULL, on_async_result, &result);
644 g_assert (result == NULL);
648 ret = secret_collection_delete_finish (collection, result, &error);
649 g_assert_no_error (error);
650 g_object_unref (result);
651 g_assert (ret == TRUE);
653 g_object_unref (collection);
655 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
656 SECRET_COLLECTION_NONE, NULL, &error);
657 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
658 g_assert (collection == NULL);
662 test_search_sync (Test *test,
665 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
666 SecretCollection *collection;
667 GHashTable *attributes;
668 GError *error = NULL;
671 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
672 SECRET_COLLECTION_NONE, NULL, &error);
673 g_assert_no_error (error);
675 attributes = g_hash_table_new (g_str_hash, g_str_equal);
676 g_hash_table_insert (attributes, "number", "1");
678 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
679 SECRET_SEARCH_NONE, NULL, &error);
680 g_assert_no_error (error);
681 g_hash_table_unref (attributes);
683 g_assert (items != NULL);
684 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
686 g_assert (items->next == NULL);
687 g_list_free_full (items, g_object_unref);
689 g_object_unref (collection);
693 test_search_async (Test *test,
696 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
697 SecretCollection *collection;
698 GAsyncResult *result = NULL;
699 GHashTable *attributes;
700 GError *error = NULL;
703 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
704 SECRET_COLLECTION_NONE, NULL, &error);
705 g_assert_no_error (error);
707 attributes = g_hash_table_new (g_str_hash, g_str_equal);
708 g_hash_table_insert (attributes, "number", "1");
710 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
711 SECRET_SEARCH_NONE, NULL,
712 on_async_result, &result);
713 g_hash_table_unref (attributes);
714 g_assert (result == NULL);
718 g_assert (G_IS_ASYNC_RESULT (result));
719 items = secret_collection_search_finish (collection, result, &error);
720 g_assert_no_error (error);
721 g_object_unref (result);
723 g_assert (items != NULL);
724 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
726 g_assert (items->next == NULL);
727 g_list_free_full (items, g_object_unref);
729 g_object_unref (collection);
733 sort_by_object_path (gconstpointer a,
736 const gchar *pa = g_dbus_proxy_get_object_path ((GDBusProxy *)a);
737 const gchar *pb = g_dbus_proxy_get_object_path ((GDBusProxy *)b);
739 return g_strcmp0 (pa, pb);
743 test_search_all_sync (Test *test,
746 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
747 SecretCollection *collection;
748 GHashTable *attributes;
749 GError *error = NULL;
752 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
753 SECRET_COLLECTION_NONE, NULL, &error);
754 g_assert_no_error (error);
756 attributes = g_hash_table_new (g_str_hash, g_str_equal);
758 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
759 SECRET_SEARCH_ALL, NULL, &error);
760 g_assert_no_error (error);
761 g_hash_table_unref (attributes);
763 items = g_list_sort (items, sort_by_object_path);
765 g_assert (items != NULL);
766 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
767 g_assert (secret_item_get_secret (items->data) == NULL);
769 g_assert (items->next != NULL);
770 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
771 g_assert (secret_item_get_secret (items->next->data) == NULL);
773 g_assert (items->next->next != NULL);
774 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
775 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
777 g_assert (items->next->next->next == NULL);
778 g_list_free_full (items, g_object_unref);
780 g_object_unref (collection);
784 test_search_all_async (Test *test,
787 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
788 SecretCollection *collection;
789 GAsyncResult *result = NULL;
790 GHashTable *attributes;
791 GError *error = NULL;
794 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
795 SECRET_COLLECTION_NONE, NULL, &error);
796 g_assert_no_error (error);
798 attributes = g_hash_table_new (g_str_hash, g_str_equal);
800 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
801 SECRET_SEARCH_ALL, NULL,
802 on_async_result, &result);
803 g_hash_table_unref (attributes);
804 g_assert (result == NULL);
808 g_assert (G_IS_ASYNC_RESULT (result));
809 items = secret_collection_search_finish (collection, result, &error);
810 g_assert_no_error (error);
811 g_object_unref (result);
813 items = g_list_sort (items, sort_by_object_path);
815 g_assert (items != NULL);
816 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
817 g_assert (secret_item_get_secret (items->data) == NULL);
819 g_assert (items->next != NULL);
820 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
821 g_assert (secret_item_get_secret (items->next->data) == NULL);
823 g_assert (items->next->next != NULL);
824 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
825 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
827 g_assert (items->next->next->next == NULL);
828 g_list_free_full (items, g_object_unref);
830 g_object_unref (collection);
834 test_search_unlock_sync (Test *test,
837 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
838 SecretCollection *collection;
839 GHashTable *attributes;
840 GError *error = NULL;
843 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
844 SECRET_COLLECTION_NONE, NULL, &error);
845 g_assert_no_error (error);
847 attributes = g_hash_table_new (g_str_hash, g_str_equal);
848 g_hash_table_insert (attributes, "number", "1");
850 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
851 SECRET_SEARCH_UNLOCK, NULL, &error);
852 g_assert_no_error (error);
853 g_hash_table_unref (attributes);
855 g_assert (items != NULL);
856 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
857 g_assert (secret_item_get_locked (items->data) == FALSE);
858 g_assert (secret_item_get_secret (items->data) == NULL);
860 g_assert (items->next == NULL);
861 g_list_free_full (items, g_object_unref);
863 g_object_unref (collection);
867 test_search_unlock_async (Test *test,
870 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
871 SecretCollection *collection;
872 GAsyncResult *result = NULL;
873 GHashTable *attributes;
874 GError *error = NULL;
877 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
878 SECRET_COLLECTION_NONE, NULL, &error);
879 g_assert_no_error (error);
881 attributes = g_hash_table_new (g_str_hash, g_str_equal);
882 g_hash_table_insert (attributes, "number", "1");
884 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
885 SECRET_SEARCH_UNLOCK, NULL,
886 on_async_result, &result);
887 g_hash_table_unref (attributes);
888 g_assert (result == NULL);
892 g_assert (G_IS_ASYNC_RESULT (result));
893 items = secret_collection_search_finish (collection, result, &error);
894 g_assert_no_error (error);
895 g_object_unref (result);
897 g_assert (items != NULL);
898 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
899 g_assert (secret_item_get_locked (items->data) == FALSE);
900 g_assert (secret_item_get_secret (items->data) == NULL);
902 g_assert (items->next == NULL);
903 g_list_free_full (items, g_object_unref);
905 g_object_unref (collection);
909 test_search_secrets_sync (Test *test,
912 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
913 SecretCollection *collection;
914 GHashTable *attributes;
915 GError *error = NULL;
919 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
920 SECRET_COLLECTION_NONE, NULL, &error);
921 g_assert_no_error (error);
923 attributes = g_hash_table_new (g_str_hash, g_str_equal);
924 g_hash_table_insert (attributes, "number", "1");
926 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
927 SECRET_SEARCH_LOAD_SECRETS,
929 g_assert_no_error (error);
930 g_hash_table_unref (attributes);
932 g_assert (items != NULL);
933 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
934 g_assert (secret_item_get_locked (items->data) == FALSE);
935 value = secret_item_get_secret (items->data);
936 g_assert (value != NULL);
937 secret_value_unref (value);
939 g_assert (items->next == NULL);
940 g_list_free_full (items, g_object_unref);
942 g_object_unref (collection);
946 test_search_secrets_async (Test *test,
949 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
950 SecretCollection *collection;
951 GAsyncResult *result = NULL;
952 GHashTable *attributes;
953 GError *error = NULL;
957 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
958 SECRET_COLLECTION_NONE, NULL, &error);
959 g_assert_no_error (error);
961 attributes = g_hash_table_new (g_str_hash, g_str_equal);
962 g_hash_table_insert (attributes, "number", "1");
964 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
965 SECRET_SEARCH_LOAD_SECRETS, NULL,
966 on_async_result, &result);
967 g_hash_table_unref (attributes);
968 g_assert (result == NULL);
972 g_assert (G_IS_ASYNC_RESULT (result));
973 items = secret_collection_search_finish (collection, result, &error);
974 g_assert_no_error (error);
975 g_object_unref (result);
977 g_assert (items != NULL);
978 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
979 g_assert (secret_item_get_locked (items->data) == FALSE);
980 value = secret_item_get_secret (items->data);
981 g_assert (value != NULL);
982 secret_value_unref (value);
984 g_assert (items->next == NULL);
985 g_list_free_full (items, g_object_unref);
987 g_object_unref (collection);
991 main (int argc, char **argv)
993 g_test_init (&argc, &argv, NULL);
994 g_set_prgname ("test-collection");
995 #if !GLIB_CHECK_VERSION(2,35,0)
999 g_test_add ("/collection/new-sync", Test, "mock-service-normal.py", setup, test_new_sync, teardown);
1000 g_test_add ("/collection/new-async", Test, "mock-service-normal.py", setup, test_new_async, teardown);
1001 g_test_add ("/collection/new-sync-noexist", Test, "mock-service-normal.py", setup, test_new_sync_noexist, teardown);
1002 g_test_add ("/collection/new-async-noexist", Test, "mock-service-normal.py", setup, test_new_async_noexist, teardown);
1003 g_test_add ("/collection/for-alias-sync", Test, "mock-service-normal.py", setup, test_for_alias_sync, teardown);
1004 g_test_add ("/collection/for-alias-async", Test, "mock-service-normal.py", setup, test_for_alias_async, teardown);
1005 g_test_add ("/collection/for-alias-load-sync", Test, "mock-service-normal.py", setup, test_for_alias_load_sync, teardown);
1006 g_test_add ("/collection/for-alias-load-async", Test, "mock-service-normal.py", setup, test_for_alias_load_async, teardown);
1007 g_test_add ("/collection/create-sync", Test, "mock-service-normal.py", setup, test_create_sync, teardown);
1008 g_test_add ("/collection/create-async", Test, "mock-service-normal.py", setup, test_create_async, teardown);
1009 g_test_add ("/collection/properties", Test, "mock-service-normal.py", setup, test_properties, teardown);
1010 g_test_add ("/collection/items", Test, "mock-service-normal.py", setup, test_items, teardown);
1011 g_test_add ("/collection/items-empty", Test, "mock-service-normal.py", setup, test_items_empty, teardown);
1012 g_test_add ("/collection/items-empty-async", Test, "mock-service-normal.py", setup, test_items_empty_async, teardown);
1013 g_test_add ("/collection/set-label-sync", Test, "mock-service-normal.py", setup, test_set_label_sync, teardown);
1014 g_test_add ("/collection/set-label-async", Test, "mock-service-normal.py", setup, test_set_label_async, teardown);
1015 g_test_add ("/collection/set-label-prop", Test, "mock-service-normal.py", setup, test_set_label_prop, teardown);
1016 g_test_add ("/collection/delete-sync", Test, "mock-service-normal.py", setup, test_delete_sync, teardown);
1017 g_test_add ("/collection/delete-async", Test, "mock-service-normal.py", setup, test_delete_async, teardown);
1019 g_test_add ("/collection/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
1020 g_test_add ("/collection/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
1021 g_test_add ("/collection/search-all-sync", Test, "mock-service-normal.py", setup, test_search_all_sync, teardown);
1022 g_test_add ("/collection/search-all-async", Test, "mock-service-normal.py", setup, test_search_all_async, teardown);
1023 g_test_add ("/collection/search-unlock-sync", Test, "mock-service-normal.py", setup, test_search_unlock_sync, teardown);
1024 g_test_add ("/collection/search-unlock-async", Test, "mock-service-normal.py", setup, test_search_unlock_async, teardown);
1025 g_test_add ("/collection/search-secrets-sync", Test, "mock-service-normal.py", setup, test_search_secrets_sync, teardown);
1026 g_test_add ("/collection/search-secrets-async", Test, "mock-service-normal.py", setup, test_search_secrets_async, teardown);
1028 return egg_tests_run_with_loop ();