Use upstream tag
[platform/upstream/libsecret.git] / libsecret / test-paths.c
1 /* libsecret - GLib wrapper for Secret Service
2  *
3  * Copyright 2011 Collabora Ltd.
4  *
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.
9  *
10  * See the included COPYING file for more information.
11  */
12
13
14 #include "config.h"
15
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"
22
23 #include "mock-service.h"
24
25 #include "egg/egg-testing.h"
26
27 #include <glib.h>
28
29 #include <errno.h>
30 #include <stdlib.h>
31
32 static const SecretSchema MOCK_SCHEMA = {
33         "org.mock.Schema",
34         SECRET_SCHEMA_NONE,
35         {
36                 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
37                 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
38                 { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
39         }
40 };
41
42 static const SecretSchema PRIME_SCHEMA = {
43         "org.mock.Prime",
44         SECRET_SCHEMA_NONE,
45         {
46                 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
47                 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
48                 { "prime", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
49         }
50 };
51
52 static const SecretSchema NO_NAME_SCHEMA = {
53         "unused.Schema.Name",
54         SECRET_SCHEMA_DONT_MATCH_NAME,
55         {
56                 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
57                 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
58         }
59 };
60
61 typedef struct {
62         SecretService *service;
63 } Test;
64
65 static void
66 setup_mock (Test *test,
67             gconstpointer data)
68 {
69         GError *error = NULL;
70         const gchar *mock_script = data;
71
72         mock_service_start (mock_script, &error);
73         g_assert_no_error (error);
74 }
75
76 static void
77 setup (Test *test,
78        gconstpointer data)
79 {
80         GError *error = NULL;
81
82         setup_mock (test, data);
83
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);
87 }
88
89 static void
90 teardown_mock (Test *test,
91                gconstpointer unused)
92 {
93         secret_service_disconnect ();
94         mock_service_stop ();
95 }
96
97 static void
98 teardown (Test *test,
99           gconstpointer unused)
100 {
101         egg_test_wait_idle ();
102
103         g_object_unref (test->service);
104         secret_service_disconnect ();
105         g_assert (test->service == NULL);
106
107         teardown_mock (test, unused);
108 }
109
110 static void
111 on_complete_get_result (GObject *source,
112                         GAsyncResult *result,
113                         gpointer user_data)
114 {
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 ();
120 }
121
122 static void
123 test_search_paths_sync (Test *test,
124                         gconstpointer used)
125 {
126         GHashTable *attributes;
127         gboolean ret;
128         gchar **locked;
129         gchar **unlocked;
130         GError *error = NULL;
131
132         attributes = g_hash_table_new (g_str_hash, g_str_equal);
133         g_hash_table_insert (attributes, "number", "1");
134
135         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
136                                                          &unlocked, &locked, &error);
137         g_assert_no_error (error);
138         g_assert (ret == TRUE);
139
140         g_assert (locked);
141         g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
142
143         g_assert (unlocked);
144         g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
145
146         g_strfreev (unlocked);
147         g_strfreev (locked);
148
149         g_hash_table_unref (attributes);
150 }
151
152 static void
153 test_search_paths_async (Test *test,
154                          gconstpointer used)
155 {
156         GAsyncResult *result = NULL;
157         GHashTable *attributes;
158         gboolean ret;
159         gchar **locked;
160         gchar **unlocked;
161         GError *error = NULL;
162
163         attributes = g_hash_table_new (g_str_hash, g_str_equal);
164         g_hash_table_insert (attributes, "number", "1");
165
166         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
167                                               on_complete_get_result, &result);
168         egg_test_wait ();
169
170         g_assert (G_IS_ASYNC_RESULT (result));
171         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
172                                                                 &unlocked, &locked,
173                                                                 &error);
174         g_assert_no_error (error);
175         g_assert (ret == TRUE);
176
177         g_assert (locked);
178         g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
179
180         g_assert (unlocked);
181         g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
182
183         g_strfreev (unlocked);
184         g_strfreev (locked);
185         g_object_unref (result);
186
187         g_hash_table_unref (attributes);
188 }
189
190 static void
191 test_search_paths_nulls (Test *test,
192                          gconstpointer used)
193 {
194         GAsyncResult *result = NULL;
195         GHashTable *attributes;
196         gboolean ret;
197         gchar **paths;
198         GError *error = NULL;
199
200         attributes = g_hash_table_new (g_str_hash, g_str_equal);
201         g_hash_table_insert (attributes, "number", "1");
202
203         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
204                                                      &paths, NULL, &error);
205         g_assert_no_error (error);
206         g_assert (ret == TRUE);
207         g_assert (paths != NULL);
208         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
209         g_strfreev (paths);
210
211         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
212                                                          NULL, &paths, &error);
213         g_assert_no_error (error);
214         g_assert (ret == TRUE);
215         g_assert (paths != NULL);
216         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
217         g_strfreev (paths);
218
219         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
220                                                          NULL, NULL, &error);
221         g_assert_no_error (error);
222         g_assert (ret == TRUE);
223
224         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
225                                               on_complete_get_result, &result);
226         egg_test_wait ();
227         g_assert (G_IS_ASYNC_RESULT (result));
228         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
229                                                            &paths, NULL, &error);
230         g_assert_no_error (error);
231         g_assert (ret == TRUE);
232         g_assert (paths != NULL);
233         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
234         g_strfreev (paths);
235         g_clear_object (&result);
236
237         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
238                                               on_complete_get_result, &result);
239         egg_test_wait ();
240         g_assert (G_IS_ASYNC_RESULT (result));
241         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
242                                                            NULL, &paths, &error);
243         g_assert_no_error (error);
244         g_assert (ret == TRUE);
245         g_assert (paths != NULL);
246         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
247         g_strfreev (paths);
248         g_clear_object (&result);
249
250         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
251                                               on_complete_get_result, &result);
252         egg_test_wait ();
253         g_assert (G_IS_ASYNC_RESULT (result));
254         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
255                                                            NULL, NULL, &error);
256         g_assert_no_error (error);
257         g_assert (ret == TRUE);
258         g_clear_object (&result);
259
260         g_hash_table_unref (attributes);
261 }
262
263 static void
264 test_secret_for_path_sync (Test *test,
265                            gconstpointer used)
266 {
267         SecretValue *value;
268         GError *error = NULL;
269         const gchar *path;
270         const gchar *password;
271         gsize length;
272
273         path = "/org/freedesktop/secrets/collection/english/1";
274         value = secret_service_get_secret_for_dbus_path_sync (test->service, path, NULL, &error);
275         g_assert_no_error (error);
276         g_assert (value != NULL);
277
278         password = secret_value_get (value, &length);
279         g_assert_cmpuint (length, ==, 3);
280         g_assert_cmpstr (password, ==, "111");
281
282         password = secret_value_get (value, NULL);
283         g_assert_cmpstr (password, ==, "111");
284
285         secret_value_unref (value);
286 }
287
288 static void
289 test_secret_for_path_async (Test *test,
290                             gconstpointer used)
291 {
292         SecretValue *value;
293         GError *error = NULL;
294         const gchar *path;
295         const gchar *password;
296         GAsyncResult *result = NULL;
297         gsize length;
298
299         path = "/org/freedesktop/secrets/collection/english/1";
300         secret_service_get_secret_for_dbus_path (test->service, path, NULL,
301                                                  on_complete_get_result, &result);
302         g_assert (result == NULL);
303         egg_test_wait ();
304
305         value = secret_service_get_secret_for_dbus_path_finish (test->service, result, &error);
306         g_assert_no_error (error);
307         g_assert (value != NULL);
308         g_object_unref (result);
309
310         password = secret_value_get (value, &length);
311         g_assert_cmpuint (length, ==, 3);
312         g_assert_cmpstr (password, ==, "111");
313
314         password = secret_value_get (value, NULL);
315         g_assert_cmpstr (password, ==, "111");
316
317         secret_value_unref (value);
318 }
319
320 static void
321 test_secrets_for_paths_sync (Test *test,
322                              gconstpointer used)
323 {
324         const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
325         const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
326         const gchar *paths[] = {
327                 path_item_one,
328                 path_item_two,
329
330                 /* This one is locked, and not returned */
331                 "/org/freedesktop/secrets/collection/spanish/10",
332                 NULL
333         };
334
335         SecretValue *value;
336         GHashTable *values;
337         GError *error = NULL;
338         const gchar *password;
339         gsize length;
340
341         values = secret_service_get_secrets_for_dbus_paths_sync (test->service, paths, NULL, &error);
342         g_assert_no_error (error);
343
344         g_assert (values != NULL);
345         g_assert_cmpuint (g_hash_table_size (values), ==, 2);
346
347         value = g_hash_table_lookup (values, path_item_one);
348         g_assert (value != NULL);
349         password = secret_value_get (value, &length);
350         g_assert_cmpuint (length, ==, 3);
351         g_assert_cmpstr (password, ==, "111");
352
353         value = g_hash_table_lookup (values, path_item_two);
354         g_assert (value != NULL);
355         password = secret_value_get (value, &length);
356         g_assert_cmpuint (length, ==, 3);
357         g_assert_cmpstr (password, ==, "222");
358
359         g_hash_table_unref (values);
360 }
361
362 static void
363 test_secrets_for_paths_async (Test *test,
364                               gconstpointer used)
365 {
366         const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
367         const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
368         const gchar *paths[] = {
369                 path_item_one,
370                 path_item_two,
371
372                 /* This one is locked, and not returned */
373                 "/org/freedesktop/secrets/collection/spanish/10",
374                 NULL
375         };
376
377         SecretValue *value;
378         GHashTable *values;
379         GError *error = NULL;
380         const gchar *password;
381         GAsyncResult *result = NULL;
382         gsize length;
383
384         secret_service_get_secrets_for_dbus_paths (test->service, paths, NULL,
385                                                    on_complete_get_result, &result);
386         g_assert (result == NULL);
387         egg_test_wait ();
388
389         values = secret_service_get_secrets_for_dbus_paths_finish (test->service, result, &error);
390         g_assert_no_error (error);
391         g_object_unref (result);
392
393         g_assert (values != NULL);
394         g_assert_cmpuint (g_hash_table_size (values), ==, 2);
395
396         value = g_hash_table_lookup (values, path_item_one);
397         g_assert (value != NULL);
398         password = secret_value_get (value, &length);
399         g_assert_cmpuint (length, ==, 3);
400         g_assert_cmpstr (password, ==, "111");
401
402         value = g_hash_table_lookup (values, path_item_two);
403         g_assert (value != NULL);
404         password = secret_value_get (value, &length);
405         g_assert_cmpuint (length, ==, 3);
406         g_assert_cmpstr (password, ==, "222");
407
408         g_hash_table_unref (values);
409 }
410
411 static void
412 test_delete_for_path_sync (Test *test,
413                            gconstpointer used)
414
415 {
416         const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/item";
417         GError *error = NULL;
418         gboolean ret;
419
420         ret = secret_service_delete_item_dbus_path_sync (test->service, path_item_one, NULL, &error);
421         g_assert_no_error (error);
422         g_assert (ret == TRUE);
423 }
424
425 static void
426 test_delete_for_path_sync_prompt (Test *test,
427                                   gconstpointer used)
428
429 {
430         const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/confirm";
431         GError *error = NULL;
432         gboolean ret;
433
434         ret = secret_service_delete_item_dbus_path_sync (test->service, path_item_one, NULL, &error);
435         g_assert_no_error (error);
436         g_assert (ret == TRUE);
437 }
438
439 static void
440 test_lock_paths_sync (Test *test,
441                       gconstpointer used)
442 {
443         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
444         const gchar *paths[] = {
445                 collection_path,
446                 NULL,
447         };
448
449         GError *error = NULL;
450         gchar **locked = NULL;
451         gboolean ret;
452
453         ret = secret_service_lock_dbus_paths_sync (test->service, paths, NULL, &locked, &error);
454         g_assert_no_error (error);
455         g_assert (ret == TRUE);
456
457         g_assert (locked != NULL);
458         g_assert_cmpstr (locked[0], ==, collection_path);
459         g_assert (locked[1] == NULL);
460         g_strfreev (locked);
461 }
462
463 static void
464 test_lock_prompt_sync (Test *test,
465                        gconstpointer used)
466 {
467         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
468         const gchar *paths[] = {
469                 collection_path,
470                 NULL,
471         };
472
473         GError *error = NULL;
474         gchar **locked = NULL;
475         gboolean ret;
476
477         ret = secret_service_lock_dbus_paths_sync (test->service, paths, NULL, &locked, &error);
478         g_assert_no_error (error);
479         g_assert (ret == TRUE);
480
481         g_assert (locked != NULL);
482         g_assert_cmpstr (locked[0], ==, collection_path);
483         g_assert (locked[1] == NULL);
484         g_strfreev (locked);
485 }
486
487 static void
488 test_unlock_paths_sync (Test *test,
489                         gconstpointer used)
490 {
491         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
492         const gchar *paths[] = {
493                 collection_path,
494                 NULL,
495         };
496
497         GError *error = NULL;
498         gchar **unlocked = NULL;
499         gboolean ret;
500
501         ret = secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, &unlocked, &error);
502         g_assert_no_error (error);
503         g_assert (ret == TRUE);
504
505         g_assert (unlocked != NULL);
506         g_assert_cmpstr (unlocked[0], ==, collection_path);
507         g_assert (unlocked[1] == NULL);
508         g_strfreev (unlocked);
509 }
510
511 static void
512 test_unlock_prompt_sync (Test *test,
513                          gconstpointer used)
514 {
515         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
516         const gchar *paths[] = {
517                 collection_path,
518                 NULL,
519         };
520
521         GError *error = NULL;
522         gchar **unlocked = NULL;
523         gboolean ret;
524
525         ret = secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, &unlocked, &error);
526         g_assert_no_error (error);
527         g_assert (ret == TRUE);
528
529         g_assert (unlocked != NULL);
530         g_assert_cmpstr (unlocked[0], ==, collection_path);
531         g_assert (unlocked[1] == NULL);
532         g_strfreev (unlocked);
533 }
534
535 static void
536 test_collection_sync (Test *test,
537                       gconstpointer used)
538 {
539         GHashTable *properties;
540         GError *error = NULL;
541         gchar *path;
542
543         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
544                                             (GDestroyNotify)g_variant_unref);
545         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
546                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
547
548         path = secret_service_create_collection_dbus_path_sync (test->service, properties,
549                                                                 NULL, SECRET_COLLECTION_CREATE_NONE,
550                                                                 NULL, &error);
551
552         g_hash_table_unref (properties);
553
554         g_assert_no_error (error);
555         g_assert (path != NULL);
556         g_assert (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
557
558         g_free (path);
559 }
560
561 static void
562 test_collection_async (Test *test,
563                        gconstpointer used)
564 {
565         GAsyncResult *result = NULL;
566         GHashTable *properties;
567         GError *error = NULL;
568         gchar *path;
569
570         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
571                                             (GDestroyNotify)g_variant_unref);
572         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
573                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
574
575         secret_service_create_collection_dbus_path (test->service, properties,
576                                                     NULL, SECRET_COLLECTION_CREATE_NONE,
577                                                     NULL, on_complete_get_result, &result);
578
579         g_hash_table_unref (properties);
580         g_assert (result == NULL);
581
582         egg_test_wait ();
583
584         path = secret_service_create_collection_dbus_path_finish (test->service, result, &error);
585         g_object_unref (result);
586
587         g_assert_no_error (error);
588         g_assert (path != NULL);
589         g_assert (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
590
591         g_free (path);
592 }
593
594 static void
595 test_item_sync (Test *test,
596                 gconstpointer used)
597 {
598         const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
599         GHashTable *properties;
600         GHashTable *attributes;
601         SecretValue *value;
602         GError *error = NULL;
603         gchar *path;
604
605         attributes = g_hash_table_new (g_str_hash, g_str_equal);
606         g_hash_table_insert (attributes, "even", "true");
607         g_hash_table_insert (attributes, "string", "ten");
608         g_hash_table_insert (attributes, "number", "10");
609
610         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
611                                             (GDestroyNotify)g_variant_unref);
612         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
613                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
614         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
615                              g_variant_ref_sink (_secret_attributes_to_variant (attributes, "org.gnome.Test")));
616
617         g_hash_table_unref (attributes);
618
619         value = secret_value_new ("andmoreandmore", -1, "text/plain");
620
621         path = secret_service_create_item_dbus_path_sync (test->service, collection_path,
622                                                           properties, value, SECRET_ITEM_CREATE_NONE,
623                                                           NULL, &error);
624
625         secret_value_unref (value);
626         g_hash_table_unref (properties);
627
628         g_assert_no_error (error);
629         g_assert (path != NULL);
630         g_assert (g_str_has_prefix (path, collection_path));
631
632         g_free (path);
633 }
634
635 static void
636 test_item_async (Test *test,
637                        gconstpointer used)
638 {
639         const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
640         GHashTable *properties;
641         GHashTable *attributes;
642         SecretValue *value;
643         GError *error = NULL;
644         GAsyncResult *result = NULL;
645         gchar *path;
646
647         attributes = g_hash_table_new (g_str_hash, g_str_equal);
648         g_hash_table_insert (attributes, "even", "true");
649         g_hash_table_insert (attributes, "string", "ten");
650         g_hash_table_insert (attributes, "number", "10");
651
652         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
653                                             (GDestroyNotify)g_variant_unref);
654         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
655                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
656         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
657                              g_variant_ref_sink (_secret_attributes_to_variant (attributes, NULL)));
658
659         g_hash_table_unref (attributes);
660
661         value = secret_value_new ("andmoreandmore", -1, "text/plain");
662
663         secret_service_create_item_dbus_path (test->service, collection_path,
664                                               properties, value, SECRET_ITEM_CREATE_NONE,
665                                               NULL, on_complete_get_result, &result);
666
667         g_assert (result == NULL);
668         secret_value_unref (value);
669         g_hash_table_unref (properties);
670
671         egg_test_wait ();
672
673         path = secret_service_create_item_dbus_path_finish (test->service, result, &error);
674         g_object_unref (result);
675
676         g_assert_no_error (error);
677         g_assert (path != NULL);
678         g_assert (g_str_has_prefix (path, collection_path));
679
680         g_free (path);
681 }
682
683 static void
684 test_set_alias_path (Test *test,
685                      gconstpointer used)
686 {
687         gchar *path;
688         GError *error = NULL;
689         gboolean ret;
690
691         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
692         g_assert_no_error (error);
693         g_assert (path == NULL);
694
695         ret = secret_service_set_alias_to_dbus_path_sync (test->service, "blah", "/org/freedesktop/secrets/collection/english", NULL, &error);
696         g_assert_no_error (error);
697         g_assert (ret == TRUE);
698
699         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
700         g_assert_no_error (error);
701         g_assert_cmpstr (path, ==, "/org/freedesktop/secrets/collection/english");
702         g_free (path);
703
704         ret = secret_service_set_alias_to_dbus_path_sync (test->service, "blah", NULL, NULL, &error);
705         g_assert_no_error (error);
706         g_assert (ret == TRUE);
707
708         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
709         g_assert_no_error (error);
710         g_assert (path == NULL);
711 }
712
713 static void
714 test_encode_decode_secret (Test *test,
715                            gconstpointer unused)
716 {
717         GVariant *variant;
718         SecretValue *value;
719         SecretValue *decoded;
720         GError *error = NULL;
721
722         value = secret_value_new ("zerogjuggs", -1, "text/plain");
723
724         secret_service_ensure_session_sync (test->service, NULL, &error);
725         g_assert_no_error (error);
726
727         variant = secret_service_encode_dbus_secret (test->service, value);
728         g_assert (variant != NULL);
729         g_assert_cmpstr (g_variant_get_type_string (variant), ==, "(oayays)");
730         secret_value_unref (value);
731
732         decoded = secret_service_decode_dbus_secret (test->service, variant);
733         g_assert (variant != NULL);
734         g_variant_unref (variant);
735
736         g_assert_cmpstr (secret_value_get_text (decoded), ==, "zerogjuggs");
737         secret_value_unref (decoded);
738 }
739
740 int
741 main (int argc, char **argv)
742 {
743         g_test_init (&argc, &argv, NULL);
744         g_set_prgname ("test-service");
745 #if !GLIB_CHECK_VERSION(2,35,0)
746         g_type_init ();
747 #endif
748
749         g_test_add ("/service/search-for-paths", Test, "mock-service-normal.py", setup, test_search_paths_sync, teardown);
750         g_test_add ("/service/search-for-paths-async", Test, "mock-service-normal.py", setup, test_search_paths_async, teardown);
751         g_test_add ("/service/search-for-paths-nulls", Test, "mock-service-normal.py", setup, test_search_paths_nulls, teardown);
752
753         g_test_add ("/service/secret-for-path-sync", Test, "mock-service-normal.py", setup, test_secret_for_path_sync, teardown);
754         g_test_add ("/service/secret-for-path-plain", Test, "mock-service-only-plain.py", setup, test_secret_for_path_sync, teardown);
755         g_test_add ("/service/secret-for-path-async", Test, "mock-service-normal.py", setup, test_secret_for_path_async, teardown);
756         g_test_add ("/service/secrets-for-paths-sync", Test, "mock-service-normal.py", setup, test_secrets_for_paths_sync, teardown);
757         g_test_add ("/service/secrets-for-paths-async", Test, "mock-service-normal.py", setup, test_secrets_for_paths_async, teardown);
758
759         g_test_add ("/service/delete-for-path", Test, "mock-service-delete.py", setup, test_delete_for_path_sync, teardown);
760         g_test_add ("/service/delete-for-path-with-prompt", Test, "mock-service-delete.py", setup, test_delete_for_path_sync_prompt, teardown);
761
762         g_test_add ("/service/lock-paths-sync", Test, "mock-service-lock.py", setup, test_lock_paths_sync, teardown);
763         g_test_add ("/service/lock-prompt-sync", Test, "mock-service-lock.py", setup, test_lock_prompt_sync, teardown);
764
765         g_test_add ("/service/unlock-paths-sync", Test, "mock-service-lock.py", setup, test_unlock_paths_sync, teardown);
766         g_test_add ("/service/unlock-prompt-sync", Test, "mock-service-lock.py", setup, test_unlock_prompt_sync, teardown);
767
768         g_test_add ("/service/create-collection-sync", Test, "mock-service-normal.py", setup, test_collection_sync, teardown);
769         g_test_add ("/service/create-collection-async", Test, "mock-service-normal.py", setup, test_collection_async, teardown);
770
771         g_test_add ("/service/create-item-sync", Test, "mock-service-normal.py", setup, test_item_sync, teardown);
772         g_test_add ("/service/create-item-async", Test, "mock-service-normal.py", setup, test_item_async, teardown);
773
774         g_test_add ("/service/set-alias-path", Test, "mock-service-normal.py", setup, test_set_alias_path, teardown);
775
776         g_test_add ("/service/encode-decode-secret", Test, "mock-service-normal.py", setup, test_encode_decode_secret, teardown);
777
778         return egg_tests_run_with_loop ();
779 }