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);
64 g_object_unref (test->service);
65 secret_service_disconnect ();
66 egg_assert_not_object (test->service);
72 on_async_result (GObject *source,
76 GAsyncResult **ret = user_data;
77 g_assert (ret != NULL);
78 g_assert (*ret == NULL);
79 *ret = g_object_ref (result);
80 egg_test_wait_stop ();
84 on_notify_stop (GObject *obj,
88 guint *sigs = user_data;
89 g_assert (sigs != NULL);
92 egg_test_wait_stop ();
96 test_new_sync (Test *test,
99 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
100 GError *error = NULL;
101 SecretCollection *collection;
103 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
104 SECRET_COLLECTION_NONE, NULL, &error);
105 g_assert_no_error (error);
107 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), ==, collection_path);
109 g_object_unref (collection);
110 egg_assert_not_object (collection);
114 test_new_async (Test *test,
115 gconstpointer unused)
117 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
118 GError *error = NULL;
119 SecretCollection *collection;
120 GAsyncResult *result = NULL;
122 secret_collection_new_for_dbus_path (test->service, collection_path,
123 SECRET_COLLECTION_NONE, NULL, on_async_result, &result);
124 g_assert (result == NULL);
128 collection = secret_collection_new_for_dbus_path_finish (result, &error);
129 g_assert_no_error (error);
130 g_object_unref (result);
132 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), ==, collection_path);
134 g_object_unref (collection);
135 egg_assert_not_object (collection);
139 test_new_sync_noexist (Test *test,
140 gconstpointer unused)
142 const gchar *collection_path = "/org/freedesktop/secrets/collection/nonexistant";
143 GError *error = NULL;
144 SecretCollection *collection;
146 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
147 SECRET_COLLECTION_NONE, NULL, &error);
148 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
149 g_assert (collection == NULL);
153 test_new_async_noexist (Test *test,
154 gconstpointer unused)
156 const gchar *collection_path = "/org/freedesktop/secrets/collection/nonexistant";
157 GError *error = NULL;
158 SecretCollection *collection;
159 GAsyncResult *result = NULL;
161 secret_collection_new_for_dbus_path (test->service, collection_path,
162 SECRET_COLLECTION_NONE, NULL, on_async_result, &result);
163 g_assert (result == NULL);
167 collection = secret_collection_new_for_dbus_path_finish (result, &error);
168 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
169 g_assert (collection == NULL);
170 g_object_unref (result);
175 test_for_alias_sync (Test *test,
178 const gchar *collection_path;
179 SecretCollection *collection;
180 GError *error = NULL;
182 collection = secret_collection_for_alias_sync (test->service, "default", NULL, &error);
183 g_assert_no_error (error);
185 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
186 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
187 g_object_unref (collection);
189 collection = secret_collection_for_alias_sync (test->service, "unknown", NULL, &error);
190 g_assert_no_error (error);
191 g_assert (collection == NULL);
195 test_for_alias_async (Test *test,
198 const gchar *collection_path;
199 SecretCollection *collection;
200 GAsyncResult *result = NULL;
201 GError *error = NULL;
203 secret_collection_for_alias (test->service, "default", NULL,
204 on_async_result, &result);
205 g_assert (result == NULL);
208 collection = secret_collection_for_alias_finish (result, &error);
209 g_assert_no_error (error);
210 g_object_unref (result);
212 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
213 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
214 g_object_unref (collection);
217 secret_collection_for_alias (test->service, "unknown", NULL,
218 on_async_result, &result);
219 g_assert (result == NULL);
222 collection = secret_collection_for_alias_finish (result, &error);
223 g_assert_no_error (error);
224 g_assert (collection == NULL);
225 g_object_unref (result);
230 test_create_sync (Test *test,
231 gconstpointer unused)
233 GError *error = NULL;
234 SecretCollection *collection;
236 collection = secret_collection_create_sync (test->service, "Train", NULL,
237 SECRET_COLLECTION_CREATE_NONE, NULL, &error);
238 g_assert_no_error (error);
240 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
241 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
242 g_assert (secret_collection_get_locked (collection) == FALSE);
244 g_object_unref (collection);
245 egg_assert_not_object (collection);
249 test_create_async (Test *test,
250 gconstpointer unused)
252 GError *error = NULL;
253 SecretCollection *collection;
254 GAsyncResult *result = NULL;
256 secret_collection_create (test->service, "Train", NULL,
257 SECRET_COLLECTION_CREATE_NONE,
258 NULL, on_async_result, &result);
259 g_assert (result == NULL);
263 collection = secret_collection_create_finish (result, &error);
264 g_assert_no_error (error);
265 g_object_unref (result);
267 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
268 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
269 g_assert (secret_collection_get_locked (collection) == FALSE);
271 g_object_unref (collection);
272 egg_assert_not_object (collection);
276 test_properties (Test *test,
277 gconstpointer unused)
279 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
280 SecretCollection *collection;
281 SecretService *service;
282 GError *error = NULL;
288 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
289 SECRET_COLLECTION_NONE, NULL, &error);
290 g_assert_no_error (error);
292 g_assert (secret_collection_get_locked (collection) == FALSE);
293 g_assert_cmpuint (secret_collection_get_created (collection), <=, time (NULL));
294 g_assert_cmpuint (secret_collection_get_modified (collection), <=, time (NULL));
296 label = secret_collection_get_label (collection);
297 g_assert_cmpstr (label, ==, "Collection One");
300 g_object_get (collection,
303 "modified", &modified,
308 g_assert (locked == FALSE);
309 g_assert_cmpuint (created, <=, time (NULL));
310 g_assert_cmpuint (modified, <=, time (NULL));
312 g_assert_cmpstr (label, ==, "Collection One");
315 g_assert (service == test->service);
316 g_object_unref (service);
318 g_object_unref (collection);
322 check_items_equal (GList *items,
332 va_start (va, items);
333 paths = g_hash_table_new (g_str_hash, g_str_equal);
334 while ((path = va_arg (va, gchar *)) != NULL)
335 g_hash_table_insert (paths, (gpointer)path, (gpointer)path);
338 num_items = g_hash_table_size (paths);
339 g_assert_cmpuint (num_items, ==, g_list_length (items));
341 for (l = items; l != NULL; l = g_list_next (l)) {
342 path = g_dbus_proxy_get_object_path (l->data);
343 have_item = g_hash_table_remove (paths, path);
344 g_assert (have_item);
347 g_hash_table_destroy (paths);
351 test_items (Test *test,
352 gconstpointer unused)
354 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
355 SecretCollection *collection;
356 GError *error = NULL;
359 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
360 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
361 g_assert_no_error (error);
363 items = secret_collection_get_items (collection);
364 check_items_equal (items,
365 "/org/freedesktop/secrets/collection/english/1",
366 "/org/freedesktop/secrets/collection/english/2",
367 "/org/freedesktop/secrets/collection/english/3",
369 g_list_free_full (items, g_object_unref);
371 g_object_get (collection, "items", &items, NULL);
372 check_items_equal (items,
373 "/org/freedesktop/secrets/collection/english/1",
374 "/org/freedesktop/secrets/collection/english/2",
375 "/org/freedesktop/secrets/collection/english/3",
377 g_list_free_full (items, g_object_unref);
379 g_object_unref (collection);
383 test_items_empty (Test *test,
384 gconstpointer unused)
386 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
387 SecretCollection *collection;
388 GError *error = NULL;
391 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
392 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
393 g_assert_no_error (error);
395 items = secret_collection_get_items (collection);
396 check_items_equal (items, NULL);
397 g_list_free_full (items, g_object_unref);
399 g_object_get (collection, "items", &items, NULL);
400 check_items_equal (items, NULL);
401 g_list_free_full (items, g_object_unref);
403 g_object_unref (collection);
407 test_items_empty_async (Test *test,
408 gconstpointer unused)
410 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
411 SecretCollection *collection;
412 GAsyncResult *result = NULL;
413 GError *error = NULL;
416 secret_collection_new_for_dbus_path (test->service, collection_path,
417 SECRET_COLLECTION_LOAD_ITEMS,
418 NULL, on_async_result, &result);
419 g_assert (result == NULL);
423 collection = secret_collection_new_for_dbus_path_finish (result, &error);
424 g_assert_no_error (error);
425 g_object_unref (result);
427 items = secret_collection_get_items (collection);
428 check_items_equal (items, NULL);
429 g_list_free_full (items, g_object_unref);
431 g_object_get (collection, "items", &items, NULL);
432 check_items_equal (items, NULL);
433 g_list_free_full (items, g_object_unref);
435 g_object_unref (collection);
439 test_set_label_sync (Test *test,
440 gconstpointer unused)
442 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
443 GError *error = NULL;
444 SecretCollection *collection;
448 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
449 SECRET_COLLECTION_NONE, NULL, &error);
450 g_assert_no_error (error);
452 label = secret_collection_get_label (collection);
453 g_assert_cmpstr (label, ==, "Collection One");
456 ret = secret_collection_set_label_sync (collection, "Another label", NULL, &error);
457 g_assert_no_error (error);
458 g_assert (ret == TRUE);
460 label = secret_collection_get_label (collection);
461 g_assert_cmpstr (label, ==, "Another label");
464 g_object_unref (collection);
468 test_set_label_async (Test *test,
469 gconstpointer unused)
471 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
472 GAsyncResult *result = NULL;
473 GError *error = NULL;
474 SecretCollection *collection;
478 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
479 SECRET_COLLECTION_NONE, NULL, &error);
480 g_assert_no_error (error);
482 label = secret_collection_get_label (collection);
483 g_assert_cmpstr (label, ==, "Collection One");
486 secret_collection_set_label (collection, "Another label", NULL, on_async_result, &result);
487 g_assert (result == NULL);
491 ret = secret_collection_set_label_finish (collection, result, &error);
492 g_assert_no_error (error);
493 g_assert (ret == TRUE);
494 g_object_unref (result);
496 label = secret_collection_get_label (collection);
497 g_assert_cmpstr (label, ==, "Another label");
500 g_object_unref (collection);
504 test_set_label_prop (Test *test,
505 gconstpointer unused)
507 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
508 GAsyncResult *result = NULL;
509 GError *error = NULL;
510 SecretCollection *collection;
514 secret_collection_new_for_dbus_path (test->service, collection_path, SECRET_COLLECTION_NONE,
515 NULL, on_async_result, &result);
516 g_assert (result == NULL);
518 collection = secret_collection_new_for_dbus_path_finish (result, &error);
519 g_assert_no_error (error);
520 g_object_unref (result);
522 label = secret_collection_get_label (collection);
523 g_assert_cmpstr (label, ==, "Collection One");
526 g_signal_connect (collection, "notify::label", G_CALLBACK (on_notify_stop), &sigs);
527 g_object_set (collection, "label", "Blah blah", NULL);
529 /* Wait for the property to actually 'take' */
532 label = secret_collection_get_label (collection);
533 g_assert_cmpstr (label, ==, "Blah blah");
536 g_object_unref (collection);
540 test_delete_sync (Test *test,
541 gconstpointer unused)
543 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
544 SecretCollection *collection;
545 GError *error = NULL;
548 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
549 SECRET_COLLECTION_NONE, NULL, &error);
550 g_assert_no_error (error);
552 ret = secret_collection_delete_sync (collection, NULL, &error);
553 g_assert_no_error (error);
554 g_assert (ret == TRUE);
556 g_object_unref (collection);
558 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
559 SECRET_COLLECTION_NONE, NULL, &error);
560 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
561 g_assert (collection == NULL);
565 test_delete_async (Test *test,
566 gconstpointer unused)
568 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
569 SecretCollection *collection;
570 GAsyncResult *result = NULL;
571 GError *error = NULL;
574 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
575 SECRET_COLLECTION_NONE, NULL, &error);
576 g_assert_no_error (error);
578 secret_collection_delete (collection, NULL, on_async_result, &result);
579 g_assert (result == NULL);
583 ret = secret_collection_delete_finish (collection, result, &error);
584 g_assert_no_error (error);
585 g_object_unref (result);
586 g_assert (ret == TRUE);
588 g_object_unref (collection);
590 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
591 SECRET_COLLECTION_NONE, NULL, &error);
592 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
593 g_assert (collection == NULL);
597 test_search_sync (Test *test,
600 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
601 SecretCollection *collection;
602 GHashTable *attributes;
603 GError *error = NULL;
606 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
607 SECRET_COLLECTION_NONE, NULL, &error);
608 g_assert_no_error (error);
610 attributes = g_hash_table_new (g_str_hash, g_str_equal);
611 g_hash_table_insert (attributes, "number", "1");
613 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
614 SECRET_SEARCH_NONE, NULL, &error);
615 g_assert_no_error (error);
616 g_hash_table_unref (attributes);
618 g_assert (items != NULL);
619 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
621 g_assert (items->next == NULL);
622 g_list_free_full (items, g_object_unref);
624 g_object_unref (collection);
628 test_search_async (Test *test,
631 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
632 SecretCollection *collection;
633 GAsyncResult *result = NULL;
634 GHashTable *attributes;
635 GError *error = NULL;
638 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
639 SECRET_COLLECTION_NONE, NULL, &error);
640 g_assert_no_error (error);
642 attributes = g_hash_table_new (g_str_hash, g_str_equal);
643 g_hash_table_insert (attributes, "number", "1");
645 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
646 SECRET_SEARCH_NONE, NULL,
647 on_async_result, &result);
648 g_hash_table_unref (attributes);
649 g_assert (result == NULL);
653 g_assert (G_IS_ASYNC_RESULT (result));
654 items = secret_collection_search_finish (collection, result, &error);
655 g_assert_no_error (error);
656 g_object_unref (result);
658 g_assert (items != NULL);
659 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
661 g_assert (items->next == NULL);
662 g_list_free_full (items, g_object_unref);
664 g_object_unref (collection);
668 sort_by_object_path (gconstpointer a,
671 const gchar *pa = g_dbus_proxy_get_object_path ((GDBusProxy *)a);
672 const gchar *pb = g_dbus_proxy_get_object_path ((GDBusProxy *)b);
674 return g_strcmp0 (pa, pb);
678 test_search_all_sync (Test *test,
681 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
682 SecretCollection *collection;
683 GHashTable *attributes;
684 GError *error = NULL;
687 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
688 SECRET_COLLECTION_NONE, NULL, &error);
689 g_assert_no_error (error);
691 attributes = g_hash_table_new (g_str_hash, g_str_equal);
693 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
694 SECRET_SEARCH_ALL, NULL, &error);
695 g_assert_no_error (error);
696 g_hash_table_unref (attributes);
698 items = g_list_sort (items, sort_by_object_path);
700 g_assert (items != NULL);
701 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
702 g_assert (secret_item_get_secret (items->data) == NULL);
704 g_assert (items->next != NULL);
705 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
706 g_assert (secret_item_get_secret (items->next->data) == NULL);
708 g_assert (items->next->next != NULL);
709 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
710 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
712 g_assert (items->next->next->next == NULL);
713 g_list_free_full (items, g_object_unref);
715 g_object_unref (collection);
719 test_search_all_async (Test *test,
722 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
723 SecretCollection *collection;
724 GAsyncResult *result = NULL;
725 GHashTable *attributes;
726 GError *error = NULL;
729 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
730 SECRET_COLLECTION_NONE, NULL, &error);
731 g_assert_no_error (error);
733 attributes = g_hash_table_new (g_str_hash, g_str_equal);
735 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
736 SECRET_SEARCH_ALL, NULL,
737 on_async_result, &result);
738 g_hash_table_unref (attributes);
739 g_assert (result == NULL);
743 g_assert (G_IS_ASYNC_RESULT (result));
744 items = secret_collection_search_finish (collection, result, &error);
745 g_assert_no_error (error);
746 g_object_unref (result);
748 items = g_list_sort (items, sort_by_object_path);
750 g_assert (items != NULL);
751 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
752 g_assert (secret_item_get_secret (items->data) == NULL);
754 g_assert (items->next != NULL);
755 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
756 g_assert (secret_item_get_secret (items->next->data) == NULL);
758 g_assert (items->next->next != NULL);
759 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
760 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
762 g_assert (items->next->next->next == NULL);
763 g_list_free_full (items, g_object_unref);
765 g_object_unref (collection);
769 test_search_unlock_sync (Test *test,
772 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
773 SecretCollection *collection;
774 GHashTable *attributes;
775 GError *error = NULL;
778 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
779 SECRET_COLLECTION_NONE, NULL, &error);
780 g_assert_no_error (error);
782 attributes = g_hash_table_new (g_str_hash, g_str_equal);
783 g_hash_table_insert (attributes, "number", "1");
785 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
786 SECRET_SEARCH_UNLOCK, NULL, &error);
787 g_assert_no_error (error);
788 g_hash_table_unref (attributes);
790 g_assert (items != NULL);
791 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
792 g_assert (secret_item_get_locked (items->data) == FALSE);
793 g_assert (secret_item_get_secret (items->data) == NULL);
795 g_assert (items->next == NULL);
796 g_list_free_full (items, g_object_unref);
798 g_object_unref (collection);
802 test_search_unlock_async (Test *test,
805 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
806 SecretCollection *collection;
807 GAsyncResult *result = NULL;
808 GHashTable *attributes;
809 GError *error = NULL;
812 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
813 SECRET_COLLECTION_NONE, NULL, &error);
814 g_assert_no_error (error);
816 attributes = g_hash_table_new (g_str_hash, g_str_equal);
817 g_hash_table_insert (attributes, "number", "1");
819 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
820 SECRET_SEARCH_UNLOCK, NULL,
821 on_async_result, &result);
822 g_hash_table_unref (attributes);
823 g_assert (result == NULL);
827 g_assert (G_IS_ASYNC_RESULT (result));
828 items = secret_collection_search_finish (collection, result, &error);
829 g_assert_no_error (error);
830 g_object_unref (result);
832 g_assert (items != NULL);
833 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
834 g_assert (secret_item_get_locked (items->data) == FALSE);
835 g_assert (secret_item_get_secret (items->data) == NULL);
837 g_assert (items->next == NULL);
838 g_list_free_full (items, g_object_unref);
840 g_object_unref (collection);
844 test_search_secrets_sync (Test *test,
847 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
848 SecretCollection *collection;
849 GHashTable *attributes;
850 GError *error = NULL;
854 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
855 SECRET_COLLECTION_NONE, NULL, &error);
856 g_assert_no_error (error);
858 attributes = g_hash_table_new (g_str_hash, g_str_equal);
859 g_hash_table_insert (attributes, "number", "1");
861 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
862 SECRET_SEARCH_LOAD_SECRETS,
864 g_assert_no_error (error);
865 g_hash_table_unref (attributes);
867 g_assert (items != NULL);
868 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
869 g_assert (secret_item_get_locked (items->data) == FALSE);
870 value = secret_item_get_secret (items->data);
871 g_assert (value != NULL);
872 secret_value_unref (value);
874 g_assert (items->next == NULL);
875 g_list_free_full (items, g_object_unref);
877 g_object_unref (collection);
881 test_search_secrets_async (Test *test,
884 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
885 SecretCollection *collection;
886 GAsyncResult *result = NULL;
887 GHashTable *attributes;
888 GError *error = NULL;
892 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
893 SECRET_COLLECTION_NONE, NULL, &error);
894 g_assert_no_error (error);
896 attributes = g_hash_table_new (g_str_hash, g_str_equal);
897 g_hash_table_insert (attributes, "number", "1");
899 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
900 SECRET_SEARCH_LOAD_SECRETS, NULL,
901 on_async_result, &result);
902 g_hash_table_unref (attributes);
903 g_assert (result == NULL);
907 g_assert (G_IS_ASYNC_RESULT (result));
908 items = secret_collection_search_finish (collection, result, &error);
909 g_assert_no_error (error);
910 g_object_unref (result);
912 g_assert (items != NULL);
913 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
914 g_assert (secret_item_get_locked (items->data) == FALSE);
915 value = secret_item_get_secret (items->data);
916 g_assert (value != NULL);
917 secret_value_unref (value);
919 g_assert (items->next == NULL);
920 g_list_free_full (items, g_object_unref);
922 g_object_unref (collection);
926 main (int argc, char **argv)
928 g_test_init (&argc, &argv, NULL);
929 g_set_prgname ("test-collection");
932 g_test_add ("/collection/new-sync", Test, "mock-service-normal.py", setup, test_new_sync, teardown);
933 g_test_add ("/collection/new-async", Test, "mock-service-normal.py", setup, test_new_async, teardown);
934 g_test_add ("/collection/new-sync-noexist", Test, "mock-service-normal.py", setup, test_new_sync_noexist, teardown);
935 g_test_add ("/collection/new-async-noexist", Test, "mock-service-normal.py", setup, test_new_async_noexist, teardown);
936 g_test_add ("/collection/for-alias-sync", Test, "mock-service-normal.py", setup, test_for_alias_sync, teardown);
937 g_test_add ("/collection/for-alias-async", Test, "mock-service-normal.py", setup, test_for_alias_async, teardown);
938 g_test_add ("/collection/create-sync", Test, "mock-service-normal.py", setup, test_create_sync, teardown);
939 g_test_add ("/collection/create-async", Test, "mock-service-normal.py", setup, test_create_async, teardown);
940 g_test_add ("/collection/properties", Test, "mock-service-normal.py", setup, test_properties, teardown);
941 g_test_add ("/collection/items", Test, "mock-service-normal.py", setup, test_items, teardown);
942 g_test_add ("/collection/items-empty", Test, "mock-service-normal.py", setup, test_items_empty, teardown);
943 g_test_add ("/collection/items-empty-async", Test, "mock-service-normal.py", setup, test_items_empty_async, teardown);
944 g_test_add ("/collection/set-label-sync", Test, "mock-service-normal.py", setup, test_set_label_sync, teardown);
945 g_test_add ("/collection/set-label-async", Test, "mock-service-normal.py", setup, test_set_label_async, teardown);
946 g_test_add ("/collection/set-label-prop", Test, "mock-service-normal.py", setup, test_set_label_prop, teardown);
947 g_test_add ("/collection/delete-sync", Test, "mock-service-normal.py", setup, test_delete_sync, teardown);
948 g_test_add ("/collection/delete-async", Test, "mock-service-normal.py", setup, test_delete_async, teardown);
950 g_test_add ("/collection/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
951 g_test_add ("/collection/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
952 g_test_add ("/collection/search-all-sync", Test, "mock-service-normal.py", setup, test_search_all_sync, teardown);
953 g_test_add ("/collection/search-all-async", Test, "mock-service-normal.py", setup, test_search_all_async, teardown);
954 g_test_add ("/collection/search-unlock-sync", Test, "mock-service-normal.py", setup, test_search_unlock_sync, teardown);
955 g_test_add ("/collection/search-unlock-async", Test, "mock-service-normal.py", setup, test_search_unlock_async, teardown);
956 g_test_add ("/collection/search-secrets-sync", Test, "mock-service-normal.py", setup, test_search_secrets_sync, teardown);
957 g_test_add ("/collection/search-secrets-async", Test, "mock-service-normal.py", setup, test_search_secrets_async, teardown);
959 return egg_tests_run_with_loop ();