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);
89 teardown_mock (Test *test,
92 secret_service_disconnect ();
100 egg_test_wait_idle ();
102 g_object_unref (test->service);
103 secret_service_disconnect ();
104 egg_assert_not_object (test->service);
106 teardown_mock (test, unused);
110 on_complete_get_result (GObject *source,
111 GAsyncResult *result,
114 GAsyncResult **ret = user_data;
115 g_assert (ret != NULL);
116 g_assert (*ret == NULL);
117 *ret = g_object_ref (result);
118 egg_test_wait_stop ();
122 test_search_sync (Test *test,
125 GHashTable *attributes;
126 GError *error = NULL;
129 attributes = g_hash_table_new (g_str_hash, g_str_equal);
130 g_hash_table_insert (attributes, "number", "1");
132 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
133 SECRET_SEARCH_NONE, NULL, &error);
134 g_assert_no_error (error);
135 g_hash_table_unref (attributes);
137 g_assert (items != NULL);
138 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
140 g_assert (items->next == NULL);
141 g_list_free_full (items, g_object_unref);
145 test_search_async (Test *test,
148 GAsyncResult *result = NULL;
149 GHashTable *attributes;
150 GError *error = NULL;
153 attributes = g_hash_table_new (g_str_hash, g_str_equal);
154 g_hash_table_insert (attributes, "number", "1");
156 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
157 SECRET_SEARCH_NONE, NULL,
158 on_complete_get_result, &result);
159 g_hash_table_unref (attributes);
160 g_assert (result == NULL);
164 g_assert (G_IS_ASYNC_RESULT (result));
165 items = secret_service_search_finish (test->service, result, &error);
166 g_assert_no_error (error);
167 g_object_unref (result);
169 g_assert (items != NULL);
170 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
172 g_assert (items->next == NULL);
173 g_list_free_full (items, g_object_unref);
177 test_search_all_sync (Test *test,
180 GHashTable *attributes;
181 GError *error = NULL;
184 attributes = g_hash_table_new (g_str_hash, g_str_equal);
185 g_hash_table_insert (attributes, "number", "1");
187 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
188 SECRET_SEARCH_ALL, NULL, &error);
189 g_assert_no_error (error);
190 g_hash_table_unref (attributes);
192 g_assert (items != NULL);
193 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
194 g_assert (secret_item_get_locked (items->data) == FALSE);
195 g_assert (secret_item_get_secret (items->data) == NULL);
197 g_assert (items->next != NULL);
198 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
199 g_assert (secret_item_get_locked (items->next->data) == TRUE);
200 g_assert (secret_item_get_secret (items->next->data) == NULL);
202 g_assert (items->next->next == NULL);
203 g_list_free_full (items, g_object_unref);
207 test_search_all_async (Test *test,
210 GAsyncResult *result = NULL;
211 GHashTable *attributes;
212 GError *error = NULL;
215 attributes = g_hash_table_new (g_str_hash, g_str_equal);
216 g_hash_table_insert (attributes, "number", "1");
218 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
219 SECRET_SEARCH_ALL, NULL,
220 on_complete_get_result, &result);
221 g_hash_table_unref (attributes);
222 g_assert (result == NULL);
226 g_assert (G_IS_ASYNC_RESULT (result));
227 items = secret_service_search_finish (test->service, result, &error);
228 g_assert_no_error (error);
229 g_object_unref (result);
231 g_assert (items != NULL);
232 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
233 g_assert (secret_item_get_locked (items->data) == FALSE);
234 g_assert (secret_item_get_secret (items->data) == NULL);
236 g_assert (items->next != NULL);
237 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
238 g_assert (secret_item_get_locked (items->next->data) == TRUE);
239 g_assert (secret_item_get_secret (items->next->data) == NULL);
241 g_assert (items->next->next == NULL);
242 g_list_free_full (items, g_object_unref);
246 test_search_unlock_sync (Test *test,
249 GHashTable *attributes;
250 GError *error = NULL;
253 attributes = g_hash_table_new (g_str_hash, g_str_equal);
254 g_hash_table_insert (attributes, "number", "1");
256 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
257 SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK,
259 g_assert_no_error (error);
260 g_hash_table_unref (attributes);
262 g_assert (items != NULL);
263 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
264 g_assert (secret_item_get_locked (items->data) == FALSE);
265 g_assert (secret_item_get_secret (items->data) == NULL);
267 g_assert (items->next != NULL);
268 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
269 g_assert (secret_item_get_locked (items->next->data) == FALSE);
270 g_assert (secret_item_get_secret (items->next->data) == NULL);
272 g_assert (items->next->next == NULL);
273 g_list_free_full (items, g_object_unref);
277 test_search_unlock_async (Test *test,
280 GAsyncResult *result = NULL;
281 GHashTable *attributes;
282 GError *error = NULL;
285 attributes = g_hash_table_new (g_str_hash, g_str_equal);
286 g_hash_table_insert (attributes, "number", "1");
288 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
289 SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK, NULL,
290 on_complete_get_result, &result);
291 g_hash_table_unref (attributes);
292 g_assert (result == NULL);
296 g_assert (G_IS_ASYNC_RESULT (result));
297 items = secret_service_search_finish (test->service, result, &error);
298 g_assert_no_error (error);
299 g_object_unref (result);
301 g_assert (items != NULL);
302 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
303 g_assert (secret_item_get_locked (items->data) == FALSE);
304 g_assert (secret_item_get_secret (items->data) == NULL);
306 g_assert (items->next != NULL);
307 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
308 g_assert (secret_item_get_locked (items->next->data) == FALSE);
309 g_assert (secret_item_get_secret (items->next->data) == NULL);
311 g_assert (items->next->next == NULL);
312 g_list_free_full (items, g_object_unref);
316 test_search_secrets_sync (Test *test,
319 GHashTable *attributes;
320 GError *error = NULL;
324 attributes = g_hash_table_new (g_str_hash, g_str_equal);
325 g_hash_table_insert (attributes, "number", "1");
327 items = secret_service_search_sync (test->service, &MOCK_SCHEMA, attributes,
328 SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS,
330 g_assert_no_error (error);
331 g_hash_table_unref (attributes);
333 g_assert (items != NULL);
334 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
335 g_assert (secret_item_get_locked (items->data) == FALSE);
336 value = secret_item_get_secret (items->data);
337 g_assert (value != NULL);
338 secret_value_unref (value);
340 g_assert (items->next != NULL);
341 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
342 g_assert (secret_item_get_locked (items->next->data) == TRUE);
343 g_assert (secret_item_get_secret (items->next->data) == NULL);
345 g_assert (items->next->next == NULL);
346 g_list_free_full (items, g_object_unref);
350 test_search_secrets_async (Test *test,
353 GAsyncResult *result = NULL;
354 GHashTable *attributes;
355 GError *error = NULL;
359 attributes = g_hash_table_new (g_str_hash, g_str_equal);
360 g_hash_table_insert (attributes, "number", "1");
362 secret_service_search (test->service, &MOCK_SCHEMA, attributes,
363 SECRET_SEARCH_ALL | SECRET_SEARCH_LOAD_SECRETS, NULL,
364 on_complete_get_result, &result);
365 g_hash_table_unref (attributes);
366 g_assert (result == NULL);
370 g_assert (G_IS_ASYNC_RESULT (result));
371 items = secret_service_search_finish (test->service, result, &error);
372 g_assert_no_error (error);
373 g_object_unref (result);
375 g_assert (items != NULL);
376 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
377 g_assert (secret_item_get_locked (items->data) == FALSE);
378 value = secret_item_get_secret (items->data);
379 g_assert (value != NULL);
380 secret_value_unref (value);
382 g_assert (items->next != NULL);
383 g_assert_cmpstr (g_dbus_proxy_get_object_path (items->next->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
384 g_assert (secret_item_get_locked (items->next->data) == TRUE);
385 g_assert (secret_item_get_secret (items->next->data) == NULL);
387 g_assert (items->next->next == NULL);
388 g_list_free_full (items, g_object_unref);
392 test_lock_sync (Test *test,
395 const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
396 SecretCollection *collection;
397 GError *error = NULL;
402 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
403 SECRET_COLLECTION_NONE, NULL, &error);
404 g_assert_no_error (error);
406 objects = g_list_append (NULL, collection);
408 ret = secret_service_lock_sync (test->service, objects, NULL, &locked, &error);
409 g_assert_no_error (error);
410 g_assert (ret == TRUE);
412 g_assert (locked != NULL);
413 g_assert (locked->data == collection);
414 g_assert (locked->next == NULL);
415 g_list_free_full (locked, g_object_unref);
417 g_list_free (objects);
418 g_object_unref (collection);
422 test_unlock_sync (Test *test,
425 const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
426 SecretCollection *collection;
427 GError *error = NULL;
432 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
433 SECRET_COLLECTION_NONE, NULL, &error);
434 g_assert_no_error (error);
436 objects = g_list_append (NULL, collection);
438 ret = secret_service_unlock_sync (test->service, objects, NULL, &unlocked, &error);
439 g_assert_no_error (error);
440 g_assert (ret == TRUE);
442 g_assert (unlocked != NULL);
443 g_assert (unlocked->data == collection);
444 g_assert (unlocked->next == NULL);
445 g_list_free_full (unlocked, g_object_unref);
447 g_list_free (objects);
448 g_object_unref (collection);
452 test_clear_sync (Test *test,
455 GError *error = NULL;
456 GHashTable *attributes;
459 attributes = secret_attributes_build (&MOCK_SCHEMA,
465 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
467 g_assert_no_error (error);
468 g_assert (ret == TRUE);
470 g_hash_table_unref (attributes);
474 test_clear_async (Test *test,
477 GError *error = NULL;
478 GAsyncResult *result = NULL;
479 GHashTable *attributes;
482 attributes = secret_attributes_build (&MOCK_SCHEMA,
488 secret_service_clear (test->service, &MOCK_SCHEMA, attributes, NULL,
489 on_complete_get_result, &result);
491 g_hash_table_unref (attributes);
492 g_assert (result == NULL);
496 ret = secret_service_clear_finish (test->service, result, &error);
497 g_assert_no_error (error);
498 g_assert (ret == TRUE);
500 g_object_unref (result);
504 test_clear_locked (Test *test,
507 GError *error = NULL;
508 GHashTable *attributes;
511 attributes = secret_attributes_build (&MOCK_SCHEMA,
517 /* Locked items can't be removed via this API */
518 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
520 g_hash_table_unref (attributes);
521 g_assert_no_error (error);
522 g_assert (ret == FALSE);
526 test_clear_no_match (Test *test,
529 GError *error = NULL;
530 GHashTable *attributes;
533 attributes = secret_attributes_build (&MOCK_SCHEMA,
538 /* Won't match anything */
539 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
541 g_hash_table_unref (attributes);
542 g_assert_no_error (error);
543 g_assert (ret == FALSE);
547 test_clear_no_name (Test *test,
550 const gchar *paths[] = { "/org/freedesktop/secrets/collection/german", NULL };
551 GError *error = NULL;
552 GHashTable *attributes;
555 attributes = secret_attributes_build (&MOCK_SCHEMA,
559 /* Shouldn't match anything, because no item with 5 in mock schema */
560 ret = secret_service_clear_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
561 g_assert_no_error (error);
562 g_assert (ret == FALSE);
564 /* We need this collection unlocked for the next test */
565 secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, NULL, &error);
566 g_assert_no_error (error);
568 /* We have an item with 5 in prime schema, but should match anyway becase of flags */
569 ret = secret_service_clear_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
570 g_assert_no_error (error);
571 g_assert (ret == TRUE);
573 g_hash_table_unref (attributes);
577 test_lookup_sync (Test *test,
580 GError *error = NULL;
581 GHashTable *attributes;
585 attributes = secret_attributes_build (&MOCK_SCHEMA,
591 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
593 g_assert_no_error (error);
594 g_hash_table_unref (attributes);
596 g_assert (value != NULL);
597 g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
598 g_assert_cmpuint (length, ==, 3);
600 secret_value_unref (value);
604 test_lookup_async (Test *test,
607 GError *error = NULL;
608 GHashTable *attributes;
609 GAsyncResult *result = NULL;
613 attributes = secret_attributes_build (&MOCK_SCHEMA,
619 secret_service_lookup (test->service, &MOCK_SCHEMA, attributes, NULL,
620 on_complete_get_result, &result);
622 g_assert (result == NULL);
623 g_hash_table_unref (attributes);
627 value = secret_service_lookup_finish (test->service, result, &error);
628 g_assert_no_error (error);
630 g_assert (value != NULL);
631 g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
632 g_assert_cmpuint (length, ==, 3);
634 secret_value_unref (value);
635 g_object_unref (result);
639 test_lookup_locked (Test *test,
642 GError *error = NULL;
643 GHashTable *attributes;
647 attributes = secret_attributes_build (&MOCK_SCHEMA,
653 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
655 g_assert_no_error (error);
656 g_hash_table_unref (attributes);
658 g_assert (value != NULL);
659 g_assert_cmpstr (secret_value_get (value, &length), ==, "3333");
660 g_assert_cmpuint (length, ==, 4);
662 secret_value_unref (value);
666 test_lookup_no_match (Test *test,
669 GError *error = NULL;
670 GHashTable *attributes;
673 attributes = secret_attributes_build (&MOCK_SCHEMA,
678 /* Won't match anything */
679 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
681 g_assert_no_error (error);
682 g_assert (value == NULL);
683 g_hash_table_unref (attributes);
687 test_lookup_no_name (Test *test,
690 GError *error = NULL;
691 GHashTable *attributes;
695 attributes = secret_attributes_build (&MOCK_SCHEMA,
699 /* should return null, because nothing with mock schema and 5 */
700 value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
701 g_assert_no_error (error);
702 g_assert (value == NULL);
704 /* should return an item, because we have a prime schema with 5, and flags not to match name */
705 value = secret_service_lookup_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
707 g_assert_no_error (error);
709 g_assert (value != NULL);
710 g_assert_cmpstr (secret_value_get (value, &length), ==, "555");
711 g_assert_cmpuint (length, ==, 3);
713 secret_value_unref (value);
714 g_hash_table_unref (attributes);
718 test_store_sync (Test *test,
721 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
722 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
723 GHashTable *attributes;
724 GError *error = NULL;
729 attributes = secret_attributes_build (&MOCK_SCHEMA,
731 "string", "seventeen",
735 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
736 "New Item Label", value, NULL, &error);
737 g_assert_no_error (error);
738 secret_value_unref (value);
739 g_hash_table_unref (attributes);
741 attributes = g_hash_table_new (g_str_hash, g_str_equal);
742 g_hash_table_insert (attributes, "even", "false");
743 g_hash_table_insert (attributes, "string", "seventeen");
744 g_hash_table_insert (attributes, "number", "17");
746 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
747 NULL, &paths, NULL, &error);
748 g_hash_table_unref (attributes);
749 g_assert (ret == TRUE);
751 g_assert (paths != NULL);
752 g_assert (paths[0] != NULL);
753 g_assert (paths[1] == NULL);
755 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
757 g_assert_no_error (error);
759 g_assert (value != NULL);
760 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
761 g_assert_cmpuint (length, ==, 9);
763 secret_value_unref (value);
768 test_store_replace (Test *test,
771 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
772 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
773 GHashTable *attributes;
774 GError *error = NULL;
778 attributes = secret_attributes_build (&MOCK_SCHEMA,
780 "string", "seventeen",
784 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
785 "New Item Label", value, NULL, &error);
786 g_assert_no_error (error);
788 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
789 "Another Label", value, NULL, &error);
790 g_assert_no_error (error);
791 secret_value_unref (value);
792 g_hash_table_unref (attributes);
794 attributes = g_hash_table_new (g_str_hash, g_str_equal);
795 g_hash_table_insert (attributes, "even", "false");
796 g_hash_table_insert (attributes, "string", "seventeen");
797 g_hash_table_insert (attributes, "number", "17");
799 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
800 NULL, &paths, NULL, &error);
801 g_hash_table_unref (attributes);
802 g_assert (ret == TRUE);
804 g_assert (paths != NULL);
805 g_assert (paths[0] != NULL);
806 g_assert (paths[1] == NULL);
812 test_store_async (Test *test,
815 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
816 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
817 GAsyncResult *result = NULL;
818 GHashTable *attributes;
819 GError *error = NULL;
824 attributes = secret_attributes_build (&MOCK_SCHEMA,
826 "string", "seventeen",
830 secret_service_store (test->service, &MOCK_SCHEMA, attributes, collection_path,
831 "New Item Label", value, NULL, on_complete_get_result, &result);
832 g_assert (result == NULL);
833 secret_value_unref (value);
834 g_hash_table_unref (attributes);
838 ret = secret_service_store_finish (test->service, result, &error);
839 g_assert_no_error (error);
840 g_object_unref (result);
842 attributes = g_hash_table_new (g_str_hash, g_str_equal);
843 g_hash_table_insert (attributes, "even", "false");
844 g_hash_table_insert (attributes, "string", "seventeen");
845 g_hash_table_insert (attributes, "number", "17");
847 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
848 NULL, &paths, NULL, &error);
849 g_hash_table_unref (attributes);
850 g_assert (ret == TRUE);
852 g_assert (paths != NULL);
853 g_assert (paths[0] != NULL);
854 g_assert (paths[1] == NULL);
856 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
858 g_assert_no_error (error);
860 g_assert (value != NULL);
861 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
862 g_assert_cmpuint (length, ==, 9);
864 secret_value_unref (value);
869 test_store_no_default (Test *test,
872 SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
873 GHashTable *attributes;
874 GError *error = NULL;
879 attributes = secret_attributes_build (&MOCK_SCHEMA,
881 "string", "seventeen",
885 ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, SECRET_COLLECTION_DEFAULT,
886 "New Item Label", value, NULL, &error);
887 g_assert_no_error (error);
888 secret_value_unref (value);
889 g_hash_table_unref (attributes);
891 attributes = g_hash_table_new (g_str_hash, g_str_equal);
892 g_hash_table_insert (attributes, "even", "false");
893 g_hash_table_insert (attributes, "string", "seventeen");
894 g_hash_table_insert (attributes, "number", "17");
896 ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes,
897 NULL, &paths, NULL, &error);
898 g_hash_table_unref (attributes);
899 g_assert (ret == TRUE);
901 g_assert (paths != NULL);
902 g_assert (paths[0] != NULL);
903 g_assert (paths[1] == NULL);
905 value = secret_service_get_secret_for_dbus_path_sync (test->service, paths[0],
907 g_assert_no_error (error);
909 g_assert (value != NULL);
910 g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
911 g_assert_cmpuint (length, ==, 9);
913 secret_value_unref (value);
918 test_set_alias_sync (Test *test,
921 SecretCollection *collection;
923 GError *error = NULL;
926 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
927 g_assert_no_error (error);
928 g_assert (blah == NULL);
930 collection = secret_collection_new_for_dbus_path_sync (test->service,
931 "/org/freedesktop/secrets/collection/english",
932 SECRET_COLLECTION_NONE, NULL, &error);
933 g_assert_no_error (error);
934 g_assert (SECRET_IS_COLLECTION (collection));
936 ret = secret_service_set_alias_sync (test->service, "blah", collection, NULL, &error);
937 g_assert_no_error (error);
938 g_assert (ret == TRUE);
940 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
941 g_assert_no_error (error);
942 g_assert_cmpstr (blah, ==, g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)));
945 ret = secret_service_set_alias_sync (test->service, "blah", NULL, NULL, &error);
946 g_assert_no_error (error);
947 g_assert (ret == TRUE);
949 blah = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
950 g_assert_no_error (error);
951 g_assert (blah == NULL);
953 g_object_unref (collection);
957 main (int argc, char **argv)
959 g_test_init (&argc, &argv, NULL);
960 g_set_prgname ("test-service");
961 #if !GLIB_CHECK_VERSION(2,35,0)
965 g_test_add ("/service/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
966 g_test_add ("/service/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
967 g_test_add ("/service/search-all-sync", Test, "mock-service-normal.py", setup, test_search_all_sync, teardown);
968 g_test_add ("/service/search-all-async", Test, "mock-service-normal.py", setup, test_search_all_async, teardown);
969 g_test_add ("/service/search-unlock-sync", Test, "mock-service-normal.py", setup, test_search_unlock_sync, teardown);
970 g_test_add ("/service/search-unlock-async", Test, "mock-service-normal.py", setup, test_search_unlock_async, teardown);
971 g_test_add ("/service/search-secrets-sync", Test, "mock-service-normal.py", setup, test_search_secrets_sync, teardown);
972 g_test_add ("/service/search-secrets-async", Test, "mock-service-normal.py", setup, test_search_secrets_async, teardown);
974 g_test_add ("/service/lock-sync", Test, "mock-service-lock.py", setup, test_lock_sync, teardown);
976 g_test_add ("/service/unlock-sync", Test, "mock-service-lock.py", setup, test_unlock_sync, teardown);
978 g_test_add ("/service/lookup-sync", Test, "mock-service-normal.py", setup, test_lookup_sync, teardown);
979 g_test_add ("/service/lookup-async", Test, "mock-service-normal.py", setup, test_lookup_async, teardown);
980 g_test_add ("/service/lookup-locked", Test, "mock-service-normal.py", setup, test_lookup_locked, teardown);
981 g_test_add ("/service/lookup-no-match", Test, "mock-service-normal.py", setup, test_lookup_no_match, teardown);
982 g_test_add ("/service/lookup-no-name", Test, "mock-service-normal.py", setup, test_lookup_no_name, teardown);
984 g_test_add ("/service/clear-sync", Test, "mock-service-delete.py", setup, test_clear_sync, teardown);
985 g_test_add ("/service/clear-async", Test, "mock-service-delete.py", setup, test_clear_async, teardown);
986 g_test_add ("/service/clear-locked", Test, "mock-service-delete.py", setup, test_clear_locked, teardown);
987 g_test_add ("/service/clear-no-match", Test, "mock-service-delete.py", setup, test_clear_no_match, teardown);
988 g_test_add ("/service/clear-no-name", Test, "mock-service-delete.py", setup, test_clear_no_name, teardown);
990 g_test_add ("/service/store-sync", Test, "mock-service-normal.py", setup, test_store_sync, teardown);
991 g_test_add ("/service/store-async", Test, "mock-service-normal.py", setup, test_store_async, teardown);
992 g_test_add ("/service/store-replace", Test, "mock-service-normal.py", setup, test_store_replace, teardown);
993 g_test_add ("/service/store-no-default", Test, "mock-service-empty.py", setup, test_store_no_default, teardown);
995 g_test_add ("/service/set-alias-sync", Test, "mock-service-normal.py", setup, test_set_alias_sync, teardown);
997 return egg_tests_run_with_loop ();