1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of gsignond
6 * Copyright (C) 2012 Intel Corporation.
8 * Contact: Amarnaht Valluri <amarnath.valluri@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
36 #include "daemon/dbus/gsignond-dbus.h"
37 #include "daemon/dbus/gsignond-dbus-auth-service-gen.h"
38 #include "daemon/dbus/gsignond-dbus-identity-gen.h"
39 #include "daemon/dbus/gsignond-dbus-auth-session-gen.h"
40 #include "common/gsignond-identity-info.h"
41 #include "gsignond/gsignond-log.h"
44 # ifdef GSIGNOND_SERVICE
45 # undef GSIGNOND_SERVICE
47 # define GSIGNOND_SERVICE NULL
55 { "UserName", "s", "test_user" },
56 { "Caption", "s", "test_caption" },
57 { "Secret", "s", "test_pass" },
58 { "StoreSecret", "b", (void *)TRUE}
62 GTestDBus *dbus = NULL;
67 static gchar* _get_executable_name()
74 //valgrind does some magic with tasks, so we read the executable name of
75 //the 'main' task, instead of the current task
76 procfname = g_strdup_printf ("/proc/%d/task/%d/exe", pid, pid);
77 path = g_malloc0 (PATH_MAX + 1);
78 res = readlink (procfname, path, PATH_MAX);
82 WARN ("failed to follow link for pid %d", pid);
92 gchar* exe_name = _get_executable_name();
93 fail_if(exe_name == NULL);
95 fail_if (g_setenv ("G_MESSAGES_DEBUG", "all", TRUE) == FALSE);
96 fail_if (g_setenv ("SSO_IDENTITY_TIMEOUT", "5", TRUE) == FALSE);
97 fail_if (g_setenv ("SSO_DAEMON_TIMEOUT", "5", TRUE) == FALSE);
98 fail_if (g_setenv ("SSO_AUTH_SESSION_TIMEOUT", "5", TRUE) == FALSE);
99 fail_if (g_setenv ("SSO_STORAGE_PATH", "/tmp/gsignond", TRUE) == FALSE);
100 fail_if (g_setenv ("SSO_SECRET_PATH", "/tmp/gsignond", TRUE) == FALSE);
101 fail_if (g_setenv ("SSO_KEYCHAIN_SYSCTX", exe_name, TRUE) == FALSE);
102 fail_if (g_setenv ("SSO_PLUGIN_TIMEOUT", "5", TRUE) == FALSE);
104 DBG ("Programe pid %d, name : %s\n", getpid(), exe_name);
107 if (system("rm -rf /tmp/gsignond") != 0) {
108 DBG("Failed to clean db path : %s\n", strerror(errno));
111 dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
112 fail_unless (dbus != NULL, "could not create test dbus");
114 g_test_dbus_add_service_dir (dbus, GSIGNOND_TEST_DBUS_SERVICE_DIR);
116 g_test_dbus_up (dbus);
117 DBG ("Test dbus server address : %s\n", g_test_dbus_get_bus_address(dbus));
119 GError *error = NULL;
121 /* start daemon maually */
123 gchar *test_daemon_path = g_build_filename (g_getenv("SSO_BIN_DIR"),
125 fail_if (test_daemon_path == NULL, "No SSO daemon path found");
127 argv[0] = test_daemon_path;
129 g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
130 &daemon_pid, &error);
131 g_free (test_daemon_path);
132 fail_if (error != NULL, "Failed to span daemon : %s",
133 error ? error->message : "");
134 sleep (5); /* 5 seconds */
136 /* session bus where no GTestBus support */
137 GIOChannel *channel = NULL;
138 gchar *bus_address = NULL;
141 gchar *argv[] = {"dbus-daemon", "--config-file=<<conf-file>>", "--print-address=<<fd>>", NULL};
143 const gchar *dbus_monitor = NULL;
145 argv[1] = g_strdup_printf ("--config-file=%s", "gsignond-dbus.conf");
147 if (pipe(pipe_fd)== -1) {
148 WARN("Failed to open temp file : %s", error->message);
149 argv[2] = g_strdup_printf ("--print-address=1");
150 g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &daemon_pid, NULL, NULL, &tmp_fd, &error);
153 argv[2] = g_strdup_printf ("--print-address=%d", pipe_fd[1]);
154 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH|G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, &daemon_pid, &error);
156 fail_if (error != NULL, "Failed to span daemon : %s", error ? error->message : "");
157 fail_if (daemon_pid == 0, "Failed to get daemon pid");
160 sleep (5); /* 5 seconds */
162 channel = g_io_channel_unix_new (tmp_fd);
163 g_io_channel_read_line (channel, &bus_address, NULL, &len, &error);
164 fail_if (error != NULL, "Failed to daemon address : %s", error ? error->message : "");
165 g_io_channel_unref (channel);
167 if (pipe_fd[0]) close (pipe_fd[0]);
168 if (pipe_fd[1]) close (pipe_fd[1]);
170 if (bus_address) bus_address[len] = '\0';
171 fail_if(bus_address == NULL || strlen(bus_address) == 0);
173 if (GSIGNOND_BUS_TYPE == G_BUS_TYPE_SYSTEM)
174 fail_if (g_setenv("DBUS_SYSTEM_BUS_ADDRESS", bus_address, TRUE) == FALSE);
176 fail_if (g_setenv("DBUS_SESSION_BUS_ADDRESS", bus_address, TRUE) == FALSE);
178 DBG ("Daemon Address : %s\n", bus_address);
179 g_free (bus_address);
181 if ((dbus_monitor = g_getenv("SSO_DBUS_DEBUG")) != NULL && g_strcmp0 (dbus_monitor, "0")) {
182 /* start dbus-monitor */
183 char *argv[] = {"dbus-monitor", "<<bus_type>>", NULL };
184 argv[1] = GSIGNOND_BUS_TYPE == G_BUS_TYPE_SYSTEM ? "--system" : "--session" ;
185 g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
187 DBG ("Error while running dbus-monitor : %s", error->message);
188 g_error_free (error);
193 DBG ("Daemon PID = %d\n", daemon_pid);
198 teardown_daemon (void)
201 g_test_dbus_down (dbus);
203 if (daemon_pid) kill (daemon_pid, SIGTERM);
206 g_unsetenv ("SSO_IDENTITY_TIMEOUT");
207 g_unsetenv ("SSO_DAEMON_TIMEOUT");
208 g_unsetenv ("SSO_AUTH_SESSION_TIMEOUT");
209 g_unsetenv ("SSO_STORAGE_PATH");
210 g_unsetenv ("SSO_SECRET_PATH");
211 g_unsetenv ("SSO_KEYCHAIN_SYSCTX");
214 gboolean _validate_identity_info (GVariant *identity_info)
216 GSignondIdentityInfo *identity = 0;
217 const gchar *username = 0;
218 if (!identity_info) return FALSE;
220 identity = (GSignondIdentityInfo *)gsignond_dictionary_new_from_variant (identity_info);
221 if (!identity) return FALSE;
223 username = gsignond_identity_info_get_username (identity);
225 gsignond_dictionary_unref (identity);
227 if (!username || strcmp (username, "test_user")) return FALSE;
232 GVariant * _get_test_identity_data()
234 GVariantBuilder builder, method_builder;
235 const gchar *mechanisms[] = {"mech1","mech2", NULL };
238 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
240 for (i=0; i < sizeof(data)/sizeof(struct IdentityData); i++) {
241 g_variant_builder_add (&builder, "{sv}", data[i].key, g_variant_new (data[i].type, data[i].value));
244 g_variant_builder_init (&method_builder, (const GVariantType *)"a{sas}");
245 g_variant_builder_add (&method_builder, "{s^as}", "ssotest", mechanisms);
247 g_variant_builder_add (&builder, "{sv}", "AuthMethods", g_variant_builder_end (&method_builder));
249 return g_variant_builder_end (&builder);
252 GVariant * _create_identity_info_with_data (const gchar *username,
253 const gchar *caption,
255 const gchar *methods[],
256 const gchar **mechanisms[])
258 GVariantBuilder builder;
260 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
262 if(username) g_variant_builder_add (&builder, "{sv}", "UserName", g_variant_new_string (username));
263 if(caption) g_variant_builder_add (&builder, "{sv}", "Caption", g_variant_new_string (caption));
264 if (type != 0) g_variant_builder_add (&builder, "{sv}", "Type", g_variant_new_int32(type));
265 if (methods && mechanisms) {
266 GVariantBuilder method_builder;
269 g_variant_builder_init (&method_builder, (const GVariantType *)"a{sas}");
271 for (i=0; methods[i]; i++) {
272 g_variant_builder_add (&method_builder, "{s^as}", methods[i], mechanisms[i]);
275 g_variant_builder_add (&builder, "{sv}", "AuthMethods", g_variant_builder_end (&method_builder));
278 return g_variant_builder_end (&builder);
282 GDBusConnection * _get_bus_connection (GError **error)
287 g_snprintf (address, 127, GSIGNOND_DBUS_ADDRESS, g_get_user_runtime_dir());
288 return g_dbus_connection_new_for_address_sync (
290 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
295 return g_bus_get_sync (GSIGNOND_BUS_TYPE, NULL, error);
299 GSignondDbusAuthService * _get_auth_service (GDBusConnection *connection,
302 return gsignond_dbus_auth_service_proxy_new_sync (
304 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
306 GSIGNOND_DAEMON_OBJECTPATH,
310 GSignondDbusIdentity * _get_identity_for_path (GDBusConnection *connection,
311 const gchar *identity_path,
314 return gsignond_dbus_identity_proxy_new_sync (
316 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
322 GSignondDbusAuthSession * _get_auth_session_for_path (GDBusConnection *connection,
323 const gchar *session_path,
326 return gsignond_dbus_auth_session_proxy_new_sync (
328 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
334 GSignondDbusIdentity * _register_identity (GSignondDbusAuthService *auth_service,
335 const gchar *app_context,
338 GDBusConnection *connection = NULL;
339 GSignondDbusIdentity *identity = NULL;
340 gchar *identity_path = NULL;
342 gboolean res = gsignond_dbus_auth_service_call_register_new_identity_sync (
350 DBG (" ERROR :: %s", error ? (*error)->message : "");
354 connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (auth_service));
355 identity = _get_identity_for_path (connection, identity_path, error);
357 g_free (identity_path);
362 GSignondDbusIdentity * _get_identity (GSignondDbusAuthService *auth_service,
364 const gchar *app_context,
365 GVariant **identity_info,
369 gchar *identity_path = NULL;
370 GDBusConnection *connection = NULL;
371 GSignondDbusIdentity *identity = NULL;
373 res = gsignond_dbus_auth_service_call_get_identity_sync(
382 if (res == FALSE || !identity_path) {
383 DBG ("ERROR :: %s", error ? (*error)->message : "");
387 connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (auth_service));
388 identity = _get_identity_for_path (connection, identity_path, error);
390 g_free (identity_path);
398 START_TEST (test_register_new_identity)
401 GDBusConnection *connection = NULL;
402 GSignondDbusAuthService *auth_service = NULL;
403 GSignondDbusIdentity *identity = NULL;
405 connection = _get_bus_connection (&error);
406 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
408 auth_service = _get_auth_service (connection, &error);
409 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
411 identity = _register_identity (auth_service, "test_app", &error);
412 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
414 g_object_unref (identity);
415 g_object_unref (auth_service);
416 g_object_unref (connection);
420 START_TEST (test_register_new_identity_with_no_app_context)
422 GError *error = NULL;
423 GSignondDbusAuthService *auth_service = NULL;
424 GSignondDbusIdentity *identity = NULL;
425 GDBusConnection *connection = _get_bus_connection (&error);
426 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
427 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
429 auth_service = _get_auth_service (connection, &error);
430 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
432 identity = _register_identity (auth_service, "", &error);
433 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
435 g_object_unref (identity);
436 g_object_unref (auth_service);
437 g_object_unref (connection);
441 START_TEST (test_identity_store)
443 GError *error = NULL; gboolean res = FALSE;
444 GSignondDbusAuthService *auth_service = 0;
445 GSignondDbusIdentity *identity = 0;
447 GVariant *identity_info = NULL;
449 GDBusConnection *connection = _get_bus_connection (&error);
450 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
451 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
453 auth_service = _get_auth_service (connection, &error);
454 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
456 identity_info = _get_test_identity_data ();
457 fail_if (identity_info == NULL, "Failed to get test identity data");
459 identity = _register_identity (auth_service, "test_app", &error);
460 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
462 res = gsignond_dbus_identity_call_store_sync (identity, identity_info,
464 fail_if (res == FALSE, "Failed to store identity : %s", error ? error->message : "");
467 DBG ("Identity id : %d\n", id);
469 g_object_unref (identity);
470 g_object_unref (auth_service);
471 g_object_unref (connection);
475 START_TEST(test_identity_get_identity)
477 GError *error = NULL;
478 GSignondDbusAuthService *auth_service = 0;
479 guint32 id = 1; /* identity id created in test_identity_store */
480 GVariant *identity_info = NULL;
481 GSignondDbusIdentity *identity = NULL;
482 GDBusConnection *connection = _get_bus_connection (&error);
483 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
484 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
486 auth_service = _get_auth_service (connection, &error);
487 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
489 identity = _get_identity (auth_service, id, "test_app", &identity_info, &error);
490 fail_if (identity == NULL, "Failed to get identity for id '%u' : %s", id, error ? error->message : "");
491 fail_if (identity_info == NULL);
493 fail_if (_validate_identity_info(identity_info) == FALSE);
495 g_object_unref (auth_service);
496 g_object_unref (identity);
497 g_object_unref (connection);
501 START_TEST(test_clear_database)
505 GSignondDbusAuthService *auth_service = 0;
506 GDBusConnection *connection = _get_bus_connection (&error);
507 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
508 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
510 auth_service = _get_auth_service (connection, &error);
511 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
513 res = gsignond_dbus_auth_service_call_clear_sync (
518 fail_if (res == FALSE || ret == FALSE, "Failed to wipe databases : %s", error ? error->message : "");
520 g_object_unref (auth_service);
521 g_object_unref (connection);
525 static void _on_session_unregistered (GSignondDbusAuthSession *sesssion, gpointer userdata)
527 gboolean *out = (gboolean*) userdata;
528 g_return_if_fail (out);
533 static void _on_identity_updated (GSignondDbusIdentity *identity, gint change_type, gpointer userdata)
535 gboolean *out = (gboolean *)userdata;
536 g_return_if_fail (out);
538 if (change_type == 2 /* GSIGNOND_IDENTITY_SIGNED_OUT */)
542 static void _on_sign_out_reply (GSignondDbusIdentity *sender, GAsyncResult *reply, gpointer data)
544 GError *error = NULL;
546 gboolean res = FALSE, ret = FALSE;
548 ret = gsignond_dbus_identity_call_sign_out_finish (sender, &res, reply, &error);
550 fail_if (ret == FALSE, "failed to finish signout, %s", error ? error->message : "");
551 fail_if (res == FALSE, "failed to call signout on identity : %s", error ? error->message : "");
553 g_main_loop_quit ((GMainLoop *)data);
554 g_main_loop_unref((GMainLoop *)data);
557 START_TEST(test_identity_signout)
561 GSignondDbusAuthService *auth_service = 0;
562 GSignondDbusIdentity *identity = 0;
563 GSignondDbusAuthSession *auth_session = 0;
564 GVariant *identity_info = NULL;
565 gchar *session_path = NULL;
567 gboolean identity_signed_out = FALSE;
568 gboolean session_unregistered = FALSE;
569 GMainLoop *loop = NULL;
570 GDBusConnection *connection = _get_bus_connection (&error);
571 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
572 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
574 loop = g_main_loop_new (NULL, FALSE);
576 auth_service = _get_auth_service (connection, &error);
577 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
579 identity = _register_identity (auth_service, "", &error);
580 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
582 identity_info = _get_test_identity_data ();
583 fail_if (identity_info == NULL);
585 res = gsignond_dbus_identity_call_store_sync (identity, identity_info,
587 fail_if (res == FALSE, "Failed to store identity");
590 g_signal_connect (identity, "info-updated", G_CALLBACK(_on_identity_updated), &identity_signed_out);
592 res = gsignond_dbus_identity_call_get_auth_session_sync (
593 identity, "ssotest", &session_path, NULL, &error);
595 fail_if (res == FALSE, "Failed to create authentication session on identity for method 'ssotest', error : %s",
596 error ? error->message : "");
597 fail_if (session_path == NULL, "(null) session_path");
599 auth_session = _get_auth_session_for_path (connection, session_path, &error);
601 g_free (session_path);
602 fail_if (error != NULL, "failed to created session proxy for path '%s', error: %s",
603 session_path, error ? error->message : "");
604 fail_if (auth_session == NULL, "(null) session object");
606 g_signal_connect (auth_session, "unregistered", G_CALLBACK (_on_session_unregistered), &session_unregistered);
608 /* Call SignOut on identity */
609 gsignond_dbus_identity_call_sign_out (identity, NULL, (GAsyncReadyCallback)_on_sign_out_reply, loop);
611 g_main_loop_run (loop);
613 fail_unless (session_unregistered == TRUE, "Session unregistred not reached");
614 fail_unless (identity_signed_out == TRUE, "Identity signed out signal not reached");
616 g_object_unref (auth_service);
617 g_object_unref (identity);
618 g_object_unref (auth_session);
619 g_object_unref (connection);
623 START_TEST(test_query_identities)
625 GDBusConnection *connection = NULL;
626 GSignondDbusAuthService *auth_service = NULL;
627 GSignondDbusIdentity *identity = NULL;
628 GVariant *v_info = NULL;
629 GSignondIdentityInfo *info1 = NULL, *info2 = NULL, *info3 = NULL, *tmp_info = NULL;
630 GSignondDictionary *filter = NULL;
631 GVariant *v_identities = NULL;
632 const gchar *methods[] = { "ssotest", NULL };
633 const gchar *mech[] = {"mech1", "mech2", NULL};
634 const gchar **mechanisms[] = { mech };
637 GError *error = NULL;
639 connection = _get_bus_connection (&error);
640 fail_if (connection == NULL, "Failed to get bus connection : %s", error ? error->message : "");
642 auth_service = _get_auth_service (connection, &error);
643 fail_if (auth_service == NULL, "Failed to get auth_service : %s", error ? error->message : "");
645 /* created identity1 */
646 identity = _register_identity (auth_service, "app_context_A", &error);
647 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
649 v_info = _create_identity_info_with_data ("user1", "caption1", 1, methods, mechanisms);
650 fail_if (v_info == NULL);
651 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
652 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
653 g_object_unref (identity);
655 identity = _get_identity (auth_service, id, "app_context_A", &v_info, &error);
656 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
657 g_object_unref (identity);
658 info1 = gsignond_dictionary_new_from_variant (v_info);
660 /* created identity2 */
661 identity = _register_identity (auth_service, "app_context_B", &error);
662 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
664 v_info = _create_identity_info_with_data ("user2", "caption2", 2, methods, mechanisms);
665 fail_if (v_info == NULL);
666 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
667 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
668 g_object_unref (identity);
670 identity = _get_identity (auth_service, id, "app_context_B", &v_info, &error);
671 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
672 g_object_unref (identity);
673 info2 = gsignond_dictionary_new_from_variant (v_info);
675 /* create identity3 */
676 identity = _register_identity (auth_service, "app_context_A", &error);
677 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
679 v_info = _create_identity_info_with_data ("user2", "caption3", 2, methods, mechanisms);
680 fail_if (v_info == NULL);
681 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
682 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
683 g_object_unref (identity);
685 identity = _get_identity (auth_service, id, "app_context_A", &v_info, &error);
686 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
687 g_object_unref (identity);
688 info3 = gsignond_dictionary_new_from_variant (v_info);
690 /* query identities for app-context: app_context_A */
692 filter = gsignond_dictionary_new();
693 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
694 gsignond_dictionary_to_variant (filter),
695 "app_context_A", &v_identities, NULL, &error);
696 gsignond_dictionary_unref (filter);
697 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
698 "app context 'app_context_A' : %s",
699 error ? error->message : "");
700 fail_if (g_variant_n_children (v_identities) != 2,
701 "Expected no of identities '%d', got '%d'", 2,
702 g_variant_n_children(v_identities));
703 /* validated query results */
704 tmp_info = gsignond_dictionary_new_from_variant (
705 g_variant_get_child_value (v_identities, 0));
706 fail_if (gsignond_identity_info_compare (info1, tmp_info) == FALSE);
707 gsignond_identity_info_unref (tmp_info);
709 tmp_info = gsignond_dictionary_new_from_variant (
710 g_variant_get_child_value (v_identities, 1));
711 fail_if (gsignond_identity_info_compare (info3, tmp_info) == FALSE);
712 gsignond_identity_info_unref (tmp_info);
714 /* query identities for app-context: app_context_B, Identity type : 2 */
716 filter = gsignond_dictionary_new();
717 gsignond_dictionary_set_int32 (filter, "Type", 2);
718 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
719 gsignond_dictionary_to_variant (filter),
720 "app_context_B", &v_identities, NULL, &error);
721 gsignond_dictionary_unref (filter);
722 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
723 "app context 'app_context_B' and Type: 2 : %s",
724 error ? error->message : "");
725 /* validated query results */
726 fail_if (g_variant_n_children (v_identities) != 1,
727 "Expected no of identities '%d', got '%d'", 1,
728 g_variant_n_children(v_identities));
729 tmp_info = gsignond_dictionary_new_from_variant (
730 g_variant_get_child_value (v_identities, 0));
731 fail_if (gsignond_identity_info_compare (info2, tmp_info) == FALSE);
732 gsignond_identity_info_unref (tmp_info);
734 /* query identities for app-context: app_context_A, Caption: "cap*" */
736 filter = gsignond_dictionary_new();
737 gsignond_dictionary_set_string (filter, "Caption", "cap");
738 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
739 gsignond_dictionary_to_variant (filter),
740 "app_context_B", &v_identities, NULL, &error);
741 gsignond_dictionary_unref (filter);
742 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
743 "app context 'app_context_A' : %s",
744 error ? error->message : "");
745 /* validated query results */
746 fail_if (g_variant_n_children (v_identities) != 1,
747 "Expected no of identities '%d', got '%d'", 1,
748 g_variant_n_children(v_identities));
749 tmp_info = gsignond_dictionary_new_from_variant (
750 g_variant_get_child_value (v_identities, 0));
751 fail_if (gsignond_identity_info_compare
752 (info2, tmp_info) == FALSE);
753 gsignond_identity_info_unref (tmp_info);
755 gsignond_identity_info_unref (info1);
756 gsignond_identity_info_unref (info2);
757 gsignond_identity_info_unref (info3);
759 g_object_unref (auth_service);
760 g_object_unref (connection);
764 Suite* daemon_suite (void)
766 Suite *s = suite_create ("Gsignon daemon");
768 TCase *tc = tcase_create ("Identity");
770 tcase_set_timeout(tc, 10);
771 tcase_add_unchecked_fixture (tc, setup_daemon, teardown_daemon);
773 tcase_add_test (tc, test_register_new_identity);
774 tcase_add_test (tc, test_register_new_identity_with_no_app_context);
775 tcase_add_test (tc, test_identity_store);
776 tcase_add_test (tc, test_identity_get_identity);
777 tcase_add_test (tc, test_clear_database);
778 tcase_add_test (tc, test_identity_signout);
779 tcase_add_test (tc, test_query_identities);
781 suite_add_tcase (s, tc);
786 int main (int argc, char *argv[])
792 #if !GLIB_CHECK_VERSION (2, 36, 0)
797 sr = srunner_create(s);
799 srunner_run_all(sr, CK_VERBOSE);
801 number_failed = srunner_ntests_failed(sr);
804 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;