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);
59 g_object_add_weak_pointer (G_OBJECT (test->service), (gpointer *)&test->service);
66 g_object_unref (test->service);
67 secret_service_disconnect ();
68 g_assert (test->service == NULL);
74 on_async_result (GObject *source,
78 GAsyncResult **ret = user_data;
79 g_assert (ret != NULL);
80 g_assert (*ret == NULL);
81 *ret = g_object_ref (result);
82 egg_test_wait_stop ();
86 on_notify_stop (GObject *obj,
90 guint *sigs = user_data;
91 g_assert (sigs != NULL);
94 egg_test_wait_stop ();
98 test_new_sync (Test *test,
101 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
102 GError *error = NULL;
105 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
106 g_assert_no_error (error);
108 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), ==, item_path);
110 g_object_unref (item);
114 test_new_sync_noexist (Test *test,
115 gconstpointer unused)
117 const gchar *item_path = "/org/freedesktop/secrets/collection/english/0000";
118 GError *error = NULL;
121 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
122 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
123 g_assert (item == NULL);
127 test_new_async (Test *test,
128 gconstpointer unused)
130 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
131 GAsyncResult *result = NULL;
132 GError *error = NULL;
135 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE,
136 NULL, on_async_result, &result);
137 g_assert (result == NULL);
141 item = secret_item_new_for_dbus_path_finish (result, &error);
142 g_assert_no_error (error);
143 g_object_unref (result);
145 g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), ==, item_path);
147 g_object_unref (item);
151 test_new_async_noexist (Test *test,
152 gconstpointer unused)
154 const gchar *item_path = "/org/freedesktop/secrets/collection/english/0000";
155 GAsyncResult *result = NULL;
156 GError *error = NULL;
159 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE,
160 NULL, on_async_result, &result);
161 g_assert (result == NULL);
165 item = secret_item_new_for_dbus_path_finish (result, &error);
166 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
167 g_assert (item == NULL);
168 g_object_unref (result);
172 test_create_sync (Test *test,
173 gconstpointer unused)
175 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
176 SecretCollection *collection;
177 GError *error = NULL;
179 GHashTable *attributes;
182 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
183 SECRET_COLLECTION_NONE, NULL, &error);
184 g_assert_no_error (error);
186 attributes = g_hash_table_new (g_str_hash, g_str_equal);
187 g_hash_table_insert (attributes, "even", "true");
188 g_hash_table_insert (attributes, "string", "ten");
189 g_hash_table_insert (attributes, "number", "10");
191 value = secret_value_new ("Hoohah", -1, "text/plain");
193 item = secret_item_create_sync (collection, &MOCK_SCHEMA, attributes, "Tunnel",
194 value, SECRET_ITEM_CREATE_NONE, NULL, &error);
195 g_assert_no_error (error);
196 g_object_add_weak_pointer (G_OBJECT (item), (gpointer *)&item);
198 g_hash_table_unref (attributes);
199 g_object_unref (collection);
200 secret_value_unref (value);
202 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), collection_path));
203 g_assert_cmpstr (secret_item_get_label (item), ==, "Tunnel");
204 g_assert (secret_item_get_locked (item) == FALSE);
206 g_object_unref (item);
207 g_assert (item == NULL);
211 test_create_async (Test *test,
212 gconstpointer unused)
214 const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
215 SecretCollection *collection;
216 GAsyncResult *result = NULL;
217 GError *error = NULL;
219 GHashTable *attributes;
222 collection = secret_collection_new_for_dbus_path_sync (test->service, collection_path,
223 SECRET_COLLECTION_NONE, NULL, &error);
224 g_assert_no_error (error);
226 attributes = g_hash_table_new (g_str_hash, g_str_equal);
227 g_hash_table_insert (attributes, "even", "true");
228 g_hash_table_insert (attributes, "string", "ten");
229 g_hash_table_insert (attributes, "number", "10");
231 value = secret_value_new ("Hoohah", -1, "text/plain");
233 secret_item_create (collection, &MOCK_SCHEMA, attributes, "Tunnel",
234 value, SECRET_ITEM_CREATE_NONE, NULL, on_async_result, &result);
235 g_assert_no_error (error);
237 g_hash_table_unref (attributes);
238 g_object_unref (collection);
239 secret_value_unref (value);
243 item = secret_item_create_finish (result, &error);
244 g_assert_no_error (error);
245 g_object_unref (result);
246 g_object_add_weak_pointer (G_OBJECT (item), (gpointer *)&item);
248 g_assert (g_str_has_prefix (g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)), collection_path));
249 g_assert_cmpstr (secret_item_get_label (item), ==, "Tunnel");
250 g_assert (secret_item_get_locked (item) == FALSE);
252 g_object_unref (item);
253 g_assert (item == NULL);
257 test_properties (Test *test,
258 gconstpointer unused)
260 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
261 GError *error = NULL;
262 GHashTable *attributes;
263 SecretService *service;
270 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
271 g_assert_no_error (error);
273 g_assert (secret_item_get_locked (item) == FALSE);
274 g_assert_cmpuint (secret_item_get_created (item), <=, time (NULL));
275 g_assert_cmpuint (secret_item_get_modified (item), <=, time (NULL));
277 label = secret_item_get_label (item);
278 g_assert_cmpstr (label, ==, "Item One");
281 attributes = secret_item_get_attributes (item);
282 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
283 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
284 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
285 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
286 g_hash_table_unref (attributes);
291 "modified", &modified,
293 "attributes", &attributes,
297 g_assert (locked == FALSE);
298 g_assert_cmpuint (created, <=, time (NULL));
299 g_assert_cmpuint (modified, <=, time (NULL));
301 g_assert_cmpstr (label, ==, "Item One");
304 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
305 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
306 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
307 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
308 g_hash_table_unref (attributes);
310 g_assert (service == test->service);
311 g_object_unref (service);
313 g_object_unref (item);
317 test_set_label_sync (Test *test,
318 gconstpointer unused)
320 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
321 GError *error = NULL;
326 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
327 g_assert_no_error (error);
329 label = secret_item_get_label (item);
330 g_assert_cmpstr (label, ==, "Item One");
333 ret = secret_item_set_label_sync (item, "Another label", NULL, &error);
334 g_assert_no_error (error);
335 g_assert (ret == TRUE);
337 label = secret_item_get_label (item);
338 g_assert_cmpstr (label, ==, "Another label");
341 g_object_unref (item);
345 test_set_label_async (Test *test,
346 gconstpointer unused)
348 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
349 GAsyncResult *result = NULL;
350 GError *error = NULL;
355 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
356 g_assert_no_error (error);
358 label = secret_item_get_label (item);
359 g_assert_cmpstr (label, ==, "Item One");
362 secret_item_set_label (item, "Another label", NULL, on_async_result, &result);
363 g_assert (result == NULL);
367 ret = secret_item_set_label_finish (item, result, &error);
368 g_assert_no_error (error);
369 g_assert (ret == TRUE);
370 g_object_unref (result);
372 label = secret_item_get_label (item);
373 g_assert_cmpstr (label, ==, "Another label");
376 g_object_unref (item);
380 test_set_label_prop (Test *test,
381 gconstpointer unused)
383 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
384 GAsyncResult *result = NULL;
385 GError *error = NULL;
390 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE, NULL, on_async_result, &result);
391 g_assert (result == NULL);
393 item = secret_item_new_for_dbus_path_finish (result, &error);
394 g_assert_no_error (error);
395 g_object_unref (result);
397 label = secret_item_get_label (item);
398 g_assert_cmpstr (label, ==, "Item One");
401 g_signal_connect (item, "notify::label", G_CALLBACK (on_notify_stop), &sigs);
402 g_object_set (item, "label", "Blah blah", NULL);
404 /* Wait for the property to actually 'take' */
407 label = secret_item_get_label (item);
408 g_assert_cmpstr (label, ==, "Blah blah");
411 g_object_add_weak_pointer (G_OBJECT (item), (gpointer *)&item);
412 g_object_unref (item);
415 g_main_context_iteration (g_main_context_get_thread_default (), TRUE);
419 test_set_attributes_sync (Test *test,
420 gconstpointer unused)
422 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
423 GError *error = NULL;
426 GHashTable *attributes;
429 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
430 g_assert_no_error (error);
432 attributes = secret_item_get_attributes (item);
433 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
434 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
435 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
436 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
437 g_hash_table_unref (attributes);
439 /* Has some other schema */
440 schema_name = secret_item_get_schema_name (item);
441 g_assert_cmpstr (schema_name, !=, MOCK_SCHEMA.name);
442 g_free (schema_name);
444 attributes = g_hash_table_new (g_str_hash, g_str_equal);
445 g_hash_table_insert (attributes, "string", "five");
446 g_hash_table_insert (attributes, "number", "5");
447 ret = secret_item_set_attributes_sync (item, &MOCK_SCHEMA, attributes, NULL, &error);
448 g_hash_table_unref (attributes);
449 g_assert_no_error (error);
450 g_assert (ret == TRUE);
452 attributes = secret_item_get_attributes (item);
453 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
454 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
455 g_assert_cmpuint (g_hash_table_size (attributes), ==, 3);
456 g_hash_table_unref (attributes);
458 /* Now has our schema */
459 schema_name = secret_item_get_schema_name (item);
460 g_assert_cmpstr (schema_name, ==, MOCK_SCHEMA.name);
461 g_free (schema_name);
463 g_object_unref (item);
467 test_set_attributes_async (Test *test,
468 gconstpointer unused)
470 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
471 GHashTable *attributes;
472 GError *error = NULL;
473 GAsyncResult *result = NULL;
478 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
479 g_assert_no_error (error);
481 attributes = secret_item_get_attributes (item);
482 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
483 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
484 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
485 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
486 g_hash_table_unref (attributes);
488 /* Has some other schema */
489 schema_name = secret_item_get_schema_name (item);
490 g_assert_cmpstr (schema_name, !=, MOCK_SCHEMA.name);
491 g_free (schema_name);
493 attributes = g_hash_table_new (g_str_hash, g_str_equal);
494 g_hash_table_insert (attributes, "string", "five");
495 g_hash_table_insert (attributes, "number", "5");
496 secret_item_set_attributes (item, &MOCK_SCHEMA, attributes, NULL, on_async_result, &result);
497 g_assert (result == NULL);
501 ret = secret_item_set_attributes_finish (item, result, &error);
502 g_assert_no_error (error);
503 g_assert (ret == TRUE);
504 g_object_unref (result);
506 attributes = secret_item_get_attributes (item);
507 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
508 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
509 g_assert_cmpuint (g_hash_table_size (attributes), ==, 3);
510 g_hash_table_unref (attributes);
512 /* Now has our schema */
513 schema_name = secret_item_get_schema_name (item);
514 g_assert_cmpstr (schema_name, ==, MOCK_SCHEMA.name);
515 g_free (schema_name);
517 g_object_unref (item);
521 test_set_attributes_prop (Test *test,
522 gconstpointer unused)
524 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
525 GAsyncResult *result = NULL;
526 GError *error = NULL;
528 GHashTable *attributes;
531 secret_item_new_for_dbus_path (test->service, item_path, SECRET_ITEM_NONE, NULL, on_async_result, &result);
532 g_assert (result == NULL);
534 item = secret_item_new_for_dbus_path_finish (result, &error);
535 g_assert_no_error (error);
536 g_object_unref (result);
538 attributes = secret_item_get_attributes (item);
539 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "one");
540 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "1");
541 g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "false");
542 g_assert_cmpuint (g_hash_table_size (attributes), ==, 4);
543 g_hash_table_unref (attributes);
545 g_signal_connect (item, "notify::attributes", G_CALLBACK (on_notify_stop), &sigs);
547 attributes = g_hash_table_new (g_str_hash, g_str_equal);
548 g_hash_table_insert (attributes, "string", "five");
549 g_hash_table_insert (attributes, "number", "5");
550 g_object_set (item, "attributes", attributes, NULL);
551 g_hash_table_unref (attributes);
553 /* Wait for the property to actually 'take' */
556 attributes = secret_item_get_attributes (item);
557 g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "five");
558 g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "5");
559 g_assert_cmpuint (g_hash_table_size (attributes), ==, 2);
560 g_hash_table_unref (attributes);
562 g_object_add_weak_pointer (G_OBJECT (item), (gpointer *)&item);
563 g_object_unref (item);
566 g_main_context_iteration (g_main_context_get_thread_default (), TRUE);
570 test_load_secret_sync (Test *test,
571 gconstpointer unused)
573 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
574 GError *error = NULL;
581 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
582 g_assert_no_error (error);
584 value = secret_item_get_secret (item);
585 g_assert (value == NULL);
587 ret = secret_item_load_secret_sync (item, NULL, &error);
588 g_assert_no_error (error);
589 g_assert (ret == TRUE);
591 value = secret_item_get_secret (item);
592 g_assert (value != NULL);
594 data = secret_value_get (value, &length);
595 egg_assert_cmpmem (data, length, ==, "111", 3);
597 secret_value_unref (value);
599 g_object_unref (item);
603 test_load_secret_async (Test *test,
604 gconstpointer unused)
606 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
607 GAsyncResult *result = NULL;
608 GError *error = NULL;
615 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
616 g_assert_no_error (error);
618 value = secret_item_get_secret (item);
619 g_assert (value == NULL);
621 secret_item_load_secret (item, NULL, on_async_result, &result);
622 g_assert (result == NULL);
626 ret = secret_item_load_secret_finish (item, result, &error);
627 g_assert_no_error (error);
628 g_assert (ret == TRUE);
629 g_object_unref (result);
631 value = secret_item_get_secret (item);
632 g_assert (value != NULL);
634 data = secret_value_get (value, &length);
635 egg_assert_cmpmem (data, length, ==, "111", 3);
637 secret_value_unref (value);
639 g_object_unref (item);
643 test_set_secret_sync (Test *test,
644 gconstpointer unused)
646 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
647 GError *error = NULL;
655 value = secret_value_new ("Sinking", -1, "strange/content-type");
657 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
658 g_assert_no_error (error);
660 ret = secret_item_set_secret_sync (item, value, NULL, &error);
661 g_assert_no_error (error);
662 g_assert (ret == TRUE);
664 check = secret_item_get_secret (item);
665 g_assert (check == value);
666 secret_value_unref (check);
667 secret_value_unref (value);
669 ret = secret_item_load_secret_sync (item, NULL, &error);
670 g_assert_no_error (error);
671 g_assert (ret == TRUE);
673 value = secret_item_get_secret (item);
674 g_assert (value != NULL);
676 data = secret_value_get (value, &length);
677 egg_assert_cmpmem (data, length, ==, "Sinking", 7);
678 g_assert_cmpstr (secret_value_get_content_type (value), ==, "strange/content-type");
680 secret_value_unref (value);
681 g_object_unref (item);
685 test_secrets_sync (Test *test,
688 const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
689 const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
690 const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
693 GError *error = NULL;
694 const gchar *password;
695 SecretItem *item_one, *item_two, *item_three;
700 item_one = secret_item_new_for_dbus_path_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
701 item_two = secret_item_new_for_dbus_path_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
702 item_three = secret_item_new_for_dbus_path_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
704 items = g_list_append (items, item_one);
705 items = g_list_append (items, item_two);
706 items = g_list_append (items, item_three);
708 ret = secret_item_load_secrets_sync (items, NULL, &error);
709 g_assert_no_error (error);
710 g_assert (ret == TRUE);
712 value = secret_item_get_secret (item_one);
713 g_assert (value != NULL);
714 password = secret_value_get (value, &length);
715 g_assert_cmpuint (length, ==, 3);
716 g_assert_cmpstr (password, ==, "111");
717 secret_value_unref (value);
719 value = secret_item_get_secret (item_two);
720 g_assert (value != NULL);
721 password = secret_value_get (value, &length);
722 g_assert_cmpuint (length, ==, 3);
723 g_assert_cmpstr (password, ==, "222");
724 secret_value_unref (value);
726 value = secret_item_get_secret (item_three);
727 g_assert (value == NULL);
729 g_list_free_full (items, g_object_unref);
733 test_secrets_async (Test *test,
736 const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
737 const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
738 const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
741 GError *error = NULL;
742 const gchar *password;
743 GAsyncResult *result = NULL;
744 SecretItem *item_one, *item_two, *item_three;
749 item_one = secret_item_new_for_dbus_path_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
750 g_assert_no_error (error);
752 item_two = secret_item_new_for_dbus_path_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
753 g_assert_no_error (error);
755 item_three = secret_item_new_for_dbus_path_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
756 g_assert_no_error (error);
759 items = g_list_append (items, item_one);
760 items = g_list_append (items, item_two);
761 items = g_list_append (items, item_three);
763 secret_item_load_secrets (items, NULL,
764 on_async_result, &result);
765 g_assert (result == NULL);
769 ret = secret_item_load_secrets_finish (result, &error);
770 g_assert_no_error (error);
771 g_object_unref (result);
772 g_assert (ret == TRUE);
774 value = secret_item_get_secret (item_one);
775 g_assert (value != NULL);
776 password = secret_value_get (value, &length);
777 g_assert_cmpuint (length, ==, 3);
778 g_assert_cmpstr (password, ==, "111");
779 secret_value_unref (value);
781 value = secret_item_get_secret (item_two);
782 g_assert (value != NULL);
783 password = secret_value_get (value, &length);
784 g_assert_cmpuint (length, ==, 3);
785 g_assert_cmpstr (password, ==, "222");
786 secret_value_unref (value);
788 value = secret_item_get_secret (item_three);
789 g_assert (value == NULL);
791 g_object_unref (item_one);
792 g_object_unref (item_two);
793 g_object_unref (item_three);
798 test_delete_sync (Test *test,
799 gconstpointer unused)
801 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
802 GError *error = NULL;
806 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
807 g_assert_no_error (error);
809 ret = secret_item_delete_sync (item, NULL, &error);
810 g_assert_no_error (error);
811 g_assert (ret == TRUE);
813 g_object_unref (item);
815 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
816 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
817 g_assert (item == NULL);
821 test_delete_async (Test *test,
822 gconstpointer unused)
824 const gchar *item_path = "/org/freedesktop/secrets/collection/english/1";
825 GAsyncResult *result = NULL;
826 GError *error = NULL;
830 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
831 g_assert_no_error (error);
833 secret_item_delete (item, NULL, on_async_result, &result);
834 g_assert (result == NULL);
838 ret = secret_item_delete_finish (item, result, &error);
839 g_assert_no_error (error);
840 g_assert (ret == TRUE);
842 g_object_unref (result);
843 g_object_unref (item);
845 item = secret_item_new_for_dbus_path_sync (test->service, item_path, SECRET_ITEM_NONE, NULL, &error);
846 g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
847 g_assert (item == NULL);
851 main (int argc, char **argv)
853 g_test_init (&argc, &argv, NULL);
854 g_set_prgname ("test-item");
855 #if !GLIB_CHECK_VERSION(2,35,0)
859 g_test_add ("/item/new-sync", Test, "mock-service-normal.py", setup, test_new_sync, teardown);
860 g_test_add ("/item/new-async", Test, "mock-service-normal.py", setup, test_new_async, teardown);
861 g_test_add ("/item/new-sync-noexist", Test, "mock-service-normal.py", setup, test_new_sync_noexist, teardown);
862 g_test_add ("/item/new-async-noexist", Test, "mock-service-normal.py", setup, test_new_async_noexist, teardown);
863 g_test_add ("/item/create-sync", Test, "mock-service-normal.py", setup, test_create_sync, teardown);
864 g_test_add ("/item/create-async", Test, "mock-service-normal.py", setup, test_create_async, teardown);
865 g_test_add ("/item/properties", Test, "mock-service-normal.py", setup, test_properties, teardown);
866 g_test_add ("/item/set-label-sync", Test, "mock-service-normal.py", setup, test_set_label_sync, teardown);
867 g_test_add ("/item/set-label-async", Test, "mock-service-normal.py", setup, test_set_label_async, teardown);
868 g_test_add ("/item/set-label-prop", Test, "mock-service-normal.py", setup, test_set_label_prop, teardown);
869 g_test_add ("/item/set-attributes-sync", Test, "mock-service-normal.py", setup, test_set_attributes_sync, teardown);
870 g_test_add ("/item/set-attributes-async", Test, "mock-service-normal.py", setup, test_set_attributes_async, teardown);
871 g_test_add ("/item/set-attributes-prop", Test, "mock-service-normal.py", setup, test_set_attributes_prop, teardown);
872 g_test_add ("/item/load-secret-sync", Test, "mock-service-normal.py", setup, test_load_secret_sync, teardown);
873 g_test_add ("/item/load-secret-async", Test, "mock-service-normal.py", setup, test_load_secret_async, teardown);
874 g_test_add ("/item/set-secret-sync", Test, "mock-service-normal.py", setup, test_set_secret_sync, teardown);
875 g_test_add ("/item/secrets-sync", Test, "mock-service-normal.py", setup, test_secrets_sync, teardown);
876 g_test_add ("/item/secrets-async", Test, "mock-service-normal.py", setup, test_secrets_async, teardown);
877 g_test_add ("/item/delete-sync", Test, "mock-service-normal.py", setup, test_delete_sync, teardown);
878 g_test_add ("/item/delete-async", Test, "mock-service-normal.py", setup, test_delete_async, teardown);
880 return egg_tests_run_with_loop ();