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",
183 SECRET_COLLECTION_NONE, NULL, &error);
184 g_assert_no_error (error);
186 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
187 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
188 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_NONE);
189 g_assert (secret_collection_get_items (collection) == NULL);
190 g_object_unref (collection);
192 collection = secret_collection_for_alias_sync (test->service, "unknown",
193 SECRET_COLLECTION_NONE, NULL, &error);
194 g_assert_no_error (error);
195 g_assert (collection == NULL);
199 test_for_alias_async (Test *test,
202 const gchar *collection_path;
203 SecretCollection *collection;
204 GAsyncResult *result = NULL;
205 GError *error = NULL;
207 secret_collection_for_alias (test->service, "default",
208 SECRET_COLLECTION_NONE,
209 NULL, on_async_result, &result);
210 g_assert (result == NULL);
213 collection = secret_collection_for_alias_finish (result, &error);
214 g_assert_no_error (error);
215 g_object_unref (result);
217 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
218 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
219 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_NONE);
220 g_assert (secret_collection_get_items (collection) == NULL);
221 g_object_unref (collection);
224 secret_collection_for_alias (test->service, "unknown",
225 SECRET_COLLECTION_NONE,
226 NULL, on_async_result, &result);
227 g_assert (result == NULL);
230 collection = secret_collection_for_alias_finish (result, &error);
231 g_assert_no_error (error);
232 g_assert (collection == NULL);
233 g_object_unref (result);
237 test_for_alias_load_sync (Test *test,
240 const gchar *collection_path;
241 SecretCollection *collection;
242 GError *error = NULL;
245 collection = secret_collection_for_alias_sync (test->service, "default",
246 SECRET_COLLECTION_LOAD_ITEMS,
248 g_assert_no_error (error);
250 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
251 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
252 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_LOAD_ITEMS);
253 items = secret_collection_get_items (collection);
254 g_assert (items != NULL);
255 g_list_free_full (items, g_object_unref);
256 g_object_unref (collection);
260 test_for_alias_load_async (Test *test,
263 const gchar *collection_path;
264 SecretCollection *collection;
265 GAsyncResult *result = NULL;
266 GError *error = NULL;
269 secret_collection_for_alias (test->service, "default",
270 SECRET_COLLECTION_LOAD_ITEMS,
271 NULL, on_async_result, &result);
272 g_assert (result == NULL);
275 collection = secret_collection_for_alias_finish (result, &error);
276 g_assert_no_error (error);
277 g_object_unref (result);
279 collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
280 g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
281 g_assert_cmpuint (secret_collection_get_flags (collection), ==, SECRET_COLLECTION_LOAD_ITEMS);
282 items = secret_collection_get_items (collection);
283 g_assert (items != NULL);
284 g_list_free_full (items, g_object_unref);
285 g_object_unref (collection);
290 test_create_sync (Test *test,
291 gconstpointer unused)
293 GError *error = NULL;
294 SecretCollection *collection;
296 collection = secret_collection_create_sync (test->service, "Train", NULL,
297 SECRET_COLLECTION_CREATE_NONE, NULL, &error);
298 g_assert_no_error (error);
300 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
301 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
302 g_assert (secret_collection_get_locked (collection) == FALSE);
304 g_object_unref (collection);
305 egg_assert_not_object (collection);
309 test_create_async (Test *test,
310 gconstpointer unused)
312 GError *error = NULL;
313 SecretCollection *collection;
314 GAsyncResult *result = NULL;
316 secret_collection_create (test->service, "Train", NULL,
317 SECRET_COLLECTION_CREATE_NONE,
318 NULL, on_async_result, &result);
319 g_assert (result == NULL);
323 collection = secret_collection_create_finish (result, &error);
324 g_assert_no_error (error);
325 g_object_unref (result);
327 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)), "/org/freedesktop/secrets/collection"));
328 g_assert_cmpstr (secret_collection_get_label (collection), ==, "Train");
329 g_assert (secret_collection_get_locked (collection) == FALSE);
331 g_object_unref (collection);
332 egg_assert_not_object (collection);
336 test_properties (Test *test,
337 gconstpointer unused)
339 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
340 SecretCollection *collection;
341 SecretService *service;
342 GError *error = NULL;
348 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
349 SECRET_COLLECTION_NONE, NULL, &error);
350 g_assert_no_error (error);
352 g_assert (secret_collection_get_locked (collection) == FALSE);
353 g_assert_cmpuint (secret_collection_get_created (collection), <=, time (NULL));
354 g_assert_cmpuint (secret_collection_get_modified (collection), <=, time (NULL));
356 label = secret_collection_get_label (collection);
357 g_assert_cmpstr (label, ==, "Collection One");
360 g_object_get (collection,
363 "modified", &modified,
368 g_assert (locked == FALSE);
369 g_assert_cmpuint (created, <=, time (NULL));
370 g_assert_cmpuint (modified, <=, time (NULL));
372 g_assert_cmpstr (label, ==, "Collection One");
375 g_assert (service == test->service);
376 g_object_unref (service);
378 g_object_unref (collection);
382 check_items_equal (GList *items,
392 va_start (va, items);
393 paths = g_hash_table_new (g_str_hash, g_str_equal);
394 while ((path = va_arg (va, gchar *)) != NULL)
395 g_hash_table_insert (paths, (gpointer)path, (gpointer)path);
398 num_items = g_hash_table_size (paths);
399 g_assert_cmpuint (num_items, ==, g_list_length (items));
401 for (l = items; l != NULL; l = g_list_next (l)) {
402 path = g_dbus_proxy_get_object_path (l->data);
403 have_item = g_hash_table_remove (paths, path);
404 g_assert (have_item);
407 g_hash_table_destroy (paths);
411 test_items (Test *test,
412 gconstpointer unused)
414 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
415 SecretCollection *collection;
416 GError *error = NULL;
419 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
420 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
421 g_assert_no_error (error);
423 items = secret_collection_get_items (collection);
424 check_items_equal (items,
425 "/org/freedesktop/secrets/collection/english/1",
426 "/org/freedesktop/secrets/collection/english/2",
427 "/org/freedesktop/secrets/collection/english/3",
429 g_list_free_full (items, g_object_unref);
431 g_object_get (collection, "items", &items, NULL);
432 check_items_equal (items,
433 "/org/freedesktop/secrets/collection/english/1",
434 "/org/freedesktop/secrets/collection/english/2",
435 "/org/freedesktop/secrets/collection/english/3",
437 g_list_free_full (items, g_object_unref);
439 g_object_unref (collection);
443 test_items_empty (Test *test,
444 gconstpointer unused)
446 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
447 SecretCollection *collection;
448 GError *error = NULL;
451 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
452 SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
453 g_assert_no_error (error);
455 items = secret_collection_get_items (collection);
456 check_items_equal (items, NULL);
457 g_list_free_full (items, g_object_unref);
459 g_object_get (collection, "items", &items, NULL);
460 check_items_equal (items, NULL);
461 g_list_free_full (items, g_object_unref);
463 g_object_unref (collection);
467 test_items_empty_async (Test *test,
468 gconstpointer unused)
470 const gchar *collection_path = "/org/freedesktop/secrets/collection/empty";
471 SecretCollection *collection;
472 GAsyncResult *result = NULL;
473 GError *error = NULL;
476 secret_collection_new_for_dbus_path (test->service, collection_path,
477 SECRET_COLLECTION_LOAD_ITEMS,
478 NULL, on_async_result, &result);
479 g_assert (result == NULL);
483 collection = secret_collection_new_for_dbus_path_finish (result, &error);
484 g_assert_no_error (error);
485 g_object_unref (result);
487 items = secret_collection_get_items (collection);
488 check_items_equal (items, NULL);
489 g_list_free_full (items, g_object_unref);
491 g_object_get (collection, "items", &items, NULL);
492 check_items_equal (items, NULL);
493 g_list_free_full (items, g_object_unref);
495 g_object_unref (collection);
499 test_set_label_sync (Test *test,
500 gconstpointer unused)
502 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
503 GError *error = NULL;
504 SecretCollection *collection;
508 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
509 SECRET_COLLECTION_NONE, NULL, &error);
510 g_assert_no_error (error);
512 label = secret_collection_get_label (collection);
513 g_assert_cmpstr (label, ==, "Collection One");
516 ret = secret_collection_set_label_sync (collection, "Another label", NULL, &error);
517 g_assert_no_error (error);
518 g_assert (ret == TRUE);
520 label = secret_collection_get_label (collection);
521 g_assert_cmpstr (label, ==, "Another label");
524 g_object_unref (collection);
528 test_set_label_async (Test *test,
529 gconstpointer unused)
531 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
532 GAsyncResult *result = NULL;
533 GError *error = NULL;
534 SecretCollection *collection;
538 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
539 SECRET_COLLECTION_NONE, NULL, &error);
540 g_assert_no_error (error);
542 label = secret_collection_get_label (collection);
543 g_assert_cmpstr (label, ==, "Collection One");
546 secret_collection_set_label (collection, "Another label", NULL, on_async_result, &result);
547 g_assert (result == NULL);
551 ret = secret_collection_set_label_finish (collection, result, &error);
552 g_assert_no_error (error);
553 g_assert (ret == TRUE);
554 g_object_unref (result);
556 label = secret_collection_get_label (collection);
557 g_assert_cmpstr (label, ==, "Another label");
560 g_object_unref (collection);
564 test_set_label_prop (Test *test,
565 gconstpointer unused)
567 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
568 GAsyncResult *result = NULL;
569 GError *error = NULL;
570 SecretCollection *collection;
574 secret_collection_new_for_dbus_path (test->service, collection_path, SECRET_COLLECTION_NONE,
575 NULL, on_async_result, &result);
576 g_assert (result == NULL);
578 collection = secret_collection_new_for_dbus_path_finish (result, &error);
579 g_assert_no_error (error);
580 g_object_unref (result);
582 label = secret_collection_get_label (collection);
583 g_assert_cmpstr (label, ==, "Collection One");
586 g_signal_connect (collection, "notify::label", G_CALLBACK (on_notify_stop), &sigs);
587 g_object_set (collection, "label", "Blah blah", NULL);
589 /* Wait for the property to actually 'take' */
592 label = secret_collection_get_label (collection);
593 g_assert_cmpstr (label, ==, "Blah blah");
596 g_object_unref (collection);
600 test_delete_sync (Test *test,
601 gconstpointer unused)
603 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
604 SecretCollection *collection;
605 GError *error = NULL;
608 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
609 SECRET_COLLECTION_NONE, NULL, &error);
610 g_assert_no_error (error);
612 ret = secret_collection_delete_sync (collection, NULL, &error);
613 g_assert_no_error (error);
614 g_assert (ret == TRUE);
616 g_object_unref (collection);
618 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
619 SECRET_COLLECTION_NONE, NULL, &error);
620 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
621 g_assert (collection == NULL);
625 test_delete_async (Test *test,
626 gconstpointer unused)
628 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
629 SecretCollection *collection;
630 GAsyncResult *result = NULL;
631 GError *error = NULL;
634 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
635 SECRET_COLLECTION_NONE, NULL, &error);
636 g_assert_no_error (error);
638 secret_collection_delete (collection, NULL, on_async_result, &result);
639 g_assert (result == NULL);
643 ret = secret_collection_delete_finish (collection, result, &error);
644 g_assert_no_error (error);
645 g_object_unref (result);
646 g_assert (ret == TRUE);
648 g_object_unref (collection);
650 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
651 SECRET_COLLECTION_NONE, NULL, &error);
652 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
653 g_assert (collection == NULL);
657 test_search_sync (Test *test,
660 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
661 SecretCollection *collection;
662 GHashTable *attributes;
663 GError *error = NULL;
666 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
667 SECRET_COLLECTION_NONE, NULL, &error);
668 g_assert_no_error (error);
670 attributes = g_hash_table_new (g_str_hash, g_str_equal);
671 g_hash_table_insert (attributes, "number", "1");
673 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
674 SECRET_SEARCH_NONE, NULL, &error);
675 g_assert_no_error (error);
676 g_hash_table_unref (attributes);
678 g_assert (items != NULL);
679 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
681 g_assert (items->next == NULL);
682 g_list_free_full (items, g_object_unref);
684 g_object_unref (collection);
688 test_search_async (Test *test,
691 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
692 SecretCollection *collection;
693 GAsyncResult *result = NULL;
694 GHashTable *attributes;
695 GError *error = NULL;
698 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
699 SECRET_COLLECTION_NONE, NULL, &error);
700 g_assert_no_error (error);
702 attributes = g_hash_table_new (g_str_hash, g_str_equal);
703 g_hash_table_insert (attributes, "number", "1");
705 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
706 SECRET_SEARCH_NONE, NULL,
707 on_async_result, &result);
708 g_hash_table_unref (attributes);
709 g_assert (result == NULL);
713 g_assert (G_IS_ASYNC_RESULT (result));
714 items = secret_collection_search_finish (collection, result, &error);
715 g_assert_no_error (error);
716 g_object_unref (result);
718 g_assert (items != NULL);
719 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
721 g_assert (items->next == NULL);
722 g_list_free_full (items, g_object_unref);
724 g_object_unref (collection);
728 sort_by_object_path (gconstpointer a,
731 const gchar *pa = g_dbus_proxy_get_object_path ((GDBusProxy *)a);
732 const gchar *pb = g_dbus_proxy_get_object_path ((GDBusProxy *)b);
734 return g_strcmp0 (pa, pb);
738 test_search_all_sync (Test *test,
741 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
742 SecretCollection *collection;
743 GHashTable *attributes;
744 GError *error = NULL;
747 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
748 SECRET_COLLECTION_NONE, NULL, &error);
749 g_assert_no_error (error);
751 attributes = g_hash_table_new (g_str_hash, g_str_equal);
753 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
754 SECRET_SEARCH_ALL, NULL, &error);
755 g_assert_no_error (error);
756 g_hash_table_unref (attributes);
758 items = g_list_sort (items, sort_by_object_path);
760 g_assert (items != NULL);
761 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
762 g_assert (secret_item_get_secret (items->data) == NULL);
764 g_assert (items->next != NULL);
765 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
766 g_assert (secret_item_get_secret (items->next->data) == NULL);
768 g_assert (items->next->next != NULL);
769 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
770 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
772 g_assert (items->next->next->next == NULL);
773 g_list_free_full (items, g_object_unref);
775 g_object_unref (collection);
779 test_search_all_async (Test *test,
782 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
783 SecretCollection *collection;
784 GAsyncResult *result = NULL;
785 GHashTable *attributes;
786 GError *error = NULL;
789 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
790 SECRET_COLLECTION_NONE, NULL, &error);
791 g_assert_no_error (error);
793 attributes = g_hash_table_new (g_str_hash, g_str_equal);
795 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
796 SECRET_SEARCH_ALL, NULL,
797 on_async_result, &result);
798 g_hash_table_unref (attributes);
799 g_assert (result == NULL);
803 g_assert (G_IS_ASYNC_RESULT (result));
804 items = secret_collection_search_finish (collection, result, &error);
805 g_assert_no_error (error);
806 g_object_unref (result);
808 items = g_list_sort (items, sort_by_object_path);
810 g_assert (items != NULL);
811 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
812 g_assert (secret_item_get_secret (items->data) == NULL);
814 g_assert (items->next != NULL);
815 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/english/2");
816 g_assert (secret_item_get_secret (items->next->data) == NULL);
818 g_assert (items->next->next != NULL);
819 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->next->data), ==, "/org/freedesktop/secrets/collection/english/3");
820 g_assert (secret_item_get_secret (items->next->next->data) == NULL);
822 g_assert (items->next->next->next == NULL);
823 g_list_free_full (items, g_object_unref);
825 g_object_unref (collection);
829 test_search_unlock_sync (Test *test,
832 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
833 SecretCollection *collection;
834 GHashTable *attributes;
835 GError *error = NULL;
838 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
839 SECRET_COLLECTION_NONE, NULL, &error);
840 g_assert_no_error (error);
842 attributes = g_hash_table_new (g_str_hash, g_str_equal);
843 g_hash_table_insert (attributes, "number", "1");
845 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
846 SECRET_SEARCH_UNLOCK, NULL, &error);
847 g_assert_no_error (error);
848 g_hash_table_unref (attributes);
850 g_assert (items != NULL);
851 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
852 g_assert (secret_item_get_locked (items->data) == FALSE);
853 g_assert (secret_item_get_secret (items->data) == NULL);
855 g_assert (items->next == NULL);
856 g_list_free_full (items, g_object_unref);
858 g_object_unref (collection);
862 test_search_unlock_async (Test *test,
865 const gchar *collection_path = "/org/freedesktop/secrets/collection/spanish";
866 SecretCollection *collection;
867 GAsyncResult *result = NULL;
868 GHashTable *attributes;
869 GError *error = NULL;
872 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
873 SECRET_COLLECTION_NONE, NULL, &error);
874 g_assert_no_error (error);
876 attributes = g_hash_table_new (g_str_hash, g_str_equal);
877 g_hash_table_insert (attributes, "number", "1");
879 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
880 SECRET_SEARCH_UNLOCK, NULL,
881 on_async_result, &result);
882 g_hash_table_unref (attributes);
883 g_assert (result == NULL);
887 g_assert (G_IS_ASYNC_RESULT (result));
888 items = secret_collection_search_finish (collection, result, &error);
889 g_assert_no_error (error);
890 g_object_unref (result);
892 g_assert (items != NULL);
893 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
894 g_assert (secret_item_get_locked (items->data) == FALSE);
895 g_assert (secret_item_get_secret (items->data) == NULL);
897 g_assert (items->next == NULL);
898 g_list_free_full (items, g_object_unref);
900 g_object_unref (collection);
904 test_search_secrets_sync (Test *test,
907 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
908 SecretCollection *collection;
909 GHashTable *attributes;
910 GError *error = NULL;
914 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
915 SECRET_COLLECTION_NONE, NULL, &error);
916 g_assert_no_error (error);
918 attributes = g_hash_table_new (g_str_hash, g_str_equal);
919 g_hash_table_insert (attributes, "number", "1");
921 items = secret_collection_search_sync (collection, &MOCK_SCHEMA, attributes,
922 SECRET_SEARCH_LOAD_SECRETS,
924 g_assert_no_error (error);
925 g_hash_table_unref (attributes);
927 g_assert (items != NULL);
928 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
929 g_assert (secret_item_get_locked (items->data) == FALSE);
930 value = secret_item_get_secret (items->data);
931 g_assert (value != NULL);
932 secret_value_unref (value);
934 g_assert (items->next == NULL);
935 g_list_free_full (items, g_object_unref);
937 g_object_unref (collection);
941 test_search_secrets_async (Test *test,
944 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
945 SecretCollection *collection;
946 GAsyncResult *result = NULL;
947 GHashTable *attributes;
948 GError *error = NULL;
952 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
953 SECRET_COLLECTION_NONE, NULL, &error);
954 g_assert_no_error (error);
956 attributes = g_hash_table_new (g_str_hash, g_str_equal);
957 g_hash_table_insert (attributes, "number", "1");
959 secret_collection_search (collection, &MOCK_SCHEMA, attributes,
960 SECRET_SEARCH_LOAD_SECRETS, NULL,
961 on_async_result, &result);
962 g_hash_table_unref (attributes);
963 g_assert (result == NULL);
967 g_assert (G_IS_ASYNC_RESULT (result));
968 items = secret_collection_search_finish (collection, result, &error);
969 g_assert_no_error (error);
970 g_object_unref (result);
972 g_assert (items != NULL);
973 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
974 g_assert (secret_item_get_locked (items->data) == FALSE);
975 value = secret_item_get_secret (items->data);
976 g_assert (value != NULL);
977 secret_value_unref (value);
979 g_assert (items->next == NULL);
980 g_list_free_full (items, g_object_unref);
982 g_object_unref (collection);
986 main (int argc, char **argv)
988 g_test_init (&argc, &argv, NULL);
989 g_set_prgname ("test-collection");
990 #if !GLIB_CHECK_VERSION(2,35,0)
994 g_test_add ("/collection/new-sync", Test, "mock-service-normal.py", setup, test_new_sync, teardown);
995 g_test_add ("/collection/new-async", Test, "mock-service-normal.py", setup, test_new_async, teardown);
996 g_test_add ("/collection/new-sync-noexist", Test, "mock-service-normal.py", setup, test_new_sync_noexist, teardown);
997 g_test_add ("/collection/new-async-noexist", Test, "mock-service-normal.py", setup, test_new_async_noexist, teardown);
998 g_test_add ("/collection/for-alias-sync", Test, "mock-service-normal.py", setup, test_for_alias_sync, teardown);
999 g_test_add ("/collection/for-alias-async", Test, "mock-service-normal.py", setup, test_for_alias_async, teardown);
1000 g_test_add ("/collection/for-alias-load-sync", Test, "mock-service-normal.py", setup, test_for_alias_load_sync, teardown);
1001 g_test_add ("/collection/for-alias-load-async", Test, "mock-service-normal.py", setup, test_for_alias_load_async, teardown);
1002 g_test_add ("/collection/create-sync", Test, "mock-service-normal.py", setup, test_create_sync, teardown);
1003 g_test_add ("/collection/create-async", Test, "mock-service-normal.py", setup, test_create_async, teardown);
1004 g_test_add ("/collection/properties", Test, "mock-service-normal.py", setup, test_properties, teardown);
1005 g_test_add ("/collection/items", Test, "mock-service-normal.py", setup, test_items, teardown);
1006 g_test_add ("/collection/items-empty", Test, "mock-service-normal.py", setup, test_items_empty, teardown);
1007 g_test_add ("/collection/items-empty-async", Test, "mock-service-normal.py", setup, test_items_empty_async, teardown);
1008 g_test_add ("/collection/set-label-sync", Test, "mock-service-normal.py", setup, test_set_label_sync, teardown);
1009 g_test_add ("/collection/set-label-async", Test, "mock-service-normal.py", setup, test_set_label_async, teardown);
1010 g_test_add ("/collection/set-label-prop", Test, "mock-service-normal.py", setup, test_set_label_prop, teardown);
1011 g_test_add ("/collection/delete-sync", Test, "mock-service-normal.py", setup, test_delete_sync, teardown);
1012 g_test_add ("/collection/delete-async", Test, "mock-service-normal.py", setup, test_delete_async, teardown);
1014 g_test_add ("/collection/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
1015 g_test_add ("/collection/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
1016 g_test_add ("/collection/search-all-sync", Test, "mock-service-normal.py", setup, test_search_all_sync, teardown);
1017 g_test_add ("/collection/search-all-async", Test, "mock-service-normal.py", setup, test_search_all_async, teardown);
1018 g_test_add ("/collection/search-unlock-sync", Test, "mock-service-normal.py", setup, test_search_unlock_sync, teardown);
1019 g_test_add ("/collection/search-unlock-async", Test, "mock-service-normal.py", setup, test_search_unlock_async, teardown);
1020 g_test_add ("/collection/search-secrets-sync", Test, "mock-service-normal.py", setup, test_search_secrets_sync, teardown);
1021 g_test_add ("/collection/search-secrets-async", Test, "mock-service-normal.py", setup, test_search_secrets_async, teardown);
1023 return egg_tests_run_with_loop ();