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-item.h"
20 #include "secret-service.h"
21 #include "secret-paths.h"
22 #include "secret-private.h"
24 #include "mock-service.h"
26 #include "egg/egg-testing.h"
33 static const SecretSchema MOCK_SCHEMA = {
34 "org.mock.Schema.Item",
37 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
38 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
39 { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
44 SecretService *service;
52 const gchar *mock_script = data;
54 mock_service_start (mock_script, &error);
55 g_assert_no_error (error);
57 test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
58 g_assert_no_error (error);
65 g_object_unref (test->service);
66 secret_service_disconnect ();
67 egg_assert_not_object (test->service);
73 on_async_result (GObject *source,
77 GAsyncResult **ret = user_data;
78 g_assert (ret != NULL);
79 g_assert (*ret == NULL);
80 *ret = g_object_ref (result);
81 egg_test_wait_stop ();
85 on_notify_stop (GObject *obj,
89 guint *sigs = user_data;
90 g_assert (sigs != NULL);
93 egg_test_wait_stop ();
97 test_new_sync (Test *test,
100 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
101 GError *error = NULL;
104 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
105 g_assert_no_error (error);
107 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), ==, item_path);
109 g_object_unref (item);
113 test_new_sync_noexist (Test *test,
114 gconstpointer unused)
116 const gchar *item_path = "/org/freedesktop/secrets/collection/english/0000";
117 GError *error = NULL;
120 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
121 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
122 g_assert (item == NULL);
126 test_new_async (Test *test,
127 gconstpointer unused)
129 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
130 GAsyncResult *result = NULL;
131 GError *error = NULL;
134 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE,
135 NULL, on_async_result, &result);
136 g_assert (result == NULL);
140 item = secret_item_new_for_dbus_path_finish (result, &error);
141 g_assert_no_error (error);
142 g_object_unref (result);
144 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), ==, item_path);
146 g_object_unref (item);
150 test_new_async_noexist (Test *test,
151 gconstpointer unused)
153 const gchar *item_path = "/org/freedesktop/secrets/collection/english/0000";
154 GAsyncResult *result = NULL;
155 GError *error = NULL;
158 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE,
159 NULL, on_async_result, &result);
160 g_assert (result == NULL);
164 item = secret_item_new_for_dbus_path_finish (result, &error);
165 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
166 g_assert (item == NULL);
167 g_object_unref (result);
171 test_create_sync (Test *test,
172 gconstpointer unused)
174 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
175 SecretCollection *collection;
176 GError *error = NULL;
178 GHashTable *attributes;
181 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
182 SECRET_COLLECTION_NONE, NULL, &error);
183 g_assert_no_error (error);
185 attributes = g_hash_table_new (g_str_hash, g_str_equal);
186 g_hash_table_insert (attributes, "even", "true");
187 g_hash_table_insert (attributes, "string", "ten");
188 g_hash_table_insert (attributes, "number", "10");
190 value = secret_value_new ("Hoohah", -1, "text/plain");
192 item = secret_item_create_sync (collection, &MOCK_SCHEMA, attributes, "Tunnel",
193 value, SECRET_ITEM_CREATE_NONE, NULL, &error);
194 g_assert_no_error (error);
196 g_hash_table_unref (attributes);
197 g_object_unref (collection);
198 secret_value_unref (value);
200 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), collection_path));
201 g_assert_cmpstr (secret_item_get_label (item), ==, "Tunnel");
202 g_assert (secret_item_get_locked (item) == FALSE);
204 g_object_unref (item);
205 egg_assert_not_object (item);
209 test_create_async (Test *test,
210 gconstpointer unused)
212 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
213 SecretCollection *collection;
214 GAsyncResult *result = NULL;
215 GError *error = NULL;
217 GHashTable *attributes;
220 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
221 SECRET_COLLECTION_NONE, NULL, &error);
222 g_assert_no_error (error);
224 attributes = g_hash_table_new (g_str_hash, g_str_equal);
225 g_hash_table_insert (attributes, "even", "true");
226 g_hash_table_insert (attributes, "string", "ten");
227 g_hash_table_insert (attributes, "number", "10");
229 value = secret_value_new ("Hoohah", -1, "text/plain");
231 secret_item_create (collection, &MOCK_SCHEMA, attributes, "Tunnel",
232 value, SECRET_ITEM_CREATE_NONE, NULL, on_async_result, &result);
233 g_assert_no_error (error);
235 g_hash_table_unref (attributes);
236 g_object_unref (collection);
237 secret_value_unref (value);
241 item = secret_item_create_finish (result, &error);
242 g_assert_no_error (error);
243 g_object_unref (result);
245 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), collection_path));
246 g_assert_cmpstr (secret_item_get_label (item), ==, "Tunnel");
247 g_assert (secret_item_get_locked (item) == FALSE);
249 g_object_unref (item);
250 egg_assert_not_object (item);
254 test_properties (Test *test,
255 gconstpointer unused)
257 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
258 GError *error = NULL;
259 GHashTable *attributes;
260 SecretService *service;
267 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
268 g_assert_no_error (error);
270 g_assert (secret_item_get_locked (item) == FALSE);
271 g_assert_cmpuint (secret_item_get_created (item), <=, time (NULL));
272 g_assert_cmpuint (secret_item_get_modified (item), <=, time (NULL));
274 label = secret_item_get_label (item);
275 g_assert_cmpstr (label, ==, "Item One");
278 attributes = secret_item_get_attributes (item);
279 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
280 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
281 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
282 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
283 g_hash_table_unref (attributes);
288 "modified", &modified,
290 "attributes", &attributes,
294 g_assert (locked == FALSE);
295 g_assert_cmpuint (created, <=, time (NULL));
296 g_assert_cmpuint (modified, <=, time (NULL));
298 g_assert_cmpstr (label, ==, "Item One");
301 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
302 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
303 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
304 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
305 g_hash_table_unref (attributes);
307 g_assert (service == test->service);
308 g_object_unref (service);
310 g_object_unref (item);
314 test_set_label_sync (Test *test,
315 gconstpointer unused)
317 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
318 GError *error = NULL;
323 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
324 g_assert_no_error (error);
326 label = secret_item_get_label (item);
327 g_assert_cmpstr (label, ==, "Item One");
330 ret = secret_item_set_label_sync (item, "Another label", NULL, &error);
331 g_assert_no_error (error);
332 g_assert (ret == TRUE);
334 label = secret_item_get_label (item);
335 g_assert_cmpstr (label, ==, "Another label");
338 g_object_unref (item);
342 test_set_label_async (Test *test,
343 gconstpointer unused)
345 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
346 GAsyncResult *result = NULL;
347 GError *error = NULL;
352 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
353 g_assert_no_error (error);
355 label = secret_item_get_label (item);
356 g_assert_cmpstr (label, ==, "Item One");
359 secret_item_set_label (item, "Another label", NULL, on_async_result, &result);
360 g_assert (result == NULL);
364 ret = secret_item_set_label_finish (item, result, &error);
365 g_assert_no_error (error);
366 g_assert (ret == TRUE);
367 g_object_unref (result);
369 label = secret_item_get_label (item);
370 g_assert_cmpstr (label, ==, "Another label");
373 g_object_unref (item);
377 test_set_label_prop (Test *test,
378 gconstpointer unused)
380 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
381 GAsyncResult *result = NULL;
382 GError *error = NULL;
387 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE, NULL, on_async_result, &result);
388 g_assert (result == NULL);
390 item = secret_item_new_for_dbus_path_finish (result, &error);
391 g_assert_no_error (error);
392 g_object_unref (result);
394 label = secret_item_get_label (item);
395 g_assert_cmpstr (label, ==, "Item One");
398 g_signal_connect (item, "notify::label", G_CALLBACK (on_notify_stop), &sigs);
399 g_object_set (item, "label", "Blah blah", NULL);
401 /* Wait for the property to actually 'take' */
404 label = secret_item_get_label (item);
405 g_assert_cmpstr (label, ==, "Blah blah");
408 g_object_unref (item);
412 test_set_attributes_sync (Test *test,
413 gconstpointer unused)
415 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
416 GError *error = NULL;
419 GHashTable *attributes;
422 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
423 g_assert_no_error (error);
425 attributes = secret_item_get_attributes (item);
426 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
427 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
428 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
429 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
430 g_hash_table_unref (attributes);
432 /* Has some other schema */
433 schema_name = secret_item_get_schema_name (item);
434 g_assert_cmpstr (schema_name, !=, MOCK_SCHEMA.name);
435 g_free (schema_name);
437 attributes = g_hash_table_new (g_str_hash, g_str_equal);
438 g_hash_table_insert (attributes, "string", "five");
439 g_hash_table_insert (attributes, "number", "5");
440 ret = secret_item_set_attributes_sync (item, &MOCK_SCHEMA, attributes, NULL, &error);
441 g_hash_table_unref (attributes);
442 g_assert_no_error (error);
443 g_assert (ret == TRUE);
445 attributes = secret_item_get_attributes (item);
446 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
447 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
448 g_assert_cmpuint (g_hash_table_size (attributes), ==, 3);
449 g_hash_table_unref (attributes);
451 /* Now has our schema */
452 schema_name = secret_item_get_schema_name (item);
453 g_assert_cmpstr (schema_name, ==, MOCK_SCHEMA.name);
454 g_free (schema_name);
456 g_object_unref (item);
460 test_set_attributes_async (Test *test,
461 gconstpointer unused)
463 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
464 GHashTable *attributes;
465 GError *error = NULL;
466 GAsyncResult *result = NULL;
471 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
472 g_assert_no_error (error);
474 attributes = secret_item_get_attributes (item);
475 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
476 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
477 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
478 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
479 g_hash_table_unref (attributes);
481 /* Has some other schema */
482 schema_name = secret_item_get_schema_name (item);
483 g_assert_cmpstr (schema_name, !=, MOCK_SCHEMA.name);
484 g_free (schema_name);
486 attributes = g_hash_table_new (g_str_hash, g_str_equal);
487 g_hash_table_insert (attributes, "string", "five");
488 g_hash_table_insert (attributes, "number", "5");
489 secret_item_set_attributes (item, &MOCK_SCHEMA, attributes, NULL, on_async_result, &result);
490 g_assert (result == NULL);
494 ret = secret_item_set_attributes_finish (item, result, &error);
495 g_assert_no_error (error);
496 g_assert (ret == TRUE);
497 g_object_unref (result);
499 attributes = secret_item_get_attributes (item);
500 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
501 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
502 g_assert_cmpuint (g_hash_table_size (attributes), ==, 3);
503 g_hash_table_unref (attributes);
505 /* Now has our schema */
506 schema_name = secret_item_get_schema_name (item);
507 g_assert_cmpstr (schema_name, ==, MOCK_SCHEMA.name);
508 g_free (schema_name);
510 g_object_unref (item);
514 test_set_attributes_prop (Test *test,
515 gconstpointer unused)
517 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
518 GAsyncResult *result = NULL;
519 GError *error = NULL;
521 GHashTable *attributes;
524 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE, NULL, on_async_result, &result);
525 g_assert (result == NULL);
527 item = secret_item_new_for_dbus_path_finish (result, &error);
528 g_assert_no_error (error);
529 g_object_unref (result);
531 attributes = secret_item_get_attributes (item);
532 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
533 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
534 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
535 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
536 g_hash_table_unref (attributes);
538 g_signal_connect (item, "notify::attributes", G_CALLBACK (on_notify_stop), &sigs);
540 attributes = g_hash_table_new (g_str_hash, g_str_equal);
541 g_hash_table_insert (attributes, "string", "five");
542 g_hash_table_insert (attributes, "number", "5");
543 g_object_set (item, "attributes", attributes, NULL);
544 g_hash_table_unref (attributes);
546 /* Wait for the property to actually 'take' */
549 attributes = secret_item_get_attributes (item);
550 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
551 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
552 g_assert_cmpuint (g_hash_table_size (attributes), ==, 2);
553 g_hash_table_unref (attributes);
555 g_object_unref (item);
559 test_load_secret_sync (Test *test,
560 gconstpointer unused)
562 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
563 GError *error = NULL;
570 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
571 g_assert_no_error (error);
573 value = secret_item_get_secret (item);
574 g_assert (value == NULL);
576 ret = secret_item_load_secret_sync (item, NULL, &error);
577 g_assert_no_error (error);
578 g_assert (ret == TRUE);
580 value = secret_item_get_secret (item);
581 g_assert (value != NULL);
583 data = secret_value_get (value, &length);
584 egg_assert_cmpmem (data, length, ==, "111", 3);
586 secret_value_unref (value);
588 g_object_unref (item);
592 test_load_secret_async (Test *test,
593 gconstpointer unused)
595 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
596 GAsyncResult *result = NULL;
597 GError *error = NULL;
604 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
605 g_assert_no_error (error);
607 value = secret_item_get_secret (item);
608 g_assert (value == NULL);
610 secret_item_load_secret (item, NULL, on_async_result, &result);
611 g_assert (result == NULL);
615 ret = secret_item_load_secret_finish (item, result, &error);
616 g_assert_no_error (error);
617 g_assert (ret == TRUE);
618 g_object_unref (result);
620 value = secret_item_get_secret (item);
621 g_assert (value != NULL);
623 data = secret_value_get (value, &length);
624 egg_assert_cmpmem (data, length, ==, "111", 3);
626 secret_value_unref (value);
628 g_object_unref (item);
632 test_set_secret_sync (Test *test,
633 gconstpointer unused)
635 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
636 GError *error = NULL;
644 value = secret_value_new ("Sinking", -1, "strange/content-type");
646 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
647 g_assert_no_error (error);
649 ret = secret_item_set_secret_sync (item, value, NULL, &error);
650 g_assert_no_error (error);
651 g_assert (ret == TRUE);
653 check = secret_item_get_secret (item);
654 g_assert (check == value);
655 secret_value_unref (check);
656 secret_value_unref (value);
658 ret = secret_item_load_secret_sync (item, NULL, &error);
659 g_assert_no_error (error);
660 g_assert (ret == TRUE);
662 value = secret_item_get_secret (item);
663 g_assert (value != NULL);
665 data = secret_value_get (value, &length);
666 egg_assert_cmpmem (data, length, ==, "Sinking", 7);
667 g_assert_cmpstr (secret_value_get_content_type (value), ==, "strange/content-type");
669 secret_value_unref (value);
670 g_object_unref (item);
674 test_secrets_sync (Test *test,
677 const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
678 const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
679 const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
682 GError *error = NULL;
683 const gchar *password;
684 SecretItem *item_one, *item_two, *item_three;
689 item_one = secret_item_new_for_dbus_path_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
690 item_two = secret_item_new_for_dbus_path_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
691 item_three = secret_item_new_for_dbus_path_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
693 items = g_list_append (items, item_one);
694 items = g_list_append (items, item_two);
695 items = g_list_append (items, item_three);
697 ret = secret_item_load_secrets_sync (items, NULL, &error);
698 g_assert_no_error (error);
699 g_assert (ret == TRUE);
701 value = secret_item_get_secret (item_one);
702 g_assert (value != NULL);
703 password = secret_value_get (value, &length);
704 g_assert_cmpuint (length, ==, 3);
705 g_assert_cmpstr (password, ==, "111");
706 secret_value_unref (value);
708 value = secret_item_get_secret (item_two);
709 g_assert (value != NULL);
710 password = secret_value_get (value, &length);
711 g_assert_cmpuint (length, ==, 3);
712 g_assert_cmpstr (password, ==, "222");
713 secret_value_unref (value);
715 value = secret_item_get_secret (item_three);
716 g_assert (value == NULL);
718 g_list_free_full (items, g_object_unref);
722 test_secrets_async (Test *test,
725 const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
726 const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
727 const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
730 GError *error = NULL;
731 const gchar *password;
732 GAsyncResult *result = NULL;
733 SecretItem *item_one, *item_two, *item_three;
738 item_one = secret_item_new_for_dbus_path_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
739 g_assert_no_error (error);
741 item_two = secret_item_new_for_dbus_path_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
742 g_assert_no_error (error);
744 item_three = secret_item_new_for_dbus_path_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
745 g_assert_no_error (error);
748 items = g_list_append (items, item_one);
749 items = g_list_append (items, item_two);
750 items = g_list_append (items, item_three);
752 secret_item_load_secrets (items, NULL,
753 on_async_result, &result);
754 g_assert (result == NULL);
758 ret = secret_item_load_secrets_finish (result, &error);
759 g_assert_no_error (error);
760 g_object_unref (result);
761 g_assert (ret == TRUE);
763 value = secret_item_get_secret (item_one);
764 g_assert (value != NULL);
765 password = secret_value_get (value, &length);
766 g_assert_cmpuint (length, ==, 3);
767 g_assert_cmpstr (password, ==, "111");
768 secret_value_unref (value);
770 value = secret_item_get_secret (item_two);
771 g_assert (value != NULL);
772 password = secret_value_get (value, &length);
773 g_assert_cmpuint (length, ==, 3);
774 g_assert_cmpstr (password, ==, "222");
775 secret_value_unref (value);
777 value = secret_item_get_secret (item_three);
778 g_assert (value == NULL);
780 g_object_unref (item_one);
781 g_object_unref (item_two);
782 g_object_unref (item_three);
787 test_delete_sync (Test *test,
788 gconstpointer unused)
790 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
791 GError *error = NULL;
795 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
796 g_assert_no_error (error);
798 ret = secret_item_delete_sync (item, NULL, &error);
799 g_assert_no_error (error);
800 g_assert (ret == TRUE);
802 g_object_unref (item);
804 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
805 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
806 g_assert (item == NULL);
810 test_delete_async (Test *test,
811 gconstpointer unused)
813 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
814 GAsyncResult *result = NULL;
815 GError *error = NULL;
819 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
820 g_assert_no_error (error);
822 secret_item_delete (item, NULL, on_async_result, &result);
823 g_assert (result == NULL);
827 ret = secret_item_delete_finish (item, result, &error);
828 g_assert_no_error (error);
829 g_assert (ret == TRUE);
831 g_object_unref (item);
833 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
834 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
835 g_assert (item == NULL);
839 main (int argc, char **argv)
841 g_test_init (&argc, &argv, NULL);
842 g_set_prgname ("test-item");
843 #if !GLIB_CHECK_VERSION(2,35,0)
847 g_test_add ("/item/new-sync", Test, "mock-service-normal.py", setup, test_new_sync, teardown);
848 g_test_add ("/item/new-async", Test, "mock-service-normal.py", setup, test_new_async, teardown);
849 g_test_add ("/item/new-sync-noexist", Test, "mock-service-normal.py", setup, test_new_sync_noexist, teardown);
850 g_test_add ("/item/new-async-noexist", Test, "mock-service-normal.py", setup, test_new_async_noexist, teardown);
851 g_test_add ("/item/create-sync", Test, "mock-service-normal.py", setup, test_create_sync, teardown);
852 g_test_add ("/item/create-async", Test, "mock-service-normal.py", setup, test_create_async, teardown);
853 g_test_add ("/item/properties", Test, "mock-service-normal.py", setup, test_properties, teardown);
854 g_test_add ("/item/set-label-sync", Test, "mock-service-normal.py", setup, test_set_label_sync, teardown);
855 g_test_add ("/item/set-label-async", Test, "mock-service-normal.py", setup, test_set_label_async, teardown);
856 g_test_add ("/item/set-label-prop", Test, "mock-service-normal.py", setup, test_set_label_prop, teardown);
857 g_test_add ("/item/set-attributes-sync", Test, "mock-service-normal.py", setup, test_set_attributes_sync, teardown);
858 g_test_add ("/item/set-attributes-async", Test, "mock-service-normal.py", setup, test_set_attributes_async, teardown);
859 g_test_add ("/item/set-attributes-prop", Test, "mock-service-normal.py", setup, test_set_attributes_prop, teardown);
860 g_test_add ("/item/load-secret-sync", Test, "mock-service-normal.py", setup, test_load_secret_sync, teardown);
861 g_test_add ("/item/load-secret-async", Test, "mock-service-normal.py", setup, test_load_secret_async, teardown);
862 g_test_add ("/item/set-secret-sync", Test, "mock-service-normal.py", setup, test_set_secret_sync, teardown);
863 g_test_add ("/item/secrets-sync", Test, "mock-service-normal.py", setup, test_secrets_sync, teardown);
864 g_test_add ("/item/secrets-async", Test, "mock-service-normal.py", setup, test_secrets_async, teardown);
865 g_test_add ("/item/delete-sync", Test, "mock-service-normal.py", setup, test_delete_sync, teardown);
866 g_test_add ("/item/delete-async", Test, "mock-service-normal.py", setup, test_delete_async, teardown);
868 return egg_tests_run_with_loop ();