2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2011-11-05 20:50:01 +00:00
|
|
|
*
|
|
|
|
* Copyright 2011 Collabora Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-item.h"
|
|
|
|
#include "secret-service.h"
|
|
|
|
#include "secret-private.h"
|
2011-11-05 20:50:01 +00:00
|
|
|
|
2012-01-23 08:36:36 +00:00
|
|
|
#include "mock-service.h"
|
|
|
|
|
2011-11-05 20:50:01 +00:00
|
|
|
#include "egg/egg-testing.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
typedef struct {
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2011-11-05 20:50:01 +00:00
|
|
|
} Test;
|
|
|
|
|
|
|
|
static void
|
2012-01-11 06:44:32 +00:00
|
|
|
setup_mock (Test *test,
|
|
|
|
gconstpointer data)
|
2011-11-05 20:50:01 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *mock_script = data;
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-23 08:36:36 +00:00
|
|
|
mock_service_start (mock_script, &error);
|
2011-11-05 20:50:01 +00:00
|
|
|
g_assert_no_error (error);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
teardown_mock (Test *test,
|
|
|
|
gconstpointer unused)
|
|
|
|
{
|
2012-01-23 08:36:36 +00:00
|
|
|
mock_service_stop ();
|
2011-11-05 20:50:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 21:46:30 +00:00
|
|
|
static void
|
|
|
|
on_complete_get_result (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GAsyncResult **ret = user_data;
|
|
|
|
g_assert (ret != NULL);
|
|
|
|
g_assert (*ret == NULL);
|
|
|
|
*ret = g_object_ref (result);
|
|
|
|
egg_test_wait_stop ();
|
|
|
|
}
|
|
|
|
|
2011-11-06 07:59:20 +00:00
|
|
|
static void
|
2012-01-26 13:34:37 +00:00
|
|
|
test_get_sync (void)
|
2011-11-06 07:59:20 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service1;
|
|
|
|
SecretService *service2;
|
|
|
|
SecretService *service3;
|
2011-11-06 07:59:20 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* Both these sohuld point to the same thing */
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service1 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-25 13:26:52 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service2 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-25 13:26:52 +00:00
|
|
|
g_assert_no_error (error);
|
2011-11-06 07:59:20 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service1));
|
2011-11-06 07:59:20 +00:00
|
|
|
g_assert (service1 == service2);
|
|
|
|
|
|
|
|
g_object_unref (service1);
|
2011-11-06 12:41:21 +00:00
|
|
|
g_assert (G_IS_OBJECT (service1));
|
2011-11-06 07:59:20 +00:00
|
|
|
|
|
|
|
g_object_unref (service2);
|
2011-11-06 12:41:21 +00:00
|
|
|
egg_assert_not_object (service2);
|
2011-11-06 07:59:20 +00:00
|
|
|
|
|
|
|
/* Services were unreffed, so this should create a new one */
|
2012-02-01 12:34:08 +00:00
|
|
|
service3 = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
|
|
|
|
g_assert (SECRET_IS_SERVICE (service3));
|
2012-01-25 13:26:52 +00:00
|
|
|
g_assert_no_error (error);
|
2011-11-06 07:59:20 +00:00
|
|
|
|
|
|
|
g_object_unref (service3);
|
2011-11-06 12:41:21 +00:00
|
|
|
egg_assert_not_object (service3);
|
2011-11-06 07:59:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 13:34:37 +00:00
|
|
|
static void
|
|
|
|
test_get_async (void)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service1;
|
|
|
|
SecretService *service2;
|
|
|
|
SecretService *service3;
|
2012-01-26 13:34:37 +00:00
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* Both these sohuld point to the same thing */
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
2012-02-01 12:34:08 +00:00
|
|
|
service1 = secret_service_get_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
2012-02-01 12:34:08 +00:00
|
|
|
service2 = secret_service_get_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service1));
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (service1 == service2);
|
|
|
|
|
|
|
|
g_object_unref (service1);
|
|
|
|
g_assert (G_IS_OBJECT (service1));
|
|
|
|
|
|
|
|
g_object_unref (service2);
|
|
|
|
egg_assert_not_object (service2);
|
|
|
|
|
|
|
|
/* Services were unreffed, so this should create a new one */
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
2012-02-01 12:34:08 +00:00
|
|
|
service3 = secret_service_get_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
|
|
|
g_object_unref (service3);
|
|
|
|
egg_assert_not_object (service3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_get_more_sync (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
|
|
|
SecretService *service2;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
GList *collections;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_NONE);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service2 = secret_service_get_sync (SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (service == service2);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
|
|
|
|
|
|
|
g_object_unref (service2);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service2 = secret_service_get_sync (SECRET_SERVICE_OPEN_SESSION, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path != NULL);
|
|
|
|
|
|
|
|
g_object_unref (service2);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_get_more_async (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
GList *collections;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
result = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
|
|
|
|
/* Now get a session with just collections */
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_LOAD_COLLECTIONS, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path == NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_new_sync (void)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service1;
|
|
|
|
SecretService *service2;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* Both these sohuld point to different things */
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
service1 = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
service2 = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service1));
|
|
|
|
g_assert (SECRET_IS_SERVICE (service2));
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (service1 != service2);
|
|
|
|
|
|
|
|
g_object_unref (service1);
|
|
|
|
egg_assert_not_object (service1);
|
|
|
|
|
|
|
|
g_object_unref (service2);
|
|
|
|
egg_assert_not_object (service2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_new_async (void)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service1;
|
|
|
|
SecretService *service2;
|
2012-01-26 13:34:37 +00:00
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* Both these sohuld point to different things */
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
|
|
|
|
NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
2012-02-01 12:34:08 +00:00
|
|
|
service1 = secret_service_new_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE, NULL,
|
|
|
|
on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
2012-02-01 12:34:08 +00:00
|
|
|
service2 = secret_service_new_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service1));
|
|
|
|
g_assert (SECRET_IS_SERVICE (service2));
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (service1 != service2);
|
|
|
|
|
|
|
|
g_object_unref (service1);
|
|
|
|
egg_assert_not_object (service1);
|
|
|
|
|
|
|
|
g_object_unref (service2);
|
|
|
|
egg_assert_not_object (service2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_new_more_sync (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
GList *collections;
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
|
|
|
|
NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_NONE);
|
|
|
|
g_assert (secret_service_get_collections (service) == NULL);
|
|
|
|
g_assert (secret_service_get_session_path (service) == NULL);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (secret_service_get_session_path (service) == NULL);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_OPEN_SESSION, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION);
|
|
|
|
g_assert (secret_service_get_collections (service) == NULL);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path != NULL);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_new_more_async (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
GList *collections;
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_new_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
result = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
|
|
|
|
/* Now get a session with just collections */
|
|
|
|
|
2012-06-27 09:45:09 +00:00
|
|
|
secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_LOAD_COLLECTIONS,
|
|
|
|
NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_new_finish (result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (secret_service_get_flags (service), ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (path == NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collections = secret_service_get_collections (service);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (collections != NULL);
|
|
|
|
g_list_free_full (collections, g_object_unref);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
static void
|
2012-01-25 13:26:52 +00:00
|
|
|
test_connect_async (Test *test,
|
|
|
|
gconstpointer used)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-11 06:44:32 +00:00
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
/* Passing false, not session */
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert (path == NULL);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-25 13:26:52 +00:00
|
|
|
test_connect_ensure_async (Test *test,
|
|
|
|
gconstpointer used)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-11 06:44:32 +00:00
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
/* Passing true, ensures session is established */
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert (SECRET_IS_SERVICE (service));
|
2012-01-11 06:44:32 +00:00
|
|
|
g_object_unref (result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_get_session_path (service);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_assert (path != NULL);
|
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
2011-11-05 20:50:01 +00:00
|
|
|
static void
|
2012-01-26 13:34:37 +00:00
|
|
|
test_ensure_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
|
|
|
SecretServiceFlags flags;
|
2012-01-26 13:34:37 +00:00
|
|
|
const gchar *path;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
/* Passing true, ensures session is established */
|
2012-06-27 09:45:09 +00:00
|
|
|
service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (service != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
flags = secret_service_get_flags (service);
|
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_NONE);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_ensure_collections_sync (service, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_object_get (service, "flags", &flags, NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_ensure_session_sync (service, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
flags = secret_service_get_flags (service);
|
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_ensure_async (Test *test,
|
2011-11-05 20:50:01 +00:00
|
|
|
gconstpointer used)
|
2012-01-26 13:34:37 +00:00
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretServiceFlags flags;
|
|
|
|
SecretService *service;
|
2012-01-26 13:34:37 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
/* Passing true, ensures session is established */
|
2012-06-27 09:45:09 +00:00
|
|
|
service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
|
|
|
|
SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (service != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
flags = secret_service_get_flags (service);
|
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_NONE);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_collections (service, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_ensure_collections_finish (service, result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_object_unref (result);
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
g_object_get (service, "flags", &flags, NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_LOAD_COLLECTIONS);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (service, NULL, on_complete_get_result, &result);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_ensure_session_finish (service, result, &error);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
g_object_unref (result);
|
|
|
|
result = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
flags = secret_service_get_flags (service);
|
|
|
|
g_assert_cmpuint (flags, ==, SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS);
|
2012-01-26 13:34:37 +00:00
|
|
|
|
|
|
|
g_object_unref (service);
|
|
|
|
egg_assert_not_object (service);
|
|
|
|
}
|
|
|
|
|
2011-11-05 20:50:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
g_set_prgname ("test-service");
|
|
|
|
g_type_init ();
|
|
|
|
|
2012-01-26 13:34:37 +00:00
|
|
|
g_test_add_func ("/service/get-sync", test_get_sync);
|
|
|
|
g_test_add_func ("/service/get-async", test_get_async);
|
|
|
|
g_test_add ("/service/get-more-sync", Test, "mock-service-normal.py", setup_mock, test_get_more_sync, teardown_mock);
|
|
|
|
g_test_add ("/service/get-more-async", Test, "mock-service-normal.py", setup_mock, test_get_more_async, teardown_mock);
|
|
|
|
|
|
|
|
g_test_add_func ("/service/new-sync", test_new_sync);
|
|
|
|
g_test_add_func ("/service/new-async", test_new_async);
|
|
|
|
g_test_add ("/service/new-more-sync", Test, "mock-service-normal.py", setup_mock, test_new_more_sync, teardown_mock);
|
|
|
|
g_test_add ("/service/new-more-async", Test, "mock-service-normal.py", setup_mock, test_new_more_async, teardown_mock);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_test_add ("/service/connect-sync", Test, "mock-service-normal.py", setup_mock, test_connect_async, teardown_mock);
|
|
|
|
g_test_add ("/service/connect-ensure-sync", Test, "mock-service-normal.py", setup_mock, test_connect_ensure_async, teardown_mock);
|
2012-01-26 13:34:37 +00:00
|
|
|
g_test_add ("/service/ensure-sync", Test, "mock-service-normal.py", setup_mock, test_ensure_sync, teardown_mock);
|
|
|
|
g_test_add ("/service/ensure-async", Test, "mock-service-normal.py", setup_mock, test_ensure_async, teardown_mock);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2011-11-06 12:38:19 +00:00
|
|
|
return egg_tests_run_with_loop ();
|
2011-11-05 20:50:01 +00:00
|
|
|
}
|