Branch data Line data Source code
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 : : #undef G_DISABLE_ASSERT
17 : :
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"
23 : :
24 : : #include "mock-service.h"
25 : :
26 : : #include "egg/egg-testing.h"
27 : :
28 : : #include <glib.h>
29 : :
30 : : #include <errno.h>
31 : : #include <stdlib.h>
32 : :
33 : : typedef struct {
34 : : SecretService *service;
35 : : } Test;
36 : :
37 : : static void
38 : 12 : setup_mock (Test *test,
39 : : gconstpointer data)
40 : : {
41 : 12 : GError *error = NULL;
42 : 12 : const gchar *mock_script = data;
43 : :
44 : 12 : mock_service_start (mock_script, &error);
45 [ - + ]: 12 : g_assert_no_error (error);
46 : 12 : }
47 : :
48 : : static void
49 : 12 : teardown_mock (Test *test,
50 : : gconstpointer unused)
51 : : {
52 : : /*
53 : : * Because the entire model of GDBus using another worker-thread
54 : : * is shit and racy as hell. If I had more time I would fix GDBus not to segfault
55 : : * during tests, but for now this is the best I can do.
56 : : */
57 : 12 : g_usleep (G_USEC_PER_SEC);
58 : :
59 : 12 : secret_service_disconnect ();
60 : 12 : mock_service_stop ();
61 : :
62 [ - + ]: 12 : while (g_main_context_iteration (NULL, FALSE));
63 : 12 : }
64 : :
65 : : static void
66 : 13 : on_complete_get_result (GObject *source,
67 : : GAsyncResult *result,
68 : : gpointer user_data)
69 : : {
70 : 13 : GAsyncResult **ret = user_data;
71 [ - + ]: 13 : g_assert_nonnull (ret);
72 [ - + ]: 13 : g_assert_null (*ret);
73 : 13 : *ret = g_object_ref (result);
74 : 13 : egg_test_wait_stop ();
75 : 13 : }
76 : :
77 : : static void
78 : 1 : test_get_sync (Test *test,
79 : : gconstpointer data)
80 : : {
81 : : SecretService *service1;
82 : : SecretService *service2;
83 : : SecretService *service3;
84 : 1 : GError *error = NULL;
85 : :
86 : : /* Both these sohuld point to the same thing */
87 : :
88 : 1 : service1 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
89 [ - + ]: 1 : g_assert_no_error (error);
90 : :
91 : 1 : service2 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
92 [ - + ]: 1 : g_assert_no_error (error);
93 : 1 : g_object_add_weak_pointer (G_OBJECT (service2), (gpointer *)&service2);
94 : :
95 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service1));
+ - - + ]
96 [ - + ]: 1 : g_assert_true (service1 == service2);
97 : :
98 : 1 : g_object_unref (service1);
99 [ - + ]: 1 : g_assert_true (G_IS_OBJECT (service1));
100 : :
101 : 1 : g_object_unref (service2);
102 : 1 : secret_service_disconnect ();
103 [ - + ]: 1 : g_assert_null (service2);
104 : :
105 : : /* Services were disconnected, so this should create a new one */
106 : 1 : service3 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
107 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service3));
+ - - + ]
108 [ - + ]: 1 : g_assert_no_error (error);
109 : 1 : g_object_add_weak_pointer (G_OBJECT (service3), (gpointer *)&service3);
110 : :
111 : 1 : g_object_unref (service3);
112 : :
113 : : /* Because the entire model of GDBus using another worker-thread is shite */
114 : 1 : g_usleep (G_USEC_PER_SEC);
115 : :
116 : 1 : secret_service_disconnect ();
117 [ - + ]: 1 : g_assert_null (service3);
118 : 1 : }
119 : :
120 : : static void
121 : 1 : test_get_async (Test *test,
122 : : gconstpointer data)
123 : : {
124 : : SecretService *service1;
125 : : SecretService *service2;
126 : : SecretService *service3;
127 : 1 : GAsyncResult *result = NULL;
128 : 1 : GError *error = NULL;
129 : :
130 : : /* Both these sohuld point to the same thing */
131 : :
132 : 1 : secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
133 [ - + ]: 1 : g_assert_null (result);
134 [ - + ]: 1 : egg_test_wait ();
135 : 1 : service1 = secret_service_get_finish (result, &error);
136 [ - + ]: 1 : g_assert_no_error (error);
137 [ + - ]: 1 : g_clear_object (&result);
138 : :
139 : 1 : secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
140 [ - + ]: 1 : g_assert_null (result);
141 [ - + ]: 1 : egg_test_wait ();
142 : 1 : service2 = secret_service_get_finish (result, &error);
143 [ - + ]: 1 : g_assert_no_error (error);
144 [ + - ]: 1 : g_clear_object (&result);
145 : 1 : g_object_add_weak_pointer (G_OBJECT (service2), (gpointer *)&service2);
146 : :
147 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service1));
+ - - + ]
148 [ - + ]: 1 : g_assert_true (service1 == service2);
149 : :
150 : 1 : g_object_unref (service1);
151 [ - + ]: 1 : g_assert_true (G_IS_OBJECT (service1));
152 : :
153 : 1 : g_object_unref (service2);
154 : 1 : secret_service_disconnect ();
155 [ - + ]: 1 : g_assert_null (service2);
156 : :
157 : : /* Services were unreffed, so this should create a new one */
158 : 1 : secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
159 [ - + ]: 1 : g_assert_null (result);
160 [ - + ]: 1 : egg_test_wait ();
161 : 1 : service3 = secret_service_get_finish (result, &error);
162 [ - + ]: 1 : g_assert_no_error (error);
163 [ + - ]: 1 : g_clear_object (&result);
164 : 1 : g_object_add_weak_pointer (G_OBJECT (service3), (gpointer *)&service3);
165 : :
166 : 1 : g_object_unref (service3);
167 : 1 : secret_service_disconnect ();
168 [ - + ]: 1 : g_assert_null (service3);
169 : 1 : }
170 : :
171 : : static void
172 : 1 : test_get_more_sync (Test *test,
173 : : gconstpointer data)
174 : : {
175 : : SecretService *service;
176 : : SecretService *service2;
177 : 1 : GError *error = NULL;
178 : : const gchar *path;
179 : : GList *collections;
180 : :
181 : 1 : service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
182 [ - + ]: 1 : g_assert_no_error (error);
183 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
184 : :
185 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_NONE);
186 : :
187 : 1 : service2 = secret_service_get_sync (SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
188 [ - + ]: 1 : g_assert_no_error (error);
189 : :
190 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
191 [ - + ]: 1 : g_assert_true (service == service2);
192 : :
193 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
194 : 1 : collections = secret_service_get_collections (service);
195 [ - + ]: 1 : g_assert_nonnull (collections);
196 : 1 : g_list_free_full (collections, g_object_unref);
197 : :
198 : 1 : g_object_unref (service2);
199 : :
200 : 1 : service2 = secret_service_get_sync (SECRET_SERVICE_OPEN_SESSION, NULL, &error);
201 [ - + ]: 1 : g_assert_no_error (error);
202 : :
203 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
204 : 1 : path = secret_service_get_session_dbus_path (service);
205 [ - + ]: 1 : g_assert_nonnull (path);
206 : :
207 : 1 : g_object_unref (service2);
208 : :
209 : 1 : g_object_unref (service);
210 : 1 : secret_service_disconnect ();
211 [ - + ]: 1 : g_assert_null (service);
212 : 1 : }
213 : :
214 : : static void
215 : 1 : test_get_more_async (Test *test,
216 : : gconstpointer data)
217 : : {
218 : 1 : GAsyncResult *result = NULL;
219 : : SecretService *service;
220 : 1 : GError *error = NULL;
221 : : const gchar *path;
222 : : GList *collections;
223 : :
224 : 1 : secret_service_get (SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
225 [ - + ]: 1 : g_assert_null (result);
226 : :
227 [ - + ]: 1 : egg_test_wait ();
228 : :
229 : 1 : service = secret_service_get_finish (result, &error);
230 [ - + ]: 1 : g_assert_no_error (error);
231 : 1 : g_object_unref (result);
232 : 1 : result = NULL;
233 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
234 : :
235 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
236 : 1 : path = secret_service_get_session_dbus_path (service);
237 [ - + ]: 1 : g_assert_nonnull (path);
238 : :
239 : 1 : collections = secret_service_get_collections (service);
240 [ - + ]: 1 : g_assert_nonnull (collections);
241 : 1 : g_list_free_full (collections, g_object_unref);
242 : :
243 : 1 : g_object_unref (service);
244 : 1 : secret_service_disconnect ();
245 [ - + ]: 1 : g_assert_null (service);
246 : :
247 : : /* Now get a session with just collections */
248 : :
249 : 1 : secret_service_get (SECRET_SERVICE_LOAD_COLLECTIONS, NULL, on_complete_get_result, &result);
250 [ - + ]: 1 : g_assert_null (result);
251 : :
252 [ - + ]: 1 : egg_test_wait ();
253 : :
254 : 1 : service = secret_service_get_finish (result, &error);
255 [ - + ]: 1 : g_assert_no_error (error);
256 : 1 : g_object_unref (result);
257 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
258 : :
259 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
260 : 1 : path = secret_service_get_session_dbus_path (service);
261 [ - + ]: 1 : g_assert_null (path);
262 : :
263 : 1 : collections = secret_service_get_collections (service);
264 [ - + ]: 1 : g_assert_nonnull (collections);
265 : 1 : g_list_free_full (collections, g_object_unref);
266 : :
267 : 1 : g_object_unref (service);
268 : 1 : secret_service_disconnect ();
269 [ - + ]: 1 : g_assert_null (service);
270 : 1 : }
271 : :
272 : : static void
273 : 1 : test_open_sync (Test *test,
274 : : gconstpointer data)
275 : : {
276 : : SecretService *service1;
277 : : SecretService *service2;
278 : 1 : GError *error = NULL;
279 : :
280 : : /* Both these sohuld point to different things */
281 : :
282 : 1 : service1 = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
283 : : SECRET_SERVICE_NONE, NULL, &error);
284 [ - + ]: 1 : g_assert_no_error (error);
285 : 1 : g_object_add_weak_pointer (G_OBJECT (service1), (gpointer *)&service1);
286 : :
287 : 1 : service2 = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
288 : : SECRET_SERVICE_NONE, NULL, &error);
289 [ - + ]: 1 : g_assert_no_error (error);
290 : 1 : g_object_add_weak_pointer (G_OBJECT (service2), (gpointer *)&service2);
291 : :
292 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service1));
+ - - + ]
293 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service2));
+ - - + ]
294 [ - + ]: 1 : g_assert_true (service1 != service2);
295 : :
296 : 1 : g_object_unref (service1);
297 [ - + ]: 1 : g_assert_null (service1);
298 : :
299 : 1 : g_object_unref (service2);
300 [ - + ]: 1 : g_assert_null (service2);
301 : 1 : }
302 : :
303 : : static void
304 : 1 : test_open_async (Test *test,
305 : : gconstpointer data)
306 : : {
307 : : SecretService *service1;
308 : : SecretService *service2;
309 : 1 : GAsyncResult *result = NULL;
310 : 1 : GError *error = NULL;
311 : :
312 : : /* Both these sohuld point to different things */
313 : :
314 : 1 : secret_service_open (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
315 : : NULL, on_complete_get_result, &result);
316 [ - + ]: 1 : g_assert_null (result);
317 [ - + ]: 1 : egg_test_wait ();
318 : 1 : service1 = secret_service_open_finish (result, &error);
319 [ - + ]: 1 : g_assert_no_error (error);
320 [ + - ]: 1 : g_clear_object (&result);
321 : 1 : g_object_add_weak_pointer (G_OBJECT (service1), (gpointer *)&service1);
322 : :
323 : 1 : secret_service_open (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE, NULL,
324 : : on_complete_get_result, &result);
325 [ - + ]: 1 : g_assert_null (result);
326 [ - + ]: 1 : egg_test_wait ();
327 : 1 : service2 = secret_service_open_finish (result, &error);
328 [ - + ]: 1 : g_assert_no_error (error);
329 [ + - ]: 1 : g_clear_object (&result);
330 : 1 : g_object_add_weak_pointer (G_OBJECT (service2), (gpointer *)&service2);
331 : :
332 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service1));
+ - - + ]
333 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service2));
+ - - + ]
334 [ - + ]: 1 : g_assert_true (service1 != service2);
335 : :
336 : 1 : g_object_unref (service1);
337 [ - + ]: 1 : g_assert_null (service1);
338 : :
339 : 1 : g_object_unref (service2);
340 [ - + ]: 1 : g_assert_null (service2);
341 : 1 : }
342 : :
343 : : static void
344 : 1 : test_open_more_sync (Test *test,
345 : : gconstpointer data)
346 : : {
347 : : SecretService *service;
348 : 1 : GError *error = NULL;
349 : : const gchar *path;
350 : : GList *collections;
351 : :
352 : 1 : service = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
353 : : NULL, &error);
354 [ - + ]: 1 : g_assert_no_error (error);
355 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
356 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
357 : :
358 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_NONE);
359 [ - + ]: 1 : g_assert_null (secret_service_get_collections (service));
360 [ - + ]: 1 : g_assert_null (secret_service_get_session_dbus_path (service));
361 : :
362 : 1 : g_object_unref (service);
363 [ - + ]: 1 : g_assert_null (service);
364 : :
365 : 1 : service = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
366 : : SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
367 [ - + ]: 1 : g_assert_no_error (error);
368 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
369 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
370 : :
371 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
372 : 1 : collections = secret_service_get_collections (service);
373 [ - + ]: 1 : g_assert_nonnull (collections);
374 : 1 : g_list_free_full (collections, g_object_unref);
375 [ - + ]: 1 : g_assert_null (secret_service_get_session_dbus_path (service));
376 : :
377 : 1 : g_object_unref (service);
378 [ - + ]: 1 : g_assert_null (service);
379 : :
380 : 1 : service = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
381 : : SECRET_SERVICE_OPEN_SESSION, NULL, &error);
382 [ - + ]: 1 : g_assert_no_error (error);
383 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
384 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
385 : :
386 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION);
387 [ - + ]: 1 : g_assert_null (secret_service_get_collections (service));
388 : 1 : path = secret_service_get_session_dbus_path (service);
389 [ - + ]: 1 : g_assert_nonnull (path);
390 : :
391 : 1 : g_object_unref (service);
392 [ - + ]: 1 : g_assert_null (service);
393 : 1 : }
394 : :
395 : : static void
396 : 1 : test_open_more_async (Test *test,
397 : : gconstpointer data)
398 : : {
399 : 1 : GAsyncResult *result = NULL;
400 : : SecretService *service;
401 : 1 : GError *error = NULL;
402 : : const gchar *path;
403 : : GList *collections;
404 : :
405 : 1 : secret_service_open (SECRET_TYPE_SERVICE, NULL,
406 : : SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
407 [ - + ]: 1 : g_assert_null (result);
408 : :
409 [ - + ]: 1 : egg_test_wait ();
410 : :
411 : 1 : service = secret_service_open_finish (result, &error);
412 [ - + ]: 1 : g_assert_no_error (error);
413 : 1 : g_object_unref (result);
414 : 1 : result = NULL;
415 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
416 : :
417 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
418 : 1 : path = secret_service_get_session_dbus_path (service);
419 [ - + ]: 1 : g_assert_nonnull (path);
420 : :
421 : 1 : collections = secret_service_get_collections (service);
422 [ - + ]: 1 : g_assert_nonnull (collections);
423 : 1 : g_list_free_full (collections, g_object_unref);
424 : :
425 : 1 : g_object_unref (service);
426 [ - + ]: 1 : g_assert_null (service);
427 : :
428 : : /* Now get a session with just collections */
429 : :
430 : 1 : secret_service_open (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_LOAD_COLLECTIONS,
431 : : NULL, on_complete_get_result, &result);
432 [ - + ]: 1 : g_assert_null (result);
433 : :
434 [ - + ]: 1 : egg_test_wait ();
435 : :
436 : 1 : service = secret_service_open_finish (result, &error);
437 [ - + ]: 1 : g_assert_no_error (error);
438 : 1 : g_object_unref (result);
439 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
440 : :
441 [ - + ]: 1 : g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
442 : 1 : path = secret_service_get_session_dbus_path (service);
443 [ - + ]: 1 : g_assert_null (path);
444 : :
445 : 1 : collections = secret_service_get_collections (service);
446 [ - + ]: 1 : g_assert_nonnull (collections);
447 : 1 : g_list_free_full (collections, g_object_unref);
448 : :
449 : 1 : g_object_unref (service);
450 [ - + ]: 1 : g_assert_null (service);
451 : 1 : }
452 : :
453 : : static void
454 : 1 : test_connect_async (Test *test,
455 : : gconstpointer used)
456 : : {
457 : 1 : GError *error = NULL;
458 : 1 : GAsyncResult *result = NULL;
459 : : SecretService *service;
460 : : const gchar *path;
461 : :
462 : : /* Passing false, not session */
463 : 1 : secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
464 [ - + ]: 1 : g_assert_null (result);
465 : :
466 [ - + ]: 1 : egg_test_wait ();
467 : :
468 : 1 : service = secret_service_get_finish (result, &error);
469 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
470 [ - + ]: 1 : g_assert_no_error (error);
471 : 1 : g_object_unref (result);
472 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
473 : :
474 : 1 : path = secret_service_get_session_dbus_path (service);
475 [ - + ]: 1 : g_assert_null (path);
476 : :
477 : 1 : g_object_unref (service);
478 : 1 : secret_service_disconnect ();
479 [ - + ]: 1 : g_assert_null (service);
480 : 1 : }
481 : :
482 : : static void
483 : 1 : test_connect_ensure_async (Test *test,
484 : : gconstpointer used)
485 : : {
486 : 1 : GError *error = NULL;
487 : 1 : GAsyncResult *result = NULL;
488 : : SecretService *service;
489 : : const gchar *path;
490 : :
491 : : /* Passing true, ensures session is established */
492 : 1 : secret_service_get (SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
493 [ - + ]: 1 : g_assert_null (result);
494 : :
495 [ - + ]: 1 : egg_test_wait ();
496 : :
497 : 1 : service = secret_service_get_finish (result, &error);
498 [ - + ]: 1 : g_assert_no_error (error);
499 [ - + + - : 1 : g_assert_true (SECRET_IS_SERVICE (service));
+ - - + ]
500 : 1 : g_object_unref (result);
501 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
502 : :
503 : 1 : path = secret_service_get_session_dbus_path (service);
504 [ - + ]: 1 : g_assert_nonnull (path);
505 : :
506 : 1 : g_object_unref (service);
507 : 1 : secret_service_disconnect ();
508 [ - + ]: 1 : g_assert_null (service);
509 : 1 : }
510 : :
511 : : static void
512 : 1 : test_ensure_sync (Test *test,
513 : : gconstpointer used)
514 : : {
515 : 1 : GError *error = NULL;
516 : : SecretService *service;
517 : : SecretServiceFlags flags;
518 : : gboolean ret;
519 : :
520 : : /* Passing true, ensures session is established */
521 : 1 : service = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
522 : : SECRET_SERVICE_NONE, NULL, &error);
523 [ - + ]: 1 : g_assert_no_error (error);
524 [ - + ]: 1 : g_assert_nonnull (service);
525 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
526 : :
527 : 1 : flags = secret_service_get_flags (service);
528 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_NONE);
529 : :
530 : 1 : ret = secret_service_load_collections_sync (service, NULL, &error);
531 [ - + ]: 1 : g_assert_no_error (error);
532 [ - + ]: 1 : g_assert_true (ret);
533 : :
534 : 1 : g_object_get (service, "flags", &flags, NULL);
535 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_LOAD_COLLECTIONS);
536 : :
537 : 1 : ret = secret_service_ensure_session_sync (service, NULL, &error);
538 [ - + ]: 1 : g_assert_no_error (error);
539 [ - + ]: 1 : g_assert_true (ret);
540 : :
541 : 1 : flags = secret_service_get_flags (service);
542 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
543 : :
544 : 1 : g_object_unref (service);
545 [ - + ]: 1 : g_assert_null (service);
546 : 1 : }
547 : :
548 : : static void
549 : 1 : test_ensure_async (Test *test,
550 : : gconstpointer used)
551 : : {
552 : 1 : GAsyncResult *result = NULL;
553 : : SecretServiceFlags flags;
554 : : SecretService *service;
555 : 1 : GError *error = NULL;
556 : : gboolean ret;
557 : :
558 : : /* Passing true, ensures session is established */
559 : 1 : service = secret_service_open_sync (SECRET_TYPE_SERVICE, NULL,
560 : : SECRET_SERVICE_NONE, NULL, &error);
561 [ - + ]: 1 : g_assert_no_error (error);
562 [ - + ]: 1 : g_assert_nonnull (service);
563 : :
564 : 1 : flags = secret_service_get_flags (service);
565 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_NONE);
566 : :
567 : 1 : secret_service_load_collections (service, NULL, on_complete_get_result, &result);
568 [ - + ]: 1 : g_assert_null (result);
569 : :
570 [ - + ]: 1 : egg_test_wait ();
571 : :
572 : 1 : ret = secret_service_load_collections_finish (service, result, &error);
573 [ - + ]: 1 : g_assert_no_error (error);
574 [ - + ]: 1 : g_assert_true (ret);
575 : 1 : g_object_unref (result);
576 : 1 : result = NULL;
577 : :
578 : 1 : g_object_get (service, "flags", &flags, NULL);
579 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_LOAD_COLLECTIONS);
580 : :
581 : 1 : secret_service_ensure_session (service, NULL, on_complete_get_result, &result);
582 [ - + ]: 1 : g_assert_null (result);
583 : :
584 [ - + ]: 1 : egg_test_wait ();
585 : :
586 : 1 : ret = secret_service_ensure_session_finish (service, result, &error);
587 [ - + ]: 1 : g_assert_no_error (error);
588 [ - + ]: 1 : g_assert_true (ret);
589 : 1 : g_object_unref (result);
590 : 1 : result = NULL;
591 : 1 : g_object_add_weak_pointer (G_OBJECT (service), (gpointer *)&service);
592 : :
593 : 1 : flags = secret_service_get_flags (service);
594 [ - + ]: 1 : g_assert_cmpuint (flags, ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
595 : :
596 : 1 : g_object_unref (service);
597 [ - + ]: 1 : g_assert_null (service);
598 : 1 : }
599 : :
600 : : int
601 : 1 : main (int argc, char **argv)
602 : : {
603 : 1 : g_test_init (&argc, &argv, NULL);
604 : 1 : g_set_prgname ("test-service");
605 : :
606 : 1 : g_test_add ("/service/get-sync", Test, "mock-service-normal.py", setup_mock, test_get_sync, teardown_mock);
607 : 1 : g_test_add ("/service/get-async", Test, "mock-service-normal.py", setup_mock, test_get_async, teardown_mock);
608 : 1 : g_test_add ("/service/get-more-sync", Test, "mock-service-normal.py", setup_mock, test_get_more_sync, teardown_mock);
609 : 1 : g_test_add ("/service/get-more-async", Test, "mock-service-normal.py", setup_mock, test_get_more_async, teardown_mock);
610 : :
611 : 1 : g_test_add ("/service/open-sync", Test, "mock-service-normal.py", setup_mock, test_open_sync, teardown_mock);
612 : 1 : g_test_add ("/service/open-async", Test, "mock-service-normal.py", setup_mock, test_open_async, teardown_mock);
613 : 1 : g_test_add ("/service/open-more-sync", Test, "mock-service-normal.py", setup_mock, test_open_more_sync, teardown_mock);
614 : 1 : g_test_add ("/service/open-more-async", Test, "mock-service-normal.py", setup_mock, test_open_more_async, teardown_mock);
615 : :
616 : 1 : g_test_add ("/service/connect-sync", Test, "mock-service-normal.py", setup_mock, test_connect_async, teardown_mock);
617 : 1 : g_test_add ("/service/connect-ensure-sync", Test, "mock-service-normal.py", setup_mock, test_connect_ensure_async, teardown_mock);
618 : 1 : g_test_add ("/service/ensure-sync", Test, "mock-service-normal.py", setup_mock, test_ensure_sync, teardown_mock);
619 : 1 : g_test_add ("/service/ensure-async", Test, "mock-service-normal.py", setup_mock, test_ensure_async, teardown_mock);
620 : :
621 : 1 : return egg_tests_run_with_loop ();
622 : : }
|