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 ("GSIGNOND_CONFIG", "daemontest.conf", TRUE) == FALSE);
96 fail_if (g_setenv ("SSO_STORAGE_PATH", "/tmp/gsignond", TRUE) == FALSE);
97 fail_if (g_setenv ("SSO_KEYCHAIN_SYSCTX", exe_name, TRUE) == FALSE);
99 DBG ("Programe pid %d, name : %s\n", getpid(), exe_name);
102 if (system("rm -rf /tmp/gsignond") != 0) {
103 DBG("Failed to clean db path : %s\n", strerror(errno));
106 dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
107 fail_unless (dbus != NULL, "could not create test dbus");
109 g_test_dbus_add_service_dir (dbus, GSIGNOND_TEST_DBUS_SERVICE_DIR);
111 g_test_dbus_up (dbus);
112 DBG ("Test dbus server address : %s\n", g_test_dbus_get_bus_address(dbus));
114 GError *error = NULL;
116 /* start daemon maually */
118 gchar *test_daemon_path = g_build_filename (g_getenv("SSO_BIN_DIR"),
120 fail_if (test_daemon_path == NULL, "No SSO daemon path found");
122 argv[0] = test_daemon_path;
124 g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
125 &daemon_pid, &error);
126 g_free (test_daemon_path);
127 fail_if (error != NULL, "Failed to span daemon : %s",
128 error ? error->message : "");
129 sleep (5); /* 5 seconds */
131 /* session bus where no GTestBus support */
132 GIOChannel *channel = NULL;
133 gchar *bus_address = NULL;
136 gchar *argv[] = {"dbus-daemon", "--config-file=<<conf-file>>", "--print-address=<<fd>>", NULL};
138 const gchar *dbus_monitor = NULL;
140 argv[1] = g_strdup_printf ("--config-file=%s", "gsignond-dbus.conf");
142 if (pipe(pipe_fd)== -1) {
143 WARN("Failed to open temp file : %s", error->message);
144 argv[2] = g_strdup_printf ("--print-address=1");
145 g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &daemon_pid, NULL, NULL, &tmp_fd, &error);
148 argv[2] = g_strdup_printf ("--print-address=%d", pipe_fd[1]);
149 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH|G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, &daemon_pid, &error);
151 fail_if (error != NULL, "Failed to span daemon : %s", error ? error->message : "");
152 fail_if (daemon_pid == 0, "Failed to get daemon pid");
155 sleep (5); /* 5 seconds */
157 channel = g_io_channel_unix_new (tmp_fd);
158 g_io_channel_read_line (channel, &bus_address, NULL, &len, &error);
159 fail_if (error != NULL, "Failed to daemon address : %s", error ? error->message : "");
160 g_io_channel_unref (channel);
162 if (pipe_fd[0]) close (pipe_fd[0]);
163 if (pipe_fd[1]) close (pipe_fd[1]);
165 if (bus_address) bus_address[len] = '\0';
166 fail_if(bus_address == NULL || strlen(bus_address) == 0);
168 if (GSIGNOND_BUS_TYPE == G_BUS_TYPE_SYSTEM)
169 fail_if (g_setenv("DBUS_SYSTEM_BUS_ADDRESS", bus_address, TRUE) == FALSE);
171 fail_if (g_setenv("DBUS_SESSION_BUS_ADDRESS", bus_address, TRUE) == FALSE);
173 DBG ("Daemon Address : %s\n", bus_address);
174 g_free (bus_address);
176 if ((dbus_monitor = g_getenv("SSO_DBUS_DEBUG")) != NULL && g_strcmp0 (dbus_monitor, "0")) {
177 /* start dbus-monitor */
178 char *argv[] = {"dbus-monitor", "<<bus_type>>", NULL };
179 argv[1] = GSIGNOND_BUS_TYPE == G_BUS_TYPE_SYSTEM ? "--system" : "--session" ;
180 g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
182 DBG ("Error while running dbus-monitor : %s", error->message);
183 g_error_free (error);
188 DBG ("Daemon PID = %d\n", daemon_pid);
193 teardown_daemon (void)
196 g_test_dbus_down (dbus);
198 if (daemon_pid) kill (daemon_pid, SIGTERM);
201 g_unsetenv ("SSO_IDENTITY_TIMEOUT");
202 g_unsetenv ("SSO_DAEMON_TIMEOUT");
203 g_unsetenv ("SSO_AUTH_SESSION_TIMEOUT");
204 g_unsetenv ("SSO_STORAGE_PATH");
205 g_unsetenv ("SSO_KEYCHAIN_SYSCTX");
208 gboolean _validate_identity_info (GVariant *identity_info)
210 GSignondIdentityInfo *identity = 0;
211 const gchar *username = 0;
212 if (!identity_info) return FALSE;
214 identity = (GSignondIdentityInfo *)gsignond_identity_info_new_from_variant (identity_info);
215 if (!identity) return FALSE;
217 username = gsignond_identity_info_get_username (identity);
219 if (!username || strcmp (username, "test_user")) return FALSE;
221 gsignond_identity_info_unref (identity);
226 GVariant * _get_test_identity_data()
228 GVariantBuilder builder, method_builder;
229 const gchar *mechanisms[] = {"mech1","mech2", NULL };
232 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
234 for (i=0; i < sizeof(data)/sizeof(struct IdentityData); i++) {
235 g_variant_builder_add (&builder, "{sv}", data[i].key, g_variant_new (data[i].type, data[i].value));
238 g_variant_builder_init (&method_builder, (const GVariantType *)"a{sas}");
239 g_variant_builder_add (&method_builder, "{s^as}", "ssotest", mechanisms);
241 g_variant_builder_add (&builder, "{sv}", "AuthMethods", g_variant_builder_end (&method_builder));
243 return g_variant_builder_end (&builder);
246 GVariant * _create_identity_info_with_data (const gchar *username,
247 const gchar *caption,
249 const gchar *methods[],
250 const gchar **mechanisms[])
252 GVariantBuilder builder;
254 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
256 if(username) g_variant_builder_add (&builder, "{sv}", "UserName", g_variant_new_string (username));
257 if(caption) g_variant_builder_add (&builder, "{sv}", "Caption", g_variant_new_string (caption));
258 if (type != 0) g_variant_builder_add (&builder, "{sv}", "Type", g_variant_new_int32(type));
259 if (methods && mechanisms) {
260 GVariantBuilder method_builder;
263 g_variant_builder_init (&method_builder, (const GVariantType *)"a{sas}");
265 for (i=0; methods[i]; i++) {
266 g_variant_builder_add (&method_builder, "{s^as}", methods[i], mechanisms[i]);
269 g_variant_builder_add (&builder, "{sv}", "AuthMethods", g_variant_builder_end (&method_builder));
272 return g_variant_builder_end (&builder);
276 GDBusConnection * _get_bus_connection (GError **error)
281 g_snprintf (address, 127, GSIGNOND_DBUS_ADDRESS, g_get_user_runtime_dir());
282 return g_dbus_connection_new_for_address_sync (
284 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
289 return g_bus_get_sync (GSIGNOND_BUS_TYPE, NULL, error);
293 GSignondDbusAuthService * _get_auth_service (GDBusConnection *connection,
296 return gsignond_dbus_auth_service_proxy_new_sync (
298 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
300 GSIGNOND_DAEMON_OBJECTPATH,
304 GSignondDbusIdentity * _get_identity_for_path (GDBusConnection *connection,
305 const gchar *identity_path,
308 return gsignond_dbus_identity_proxy_new_sync (
310 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
316 GSignondDbusAuthSession * _get_auth_session_for_path (GDBusConnection *connection,
317 const gchar *session_path,
320 return gsignond_dbus_auth_session_proxy_new_sync (
322 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
328 GSignondDbusIdentity * _register_identity (GSignondDbusAuthService *auth_service,
329 const gchar *app_context,
332 GDBusConnection *connection = NULL;
333 GSignondDbusIdentity *identity = NULL;
334 gchar *identity_path = NULL;
336 gboolean res = gsignond_dbus_auth_service_call_register_new_identity_sync (
344 DBG (" ERROR :: %s", error ? (*error)->message : "");
348 connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (auth_service));
349 identity = _get_identity_for_path (connection, identity_path, error);
351 g_free (identity_path);
356 GSignondDbusIdentity * _get_identity (GSignondDbusAuthService *auth_service,
358 const gchar *app_context,
359 GVariant **identity_info,
363 gchar *identity_path = NULL;
364 GDBusConnection *connection = NULL;
365 GSignondDbusIdentity *identity = NULL;
367 res = gsignond_dbus_auth_service_call_get_identity_sync(
376 if (res == FALSE || !identity_path) {
377 DBG ("ERROR :: %s", error ? (*error)->message : "");
381 connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (auth_service));
382 identity = _get_identity_for_path (connection, identity_path, error);
384 g_free (identity_path);
392 START_TEST (test_register_new_identity)
395 GDBusConnection *connection = NULL;
396 GSignondDbusAuthService *auth_service = NULL;
397 GSignondDbusIdentity *identity = NULL;
399 connection = _get_bus_connection (&error);
400 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
402 auth_service = _get_auth_service (connection, &error);
403 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
405 identity = _register_identity (auth_service, "test_app", &error);
406 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
408 g_object_unref (identity);
409 g_object_unref (auth_service);
410 g_object_unref (connection);
414 START_TEST (test_register_new_identity_with_no_app_context)
416 GError *error = NULL;
417 GSignondDbusAuthService *auth_service = NULL;
418 GSignondDbusIdentity *identity = NULL;
419 GDBusConnection *connection = _get_bus_connection (&error);
420 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
421 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
423 auth_service = _get_auth_service (connection, &error);
424 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
426 identity = _register_identity (auth_service, "", &error);
427 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
429 g_object_unref (identity);
430 g_object_unref (auth_service);
431 g_object_unref (connection);
435 START_TEST (test_identity_store)
437 GError *error = NULL; gboolean res = FALSE;
438 GSignondDbusAuthService *auth_service = 0;
439 GSignondDbusIdentity *identity = 0;
441 GVariant *identity_info = NULL;
443 GDBusConnection *connection = _get_bus_connection (&error);
444 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
445 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
447 auth_service = _get_auth_service (connection, &error);
448 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
450 identity_info = _get_test_identity_data ();
451 fail_if (identity_info == NULL, "Failed to get test identity data");
453 identity = _register_identity (auth_service, "test_app", &error);
454 fail_if (identity == NULL, "Failed to register identity : %s", error ? error->message : "");
456 res = gsignond_dbus_identity_call_store_sync (identity, identity_info,
458 fail_if (res == FALSE, "Failed to store identity : %s", error ? error->message : "");
461 DBG ("Identity id : %d\n", id);
463 g_object_unref (identity);
464 g_object_unref (auth_service);
465 g_object_unref (connection);
469 START_TEST(test_identity_get_identity)
471 GError *error = NULL;
472 GSignondDbusAuthService *auth_service = 0;
473 guint32 id = 1; /* identity id created in test_identity_store */
474 GVariant *identity_info = NULL;
475 GSignondDbusIdentity *identity = NULL;
476 GDBusConnection *connection = _get_bus_connection (&error);
477 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
478 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
480 auth_service = _get_auth_service (connection, &error);
481 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
483 identity = _get_identity (auth_service, id, "test_app", &identity_info, &error);
484 fail_if (identity == NULL, "Failed to get identity for id '%u' : %s", id, error ? error->message : "");
485 fail_if (identity_info == NULL);
487 fail_if (_validate_identity_info(identity_info) == FALSE);
489 g_object_unref (auth_service);
490 g_object_unref (identity);
491 g_object_unref (connection);
495 START_TEST(test_clear_database)
499 GSignondDbusAuthService *auth_service = 0;
500 GDBusConnection *connection = _get_bus_connection (&error);
501 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
502 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
504 auth_service = _get_auth_service (connection, &error);
505 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
507 res = gsignond_dbus_auth_service_call_clear_sync (
512 fail_if (res == FALSE || ret == FALSE, "Failed to wipe databases : %s", error ? error->message : "");
514 g_object_unref (auth_service);
515 g_object_unref (connection);
519 static void _on_session_unregistered (GSignondDbusAuthSession *sesssion, gpointer userdata)
521 gboolean *out = (gboolean*) userdata;
522 g_return_if_fail (out);
527 static void _on_identity_updated (GSignondDbusIdentity *identity, gint change_type, gpointer userdata)
529 gboolean *out = (gboolean *)userdata;
530 g_return_if_fail (out);
532 if (change_type == 2 /* GSIGNOND_IDENTITY_SIGNED_OUT */)
536 static void _on_sign_out_reply (GSignondDbusIdentity *sender, GAsyncResult *reply, gpointer data)
538 GError *error = NULL;
540 gboolean res = FALSE, ret = FALSE;
542 ret = gsignond_dbus_identity_call_sign_out_finish (sender, &res, reply, &error);
544 fail_if (ret == FALSE, "failed to finish signout, %s", error ? error->message : "");
545 fail_if (res == FALSE, "failed to call signout on identity : %s", error ? error->message : "");
547 g_main_loop_quit ((GMainLoop *)data);
548 g_main_loop_unref((GMainLoop *)data);
551 START_TEST(test_identity_signout)
555 GSignondDbusAuthService *auth_service = 0;
556 GSignondDbusIdentity *identity = 0;
557 GSignondDbusAuthSession *auth_session = 0;
558 GVariant *identity_info = NULL;
559 gchar *session_path = NULL;
561 gboolean identity_signed_out = FALSE;
562 gboolean session_unregistered = FALSE;
563 GMainLoop *loop = NULL;
564 GDBusConnection *connection = _get_bus_connection (&error);
565 fail_if (connection == NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
566 fail_if (error != NULL, "failed to get bus connection : %s", error ? error->message : "(null)");
568 loop = g_main_loop_new (NULL, FALSE);
570 auth_service = _get_auth_service (connection, &error);
571 fail_if (auth_service == NULL, "failed to get auth_service : %s", error ? error->message : "");
573 identity = _register_identity (auth_service, "", &error);
574 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
576 identity_info = _get_test_identity_data ();
577 fail_if (identity_info == NULL);
579 res = gsignond_dbus_identity_call_store_sync (identity, identity_info,
581 fail_if (res == FALSE, "Failed to store identity");
584 g_signal_connect (identity, "info-updated", G_CALLBACK(_on_identity_updated), &identity_signed_out);
586 res = gsignond_dbus_identity_call_get_auth_session_sync (
587 identity, "ssotest", &session_path, NULL, &error);
589 fail_if (res == FALSE, "Failed to create authentication session on identity for method 'ssotest', error : %s",
590 error ? error->message : "");
591 fail_if (session_path == NULL, "(null) session_path");
593 auth_session = _get_auth_session_for_path (connection, session_path, &error);
595 g_free (session_path);
596 fail_if (error != NULL, "failed to created session proxy for path '%s', error: %s",
597 session_path, error ? error->message : "");
598 fail_if (auth_session == NULL, "(null) session object");
600 g_signal_connect (auth_session, "unregistered", G_CALLBACK (_on_session_unregistered), &session_unregistered);
602 /* Call SignOut on identity */
603 gsignond_dbus_identity_call_sign_out (identity, NULL, (GAsyncReadyCallback)_on_sign_out_reply, loop);
605 g_main_loop_run (loop);
607 fail_unless (session_unregistered == TRUE, "Session unregistred not reached");
608 fail_unless (identity_signed_out == TRUE, "Identity signed out signal not reached");
610 g_object_unref (auth_service);
611 g_object_unref (identity);
612 g_object_unref (auth_session);
613 g_object_unref (connection);
617 START_TEST(test_query_identities)
619 GDBusConnection *connection = NULL;
620 GSignondDbusAuthService *auth_service = NULL;
621 GSignondDbusIdentity *identity = NULL;
622 GVariant *v_info = NULL;
623 GSignondIdentityInfo *info1 = NULL, *info2 = NULL, *info3 = NULL, *tmp_info = NULL;
624 GSignondDictionary *filter = NULL;
625 GVariant *v_identities = NULL;
626 const gchar *methods[] = { "ssotest", NULL };
627 const gchar *mech[] = {"mech1", "mech2", NULL};
628 const gchar **mechanisms[] = { mech };
631 GError *error = NULL;
633 connection = _get_bus_connection (&error);
634 fail_if (connection == NULL, "Failed to get bus connection : %s", error ? error->message : "");
636 auth_service = _get_auth_service (connection, &error);
637 fail_if (auth_service == NULL, "Failed to get auth_service : %s", error ? error->message : "");
639 /* created identity1 */
640 identity = _register_identity (auth_service, "app_context_A", &error);
641 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
643 v_info = _create_identity_info_with_data ("user1", "caption1", 1, methods, mechanisms);
644 fail_if (v_info == NULL);
645 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
646 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
647 g_object_unref (identity);
649 identity = _get_identity (auth_service, id, "app_context_A", &v_info, &error);
650 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
651 g_object_unref (identity);
652 info1 = gsignond_identity_info_new_from_variant (v_info);
654 /* created identity2 */
655 identity = _register_identity (auth_service, "app_context_B", &error);
656 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
658 v_info = _create_identity_info_with_data ("user2", "caption2", 2, methods, mechanisms);
659 fail_if (v_info == NULL);
660 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
661 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
662 g_object_unref (identity);
664 identity = _get_identity (auth_service, id, "app_context_B", &v_info, &error);
665 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
666 g_object_unref (identity);
667 info2 = gsignond_identity_info_new_from_variant (v_info);
669 /* create identity3 */
670 identity = _register_identity (auth_service, "app_context_A", &error);
671 fail_if (identity == NULL, "Failed to register new identity : %s", error ? error->message : "");
673 v_info = _create_identity_info_with_data ("user2", "caption3", 2, methods, mechanisms);
674 fail_if (v_info == NULL);
675 res = gsignond_dbus_identity_call_store_sync (identity, v_info, &id, NULL, &error);
676 fail_if (res == FALSE || id == 0, "Failed to store identity : %s", error ? error->message : "");
677 g_object_unref (identity);
679 identity = _get_identity (auth_service, id, "app_context_A", &v_info, &error);
680 fail_if (identity == NULL || v_info == NULL, "Failed to load identity for id '%d' : %s", id, error ? error->message : "");
681 g_object_unref (identity);
682 info3 = gsignond_identity_info_new_from_variant (v_info);
684 /* query identities for app-context: app_context_A */
686 filter = gsignond_dictionary_new();
687 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
688 gsignond_dictionary_to_variant (filter),
689 "app_context_A", &v_identities, NULL, &error);
690 gsignond_dictionary_unref (filter);
691 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
692 "app context 'app_context_A' : %s",
693 error ? error->message : "");
694 fail_if (g_variant_n_children (v_identities) != 2,
695 "Expected no of identities '%d', got '%d'", 2,
696 g_variant_n_children(v_identities));
697 /* validated query results */
698 tmp_info = gsignond_identity_info_new_from_variant (
699 g_variant_get_child_value (v_identities, 0));
700 fail_if (gsignond_identity_info_compare (info1, tmp_info) == FALSE);
701 gsignond_identity_info_unref (tmp_info);
703 tmp_info = gsignond_identity_info_new_from_variant (
704 g_variant_get_child_value (v_identities, 1));
705 fail_if (gsignond_identity_info_compare (info3, tmp_info) == FALSE);
706 gsignond_identity_info_unref (tmp_info);
708 /* query identities for app-context: app_context_B, Identity type : 2 */
710 filter = gsignond_dictionary_new();
711 gsignond_dictionary_set_int32 (filter, "Type", 2);
712 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
713 gsignond_dictionary_to_variant (filter),
714 "app_context_B", &v_identities, NULL, &error);
715 gsignond_dictionary_unref (filter);
716 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
717 "app context 'app_context_B' and Type: 2 : %s",
718 error ? error->message : "");
719 /* validated query results */
720 fail_if (g_variant_n_children (v_identities) != 1,
721 "Expected no of identities '%d', got '%d'", 1,
722 g_variant_n_children(v_identities));
723 tmp_info = gsignond_identity_info_new_from_variant (
724 g_variant_get_child_value (v_identities, 0));
725 fail_if (gsignond_identity_info_compare (info2, tmp_info) == FALSE);
726 gsignond_identity_info_unref (tmp_info);
728 /* query identities for app-context: app_context_A, Caption: "cap*" */
730 filter = gsignond_dictionary_new();
731 gsignond_dictionary_set_string (filter, "Caption", "cap");
732 res = gsignond_dbus_auth_service_call_query_identities_sync (auth_service,
733 gsignond_dictionary_to_variant (filter),
734 "app_context_B", &v_identities, NULL, &error);
735 gsignond_dictionary_unref (filter);
736 fail_if (res == FALSE || !v_identities, "Failed to query identities for "
737 "app context 'app_context_A' : %s",
738 error ? error->message : "");
739 /* validated query results */
740 fail_if (g_variant_n_children (v_identities) != 1,
741 "Expected no of identities '%d', got '%d'", 1,
742 g_variant_n_children(v_identities));
743 tmp_info = gsignond_identity_info_new_from_variant (
744 g_variant_get_child_value (v_identities, 0));
745 fail_if (gsignond_identity_info_compare
746 (info2, tmp_info) == FALSE);
747 gsignond_identity_info_unref (tmp_info);
749 gsignond_identity_info_unref (info1);
750 gsignond_identity_info_unref (info2);
751 gsignond_identity_info_unref (info3);
753 g_object_unref (auth_service);
754 g_object_unref (connection);
758 Suite* daemon_suite (void)
760 Suite *s = suite_create ("Gsignon daemon");
762 TCase *tc = tcase_create ("Identity");
764 tcase_set_timeout(tc, 10);
765 tcase_add_unchecked_fixture (tc, setup_daemon, teardown_daemon);
767 tcase_add_test (tc, test_register_new_identity);
768 tcase_add_test (tc, test_register_new_identity_with_no_app_context);
769 tcase_add_test (tc, test_identity_store);
770 tcase_add_test (tc, test_identity_get_identity);
771 tcase_add_test (tc, test_clear_database);
772 tcase_add_test (tc, test_identity_signout);
773 tcase_add_test (tc, test_query_identities);
775 suite_add_tcase (s, tc);
780 int main (int argc, char *argv[])
786 #if !GLIB_CHECK_VERSION (2, 36, 0)
791 sr = srunner_create(s);
793 srunner_run_all(sr, CK_VERBOSE);
795 number_failed = srunner_ntests_failed(sr);
798 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;