1 /* libsecret - GLib wrapper for Secret Service
3 * Copyright 2011 Collabora Ltd.
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.
16 #include "secret-attributes.h"
17 #include "secret-collection.h"
18 #include "secret-item.h"
19 #include "secret-paths.h"
20 #include "secret-private.h"
21 #include "secret-service.h"
23 #include "mock-service.h"
25 #include "egg/egg-testing.h"
32 static const SecretSchema MOCK_SCHEMA = {
36 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
37 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
38 { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
42 static const SecretSchema PRIME_SCHEMA = {
46 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
47 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
48 { "prime", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
52 static const SecretSchema NO_NAME_SCHEMA = {
54 SECRET_SCHEMA_DONT_MATCH_NAME,
56 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
57 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
62 SecretService *service;
66 setup_mock (Test *test,
70 const gchar *mock_script = data;
72 mock_service_start (mock_script, &error);
73 g_assert_no_error (error);
82 setup_mock (test, data);
84 test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
85 g_assert_no_error (error);
86 g_object_add_weak_pointer (G_OBJECT (test->service), (gpointer *)&test->service);
90 teardown_mock (Test *test,
93 secret_service_disconnect ();
101 egg_test_wait_idle ();
103 g_object_unref (test->service);
104 secret_service_disconnect ();
105 g_assert (test->service == NULL);
107 teardown_mock (test, unused);
111 on_complete_get_result (GObject *source,
112 GAsyncResult *result,
115 GAsyncResult **ret = user_data;
116 g_assert (ret != NULL);
117 g_assert (*ret == NULL);
118 *ret = g_object_ref (result);
119 egg_test_wait_stop ();
123 test_search_sync (Test *test,
126 GHashTable *attributes;
127 GError *error = NULL;
130 attributes = g_hash_table_new (g_str_hash, g_str_equal);
131 g_hash_table_insert (attributes, "number", "1");
133 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
134 SECRET_SEARCH_NONE, NULL, &error);
135 g_assert_no_error (error);
136 g_hash_table_unref (attributes);
138 g_assert (items != NULL);
139 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
141 g_assert (items->next == NULL);
142 g_list_free_full (items, g_object_unref);
146 test_search_async (Test *test,
149 GAsyncResult *result = NULL;
150 GHashTable *attributes;
151 GError *error = NULL;
154 attributes = g_hash_table_new (g_str_hash, g_str_equal);
155 g_hash_table_insert (attributes, "number", "1");
157 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
158 SECRET_SEARCH_NONE, NULL,
159 on_complete_get_result, &result);
160 g_hash_table_unref (attributes);
161 g_assert (result == NULL);
165 g_assert (G_IS_ASYNC_RESULT (result));
166 items = secret_service_search_finish (test->service, result, &error);
167 g_assert_no_error (error);
168 g_object_unref (result);
170 g_assert (items != NULL);
171 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
173 g_assert (items->next == NULL);
174 g_list_free_full (items, g_object_unref);
178 test_search_all_sync (Test *test,
181 GHashTable *attributes;
182 GError *error = NULL;
185 attributes = g_hash_table_new (g_str_hash, g_str_equal);
186 g_hash_table_insert (attributes, "number", "1");
188 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
189 SECRET_SEARCH_ALL, NULL, &error);
190 g_assert_no_error (error);
191 g_hash_table_unref (attributes);
193 g_assert (items != NULL);
194 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
195 g_assert (secret_item_get_locked (items->data) == FALSE);
196 g_assert (secret_item_get_secret (items->data) == NULL);
198 g_assert (items->next != NULL);
199 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
200 g_assert (secret_item_get_locked (items->next->data) == TRUE);
201 g_assert (secret_item_get_secret (items->next->data) == NULL);
203 g_assert (items->next->next == NULL);
204 g_list_free_full (items, g_object_unref);
208 test_search_all_async (Test *test,
211 GAsyncResult *result = NULL;
212 GHashTable *attributes;
213 GError *error = NULL;
216 attributes = g_hash_table_new (g_str_hash, g_str_equal);
217 g_hash_table_insert (attributes, "number", "1");
219 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
220 SECRET_SEARCH_ALL, NULL,
221 on_complete_get_result, &result);
222 g_hash_table_unref (attributes);
223 g_assert (result == NULL);
227 g_assert (G_IS_ASYNC_RESULT (result));
228 items = secret_service_search_finish (test->service, result, &error);
229 g_assert_no_error (error);
230 g_object_unref (result);
232 g_assert (items != NULL);
233 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
234 g_assert (secret_item_get_locked (items->data) == FALSE);
235 g_assert (secret_item_get_secret (items->data) == NULL);
237 g_assert (items->next != NULL);
238 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
239 g_assert (secret_item_get_locked (items->next->data) == TRUE);
240 g_assert (secret_item_get_secret (items->next->data) == NULL);
242 g_assert (items->next->next == NULL);
243 g_list_free_full (items, g_object_unref);
247 test_search_unlock_sync (Test *test,
250 GHashTable *attributes;
251 GError *error = NULL;
254 attributes = g_hash_table_new (g_str_hash, g_str_equal);
255 g_hash_table_insert (attributes, "number", "1");
257 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
258 SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK,
260 g_assert_no_error (error);
261 g_hash_table_unref (attributes);
263 g_assert (items != NULL);
264 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
265 g_assert (secret_item_get_locked (items->data) == FALSE);
266 g_assert (secret_item_get_secret (items->data) == NULL);
268 g_assert (items->next != NULL);
269 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
270 g_assert (secret_item_get_locked (items->next->data) == FALSE);
271 g_assert (secret_item_get_secret (items->next->data) == NULL);
273 g_assert (items->next->next == NULL);
274 g_list_free_full (items, g_object_unref);
278 test_search_unlock_async (Test *test,
281 GAsyncResult *result = NULL;
282 GHashTable *attributes;
283 GError *error = NULL;
286 attributes = g_hash_table_new (g_str_hash, g_str_equal);
287 g_hash_table_insert (attributes, "number", "1");
289 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
290 SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK, NULL,
291 on_complete_get_result, &result);
292 g_hash_table_unref (attributes);
293 g_assert (result == NULL);
297 g_assert (G_IS_ASYNC_RESULT (result));
298 items = secret_service_search_finish (test->service, result, &error);
299 g_assert_no_error (error);
300 g_object_unref (result);
302 g_assert (items != NULL);
303 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
304 g_assert (secret_item_get_locked (items->data) == FALSE);
305 g_assert (secret_item_get_secret (items->data) == NULL);
307 g_assert (items->next != NULL);
308 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
309 g_assert (secret_item_get_locked (items->next->data) == FALSE);
310 g_assert (secret_item_get_secret (items->next->data) == NULL);
312 g_assert (items->next->next == NULL);
313 g_list_free_full (items, g_object_unref);
317 test_search_secrets_sync (Test *test,
320 GHashTable *attributes;
321 GError *error = NULL;
325 attributes = g_hash_table_new (g_str_hash, g_str_equal);
326 g_hash_table_insert (attributes, "number", "1");
328 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
329 SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS,
331 g_assert_no_error (error);
332 g_hash_table_unref (attributes);
334 g_assert (items != NULL);
335 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
336 g_assert (secret_item_get_locked (items->data) == FALSE);
337 value = secret_item_get_secret (items->data);
338 g_assert (value != NULL);
339 secret_value_unref (value);
341 g_assert (items->next != NULL);
342 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
343 g_assert (secret_item_get_locked (items->next->data) == TRUE);
344 g_assert (secret_item_get_secret (items->next->data) == NULL);
346 g_assert (items->next->next == NULL);
347 g_list_free_full (items, g_object_unref);
351 test_search_secrets_async (Test *test,
354 GAsyncResult *result = NULL;
355 GHashTable *attributes;
356 GError *error = NULL;
360 attributes = g_hash_table_new (g_str_hash, g_str_equal);
361 g_hash_table_insert (attributes, "number", "1");
363 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
364 SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS, NULL,
365 on_complete_get_result, &result);
366 g_hash_table_unref (attributes);
367 g_assert (result == NULL);
371 g_assert (G_IS_ASYNC_RESULT (result));
372 items = secret_service_search_finish (test->service, result, &error);
373 g_assert_no_error (error);
374 g_object_unref (result);
376 g_assert (items != NULL);
377 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
378 g_assert (secret_item_get_locked (items->data) == FALSE);
379 value = secret_item_get_secret (items->data);
380 g_assert (value != NULL);
381 secret_value_unref (value);
383 g_assert (items->next != NULL);
384 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
385 g_assert (secret_item_get_locked (items->next->data) == TRUE);
386 g_assert (secret_item_get_secret (items->next->data) == NULL);
388 g_assert (items->next->next == NULL);
389 g_list_free_full (items, g_object_unref);
393 test_lock_sync (Test *test,
396 const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
397 SecretCollection *collection;
398 GError *error = NULL;
403 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
404 SECRET_COLLECTION_NONE, NULL, &error);
405 g_assert_no_error (error);
407 objects = g_list_append (NULL, collection);
409 ret = secret_service_lock_sync (test->service, objects, NULL, &locked, &error);
410 g_assert_no_error (error);
411 g_assert (ret == TRUE);
413 g_assert (locked != NULL);
414 g_assert (locked->data == collection);
415 g_assert (locked->next == NULL);
416 g_list_free_full (locked, g_object_unref);
418 g_list_free (objects);
419 g_object_unref (collection);
423 test_unlock_sync (Test *test,
426 const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
427 SecretCollection *collection;
428 GError *error = NULL;
433 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
434 SECRET_COLLECTION_NONE, NULL, &error);
435 g_assert_no_error (error);
437 objects = g_list_append (NULL, collection);
439 ret = secret_service_unlock_sync (test->service, objects, NULL, &unlocked, &error);
440 g_assert_no_error (error);
441 g_assert (ret == TRUE);
443 g_assert (unlocked != NULL);
444 g_assert (unlocked->data == collection);
445 g_assert (unlocked->next == NULL);
446 g_list_free_full (unlocked, g_object_unref);
448 g_list_free (objects);
449 g_object_unref (collection);
453 test_clear_sync (Test *test,
456 GError *error = NULL;
457 GHashTable *attributes;
460 attributes = secret_attributes_build (&MOCK_SCHEMA,
466 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
468 g_assert_no_error (error);
469 g_assert (ret == TRUE);
471 g_hash_table_unref (attributes);
475 test_clear_async (Test *test,
478 GError *error = NULL;
479 GAsyncResult *result = NULL;
480 GHashTable *attributes;
483 attributes = secret_attributes_build (&MOCK_SCHEMA,
489 secret_service_clear (test->service, &MOCK_SCHEMA, attributes, NULL,
490 on_complete_get_result, &result);
492 g_hash_table_unref (attributes);
493 g_assert (result == NULL);
497 ret = secret_service_clear_finish (test->service, result, &error);
498 g_assert_no_error (error);
499 g_assert (ret == TRUE);
501 g_object_unref (result);
505 test_clear_locked (Test *test,
508 GError *error = NULL;
509 GHashTable *attributes;
512 attributes = secret_attributes_build (&MOCK_SCHEMA,
518 /* Locked items can't be removed via this API */
519 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
521 g_hash_table_unref (attributes);
522 g_assert_no_error (error);
523 g_assert (ret == FALSE);
527 test_clear_no_match (Test *test,
530 GError *error = NULL;
531 GHashTable *attributes;
534 attributes = secret_attributes_build (&MOCK_SCHEMA,
539 /* Won't match anything */
540 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
542 g_hash_table_unref (attributes);
543 g_assert_no_error (error);
544 g_assert (ret == FALSE);
548 test_clear_no_name (Test *test,
551 const gchar *paths[] = { "/org/freedesktop/secrets/collection/german", NULL };
552 GError *error = NULL;
553 GHashTable *attributes;
556 attributes = secret_attributes_build (&MOCK_SCHEMA,
560 /* Shouldn't match anything, because no item with 5 in mock schema */
561 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
562 g_assert_no_error (error);
563 g_assert (ret == FALSE);
565 /* We need this collection unlocked for the next test */
566 secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, NULL, &error);
567 g_assert_no_error (error);
569 /* We have an item with 5 in prime schema, but should match anyway becase of flags */
570 ret = secret_service_clear_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
571 g_assert_no_error (error);
572 g_assert (ret == TRUE);
574 g_hash_table_unref (attributes);
578 test_lookup_sync (Test *test,
581 GError *error = NULL;
582 GHashTable *attributes;
586 attributes = secret_attributes_build (&MOCK_SCHEMA,
592 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
594 g_assert_no_error (error);
595 g_hash_table_unref (attributes);
597 g_assert (value != NULL);
598 g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
599 g_assert_cmpuint (length, ==, 3);
601 secret_value_unref (value);
605 test_lookup_async (Test *test,
608 GError *error = NULL;
609 GHashTable *attributes;
610 GAsyncResult *result = NULL;
614 attributes = secret_attributes_build (&MOCK_SCHEMA,
620 secret_service_lookup (test->service, &MOCK_SCHEMA, attributes, NULL,
621 on_complete_get_result, &result);
623 g_assert (result == NULL);
624 g_hash_table_unref (attributes);
628 value = secret_service_lookup_finish (test->service, result, &error);
629 g_assert_no_error (error);
631 g_assert (value != NULL);
632 g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
633 g_assert_cmpuint (length, ==, 3);
635 secret_value_unref (value);
636 g_object_unref (result);
640 test_lookup_locked (Test *test,
643 GError *error = NULL;
644 GHashTable *attributes;
648 attributes = secret_attributes_build (&MOCK_SCHEMA,
654 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
656 g_assert_no_error (error);
657 g_hash_table_unref (attributes);
659 g_assert (value != NULL);
660 g_assert_cmpstr (secret_value_get (value, &length), ==, "3333");
661 g_assert_cmpuint (length, ==, 4);
663 secret_value_unref (value);
667 test_lookup_no_match (Test *test,
670 GError *error = NULL;
671 GHashTable *attributes;
674 attributes = secret_attributes_build (&MOCK_SCHEMA,
679 /* Won't match anything */
680 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
682 g_assert_no_error (error);
683 g_assert (value == NULL);
684 g_hash_table_unref (attributes);
688 test_lookup_no_name (Test *test,
691 GError *error = NULL;
692 GHashTable *attributes;
696 attributes = secret_attributes_build (&MOCK_SCHEMA,
700 /* should return null, because nothing with mock schema and 5 */
701 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
702 g_assert_no_error (error);
703 g_assert (value == NULL);
705 /* should return an item, because we have a prime schema with 5, and flags not to match name */
706 value = secret_service_lookup_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
708 g_assert_no_error (error);
710 g_assert (value != NULL);
711 g_assert_cmpstr (secret_value_get (value, &length), ==, "555");
712 g_assert_cmpuint (length, ==, 3);
714 secret_value_unref (value);
715 g_hash_table_unref (attributes);
719 test_store_sync (Test *test,
722 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
723 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
724 GHashTable *attributes;
725 GError *error = NULL;
730 attributes = secret_attributes_build (&MOCK_SCHEMA,
732 "string", "seventeen",
736 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
737 "New Item Label", value, NULL, &error);
738 g_assert_no_error (error);
739 secret_value_unref (value);
740 g_hash_table_unref (attributes);
742 attributes = g_hash_table_new (g_str_hash, g_str_equal);
743 g_hash_table_insert (attributes, "even", "false");
744 g_hash_table_insert (attributes, "string", "seventeen");
745 g_hash_table_insert (attributes, "number", "17");
747 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
748 NULL, &paths, NULL, &error);
749 g_hash_table_unref (attributes);
750 g_assert (ret == TRUE);
752 g_assert (paths != NULL);
753 g_assert (paths[0] != NULL);
754 g_assert (paths[1] == NULL);
756 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
758 g_assert_no_error (error);
760 g_assert (value != NULL);
761 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
762 g_assert_cmpuint (length, ==, 9);
764 secret_value_unref (value);
769 test_store_replace (Test *test,
772 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
773 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
774 GHashTable *attributes;
775 GError *error = NULL;
779 attributes = secret_attributes_build (&MOCK_SCHEMA,
781 "string", "seventeen",
785 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
786 "New Item Label", value, NULL, &error);
787 g_assert_no_error (error);
789 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
790 "Another Label", value, NULL, &error);
791 g_assert_no_error (error);
792 secret_value_unref (value);
793 g_hash_table_unref (attributes);
795 attributes = g_hash_table_new (g_str_hash, g_str_equal);
796 g_hash_table_insert (attributes, "even", "false");
797 g_hash_table_insert (attributes, "string", "seventeen");
798 g_hash_table_insert (attributes, "number", "17");
800 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
801 NULL, &paths, NULL, &error);
802 g_hash_table_unref (attributes);
803 g_assert (ret == TRUE);
805 g_assert (paths != NULL);
806 g_assert (paths[0] != NULL);
807 g_assert (paths[1] == NULL);
813 test_store_async (Test *test,
816 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
817 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
818 GAsyncResult *result = NULL;
819 GHashTable *attributes;
820 GError *error = NULL;
825 attributes = secret_attributes_build (&MOCK_SCHEMA,
827 "string", "seventeen",
831 secret_service_store (test->service, &MOCK_SCHEMA, attributes, collection_path,
832 "New Item Label", value, NULL, on_complete_get_result, &result);
833 g_assert (result == NULL);
834 secret_value_unref (value);
835 g_hash_table_unref (attributes);
839 ret = secret_service_store_finish (test->service, result, &error);
840 g_assert_no_error (error);
841 g_object_unref (result);
843 attributes = g_hash_table_new (g_str_hash, g_str_equal);
844 g_hash_table_insert (attributes, "even", "false");
845 g_hash_table_insert (attributes, "string", "seventeen");
846 g_hash_table_insert (attributes, "number", "17");
848 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
849 NULL, &paths, NULL, &error);
850 g_hash_table_unref (attributes);
851 g_assert (ret == TRUE);
853 g_assert (paths != NULL);
854 g_assert (paths[0] != NULL);
855 g_assert (paths[1] == NULL);
857 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
859 g_assert_no_error (error);
861 g_assert (value != NULL);
862 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
863 g_assert_cmpuint (length, ==, 9);
865 secret_value_unref (value);
870 test_store_no_default (Test *test,
873 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
874 GHashTable *attributes;
875 GError *error = NULL;
880 attributes = secret_attributes_build (&MOCK_SCHEMA,
882 "string", "seventeen",
886 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, SECRET_COLLECTION_DEFAULT,
887 "New Item Label", value, NULL, &error);
888 g_assert_no_error (error);
889 secret_value_unref (value);
890 g_hash_table_unref (attributes);
892 attributes = g_hash_table_new (g_str_hash, g_str_equal);
893 g_hash_table_insert (attributes, "even", "false");
894 g_hash_table_insert (attributes, "string", "seventeen");
895 g_hash_table_insert (attributes, "number", "17");
897 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
898 NULL, &paths, NULL, &error);
899 g_hash_table_unref (attributes);
900 g_assert (ret == TRUE);
902 g_assert (paths != NULL);
903 g_assert (paths[0] != NULL);
904 g_assert (paths[1] == NULL);
906 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
908 g_assert_no_error (error);
910 g_assert (value != NULL);
911 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
912 g_assert_cmpuint (length, ==, 9);
914 secret_value_unref (value);
919 test_set_alias_sync (Test *test,
922 SecretCollection *collection;
924 GError *error = NULL;
927 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
928 g_assert_no_error (error);
929 g_assert (blah == NULL);
931 collection = secret_collection_new_for_dbus_path_sync (test->service,
932 "/org/freedesktop/secrets/collection/english",
933 SECRET_COLLECTION_NONE, NULL, &error);
934 g_assert_no_error (error);
935 g_assert (SECRET_IS_COLLECTION (collection));
937 ret = secret_service_set_alias_sync (test->service, "blah", collection, NULL, &error);
938 g_assert_no_error (error);
939 g_assert (ret == TRUE);
941 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
942 g_assert_no_error (error);
943 g_assert_cmpstr (blah, ==, g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)));
946 ret = secret_service_set_alias_sync (test->service, "blah", NULL, NULL, &error);
947 g_assert_no_error (error);
948 g_assert (ret == TRUE);
950 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
951 g_assert_no_error (error);
952 g_assert (blah == NULL);
954 g_object_unref (collection);
958 main (int argc, char **argv)
960 g_test_init (&argc, &argv, NULL);
961 g_set_prgname ("test-service");
962 #if !GLIB_CHECK_VERSION(2,35,0)
966 g_test_add ("/service/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
967 g_test_add ("/service/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
968 g_test_add ("/service/search-all-sync", Test, "mock-service-normal.py", setup, test_search_all_sync, teardown);
969 g_test_add ("/service/search-all-async", Test, "mock-service-normal.py", setup, test_search_all_async, teardown);
970 g_test_add ("/service/search-unlock-sync", Test, "mock-service-normal.py", setup, test_search_unlock_sync, teardown);
971 g_test_add ("/service/search-unlock-async", Test, "mock-service-normal.py", setup, test_search_unlock_async, teardown);
972 g_test_add ("/service/search-secrets-sync", Test, "mock-service-normal.py", setup, test_search_secrets_sync, teardown);
973 g_test_add ("/service/search-secrets-async", Test, "mock-service-normal.py", setup, test_search_secrets_async, teardown);
975 g_test_add ("/service/lock-sync", Test, "mock-service-lock.py", setup, test_lock_sync, teardown);
977 g_test_add ("/service/unlock-sync", Test, "mock-service-lock.py", setup, test_unlock_sync, teardown);
979 g_test_add ("/service/lookup-sync", Test, "mock-service-normal.py", setup, test_lookup_sync, teardown);
980 g_test_add ("/service/lookup-async", Test, "mock-service-normal.py", setup, test_lookup_async, teardown);
981 g_test_add ("/service/lookup-locked", Test, "mock-service-normal.py", setup, test_lookup_locked, teardown);
982 g_test_add ("/service/lookup-no-match", Test, "mock-service-normal.py", setup, test_lookup_no_match, teardown);
983 g_test_add ("/service/lookup-no-name", Test, "mock-service-normal.py", setup, test_lookup_no_name, teardown);
985 g_test_add ("/service/clear-sync", Test, "mock-service-delete.py", setup, test_clear_sync, teardown);
986 g_test_add ("/service/clear-async", Test, "mock-service-delete.py", setup, test_clear_async, teardown);
987 g_test_add ("/service/clear-locked", Test, "mock-service-delete.py", setup, test_clear_locked, teardown);
988 g_test_add ("/service/clear-no-match", Test, "mock-service-delete.py", setup, test_clear_no_match, teardown);
989 g_test_add ("/service/clear-no-name", Test, "mock-service-delete.py", setup, test_clear_no_name, teardown);
991 g_test_add ("/service/store-sync", Test, "mock-service-normal.py", setup, test_store_sync, teardown);
992 g_test_add ("/service/store-async", Test, "mock-service-normal.py", setup, test_store_async, teardown);
993 g_test_add ("/service/store-replace", Test, "mock-service-normal.py", setup, test_store_replace, teardown);
994 g_test_add ("/service/store-no-default", Test, "mock-service-empty.py", setup, test_store_no_default, teardown);
996 g_test_add ("/service/set-alias-sync", Test, "mock-service-normal.py", setup, test_set_alias_sync, teardown);
998 return egg_tests_run_with_loop ();