2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2012-01-30 13:26:44 +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-06-28 11:15:06 +00:00
|
|
|
#include "secret-attributes.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"
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
#include "mock-service.h"
|
|
|
|
|
|
|
|
#include "egg/egg-testing.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
static const SecretSchema MOCK_SCHEMA = {
|
|
|
|
"org.mock.Schema",
|
2012-03-11 08:06:40 +00:00
|
|
|
SECRET_SCHEMA_NONE,
|
2012-01-30 13:26:44 +00:00
|
|
|
{
|
2012-03-11 08:06:40 +00:00
|
|
|
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
|
|
|
|
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
|
|
|
{ "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
static const SecretSchema PRIME_SCHEMA = {
|
|
|
|
"org.mock.Prime",
|
2012-03-11 08:06:40 +00:00
|
|
|
SECRET_SCHEMA_NONE,
|
2012-01-30 13:26:44 +00:00
|
|
|
{
|
2012-03-11 08:06:40 +00:00
|
|
|
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
|
|
|
|
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
2012-03-18 18:04:44 +00:00
|
|
|
{ "prime", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SecretSchema NO_NAME_SCHEMA = {
|
|
|
|
"unused.Schema.Name",
|
|
|
|
SECRET_SCHEMA_DONT_MATCH_NAME,
|
|
|
|
{
|
|
|
|
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
|
|
|
|
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-30 13:26:44 +00:00
|
|
|
} Test;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_mock (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *mock_script = data;
|
|
|
|
|
|
|
|
mock_service_start (mock_script, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup (Test *test,
|
|
|
|
gconstpointer data)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
setup_mock (test, data);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
teardown_mock (Test *test,
|
|
|
|
gconstpointer unused)
|
|
|
|
{
|
|
|
|
mock_service_stop ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
teardown (Test *test,
|
|
|
|
gconstpointer unused)
|
|
|
|
{
|
|
|
|
egg_test_wait_idle ();
|
|
|
|
|
|
|
|
g_object_unref (test->service);
|
|
|
|
egg_assert_not_object (test->service);
|
|
|
|
|
|
|
|
teardown_mock (test, unused);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_paths_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
gchar **locked;
|
|
|
|
gchar **unlocked;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&unlocked, &locked, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (unlocked);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
g_strfreev (locked);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_paths_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
gchar **locked;
|
|
|
|
gchar **unlocked;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search_for_paths (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
&unlocked, &locked,
|
|
|
|
&error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (unlocked);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
g_strfreev (locked);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_paths_nulls (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
gchar **paths;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&paths, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (paths != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &paths, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (paths != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search_for_paths (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
&paths, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (paths != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search_for_paths (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &paths, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (paths != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search_for_paths (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
GList *locked;
|
|
|
|
GList *unlocked;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&unlocked, &locked, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (locked->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (unlocked != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (unlocked->data), ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_list_free_full (unlocked, g_object_unref);
|
|
|
|
g_list_free_full (locked, g_object_unref);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
GList *locked;
|
|
|
|
GList *unlocked;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
&unlocked, &locked,
|
|
|
|
&error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (locked->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (unlocked != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (unlocked->data), ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_list_free_full (unlocked, g_object_unref);
|
|
|
|
g_list_free_full (locked, g_object_unref);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_search_nulls (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean ret;
|
|
|
|
GList *items;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "number", "1");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&items, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (items != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &items, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (items != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
&items, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (items != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/english/1");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &items, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_assert (items != NULL);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (items->data), ==, "/org/freedesktop/secrets/collection/spanish/10");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
egg_test_wait ();
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_finish (test->service, result,
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
g_clear_object (&result);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secret_for_path_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
const gchar *password;
|
|
|
|
gsize length;
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
path = "/org/freedesktop/secrets/collection/english/1";
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_service_get_secret_for_path_sync (test->service, path, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (value != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, NULL);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secret_for_path_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
const gchar *password;
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
gsize length;
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
path = "/org/freedesktop/secrets/collection/english/1";
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_secret_for_path (test->service, path, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_service_get_secret_for_path_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (value != NULL);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, NULL);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secrets_for_paths_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
|
|
|
|
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
path_item_one,
|
|
|
|
path_item_two,
|
|
|
|
|
|
|
|
/* This one is locked, and not returned */
|
2012-01-31 19:20:31 +00:00
|
|
|
"/org/freedesktop/secrets/collection/spanish/10",
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *values;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *password;
|
|
|
|
gsize length;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
values = secret_service_get_secrets_for_paths_sync (test->service, paths, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (values != NULL);
|
|
|
|
g_assert_cmpuint (g_hash_table_size (values), ==, 2);
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, path_item_one);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, path_item_two);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "222");
|
|
|
|
|
|
|
|
g_hash_table_unref (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secrets_for_paths_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
|
|
|
|
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
path_item_one,
|
|
|
|
path_item_two,
|
|
|
|
|
|
|
|
/* This one is locked, and not returned */
|
2012-01-31 19:20:31 +00:00
|
|
|
"/org/freedesktop/secrets/collection/spanish/10",
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *values;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *password;
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
gsize length;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_secrets_for_paths (test->service, paths, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
values = secret_service_get_secrets_for_paths_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_assert (values != NULL);
|
|
|
|
g_assert_cmpuint (g_hash_table_size (values), ==, 2);
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, path_item_one);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, path_item_two);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "222");
|
|
|
|
|
|
|
|
g_hash_table_unref (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secrets_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
|
|
|
|
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
|
|
|
|
const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *values;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *password;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item_one, *item_two, *item_three;
|
2012-01-30 13:26:44 +00:00
|
|
|
GList *items = NULL;
|
|
|
|
gsize length;
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
item_one = secret_item_new_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
|
|
|
|
item_two = secret_item_new_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
|
|
|
|
item_three = secret_item_new_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
items = g_list_append (items, item_one);
|
|
|
|
items = g_list_append (items, item_two);
|
|
|
|
items = g_list_append (items, item_three);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
values = secret_service_get_secrets_sync (test->service, items, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (values != NULL);
|
|
|
|
g_assert_cmpuint (g_hash_table_size (values), ==, 2);
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, item_one);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, item_two);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "222");
|
|
|
|
|
|
|
|
g_hash_table_unref (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_secrets_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
|
|
|
|
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
|
|
|
|
const gchar *path_item_three = "/org/freedesktop/secrets/collection/spanish/10";
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *values;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *password;
|
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item_one, *item_two, *item_three;
|
2012-01-30 13:26:44 +00:00
|
|
|
GList *items = NULL;
|
|
|
|
gsize length;
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
item_one = secret_item_new_sync (test->service, path_item_one, SECRET_ITEM_NONE, NULL, &error);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
item_two = secret_item_new_sync (test->service, path_item_two, SECRET_ITEM_NONE, NULL, &error);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
item_three = secret_item_new_sync (test->service, path_item_three, SECRET_ITEM_NONE, NULL, &error);
|
2012-01-31 19:20:31 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
items = g_list_append (items, item_one);
|
|
|
|
items = g_list_append (items, item_two);
|
|
|
|
items = g_list_append (items, item_three);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get_secrets (test->service, items, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
on_complete_get_result, &result);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
g_list_free (items);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
values = secret_service_get_secrets_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_assert (values != NULL);
|
|
|
|
g_assert_cmpuint (g_hash_table_size (values), ==, 2);
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, item_one);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "111");
|
|
|
|
|
|
|
|
value = g_hash_table_lookup (values, item_two);
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_value_get (value, &length);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
g_assert_cmpstr (password, ==, "222");
|
|
|
|
|
|
|
|
g_hash_table_unref (values);
|
|
|
|
|
|
|
|
g_object_unref (item_one);
|
|
|
|
g_object_unref (item_two);
|
|
|
|
g_object_unref (item_three);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_delete_for_path_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/item";
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_delete_for_path_sync_prompt (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/confirm";
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lock_paths_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
collection_path,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **locked = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked != NULL);
|
|
|
|
g_assert_cmpstr (locked[0], ==, collection_path);
|
|
|
|
g_assert (locked[1] == NULL);
|
|
|
|
g_strfreev (locked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lock_prompt_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
collection_path,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **locked = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked != NULL);
|
|
|
|
g_assert_cmpstr (locked[0], ==, collection_path);
|
|
|
|
g_assert (locked[1] == NULL);
|
|
|
|
g_strfreev (locked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lock_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GList *locked;
|
|
|
|
GList *objects;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collection = secret_collection_new_sync (test->service, collection_path, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
objects = g_list_append (NULL, collection);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_lock_sync (test->service, objects, NULL, &locked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (locked != NULL);
|
|
|
|
g_assert (locked->data == collection);
|
|
|
|
g_assert (locked->next == NULL);
|
|
|
|
g_list_free_full (locked, g_object_unref);
|
|
|
|
|
|
|
|
g_list_free (objects);
|
|
|
|
g_object_unref (collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_unlock_paths_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
collection_path,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **unlocked = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (unlocked != NULL);
|
|
|
|
g_assert_cmpstr (unlocked[0], ==, collection_path);
|
|
|
|
g_assert (unlocked[1] == NULL);
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_unlock_prompt_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
|
2012-01-30 13:26:44 +00:00
|
|
|
const gchar *paths[] = {
|
|
|
|
collection_path,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **unlocked = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (unlocked != NULL);
|
|
|
|
g_assert_cmpstr (unlocked[0], ==, collection_path);
|
|
|
|
g_assert (unlocked[1] == NULL);
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_unlock_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
2012-01-31 19:20:31 +00:00
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-30 13:26:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GList *unlocked;
|
|
|
|
GList *objects;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
collection = secret_collection_new_sync (test->service, collection_path, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
objects = g_list_append (NULL, collection);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_unlock_sync (test->service, objects, NULL, &unlocked, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (unlocked != NULL);
|
|
|
|
g_assert (unlocked->data == collection);
|
|
|
|
g_assert (unlocked->next == NULL);
|
|
|
|
g_list_free_full (unlocked, g_object_unref);
|
|
|
|
|
|
|
|
g_list_free (objects);
|
|
|
|
g_object_unref (collection);
|
|
|
|
}
|
|
|
|
|
2012-01-30 15:07:55 +00:00
|
|
|
static void
|
|
|
|
test_collection_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GHashTable *properties;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
|
2012-01-30 15:07:55 +00:00
|
|
|
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_collection_path_sync (test->service, properties,
|
2012-01-30 15:07:55 +00:00
|
|
|
NULL, NULL, &error);
|
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
g_assert (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_collection_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *properties;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
|
2012-01-30 15:07:55 +00:00
|
|
|
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_create_collection_path (test->service, properties,
|
2012-01-30 15:07:55 +00:00
|
|
|
NULL, NULL, on_complete_get_result, &result);
|
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_collection_path_finish (test->service, result, &error);
|
2012-01-30 15:07:55 +00:00
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
g_assert (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_item_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
|
|
|
|
GHashTable *properties;
|
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 15:07:55 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "even", "true");
|
|
|
|
g_hash_table_insert (attributes, "string", "ten");
|
|
|
|
g_hash_table_insert (attributes, "number", "10");
|
|
|
|
|
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
|
2012-01-30 15:07:55 +00:00
|
|
|
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
|
2012-06-28 11:15:06 +00:00
|
|
|
g_variant_ref_sink (_secret_attributes_to_variant (attributes, "org.gnome.Test")));
|
2012-01-30 15:07:55 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_value_new ("andmoreandmore", -1, "text/plain");
|
2012-01-30 15:07:55 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_item_path_sync (test->service, collection_path,
|
2012-01-30 15:07:55 +00:00
|
|
|
properties, value, FALSE,
|
|
|
|
NULL, &error);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 15:07:55 +00:00
|
|
|
g_hash_table_unref (properties);
|
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
g_assert (g_str_has_prefix (path, collection_path));
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_item_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
|
|
|
|
GHashTable *properties;
|
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 15:07:55 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "even", "true");
|
|
|
|
g_hash_table_insert (attributes, "string", "ten");
|
|
|
|
g_hash_table_insert (attributes, "number", "10");
|
|
|
|
|
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
|
2012-01-30 15:07:55 +00:00
|
|
|
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
|
2012-02-01 12:34:08 +00:00
|
|
|
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
|
2012-06-28 11:15:06 +00:00
|
|
|
g_variant_ref_sink (_secret_attributes_to_variant (attributes, NULL)));
|
2012-01-30 15:07:55 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_value_new ("andmoreandmore", -1, "text/plain");
|
2012-01-30 15:07:55 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_create_item_path (test->service, collection_path,
|
2012-01-30 15:07:55 +00:00
|
|
|
properties, value, FALSE,
|
|
|
|
NULL, on_complete_get_result, &result);
|
|
|
|
|
|
|
|
g_assert (result == NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 15:07:55 +00:00
|
|
|
g_hash_table_unref (properties);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_item_path_finish (test->service, result, &error);
|
2012-01-30 15:07:55 +00:00
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path != NULL);
|
|
|
|
g_assert (g_str_has_prefix (path, collection_path));
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
static void
|
|
|
|
test_remove_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-30 13:26:44 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "one",
|
|
|
|
"number", 1,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret = secret_service_remove_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
2012-06-28 11:15:06 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_remove_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GAsyncResult *result = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-30 13:26:44 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "one",
|
|
|
|
"number", 1,
|
|
|
|
NULL);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
secret_service_remove (test->service, &MOCK_SCHEMA, attributes, NULL,
|
|
|
|
on_complete_get_result, &result);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert (result == NULL);
|
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_remove_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_object_unref (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_remove_locked (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-30 13:26:44 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "tres",
|
|
|
|
"number", 3,
|
|
|
|
NULL);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
ret = secret_service_remove_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_remove_no_match (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-30 13:26:44 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", TRUE,
|
|
|
|
"string", "one",
|
|
|
|
NULL);
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
/* Won't match anything */
|
2012-06-28 11:15:06 +00:00
|
|
|
ret = secret_service_remove_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == FALSE);
|
|
|
|
}
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
static void
|
|
|
|
test_remove_no_name (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-03-18 18:04:44 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"number", 5,
|
|
|
|
NULL);
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
/* Shouldn't match anything, because no item with 5 in mock schema */
|
2012-06-28 11:15:06 +00:00
|
|
|
ret = secret_service_remove_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-03-18 18:04:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == FALSE);
|
|
|
|
|
|
|
|
/* We have an item with 5 in prime schema, but should match anyway becase of flags */
|
2012-06-28 11:15:06 +00:00
|
|
|
ret = secret_service_remove_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
|
2012-03-18 18:04:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
2012-06-28 11:15:06 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
2012-03-18 18:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
static void
|
|
|
|
test_lookup_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "one",
|
|
|
|
"number", 1,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert_no_error (error);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lookup_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-30 13:26:44 +00:00
|
|
|
GAsyncResult *result = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "one",
|
|
|
|
"number", 1,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
secret_service_lookup (test->service, &MOCK_SCHEMA, attributes, NULL,
|
|
|
|
on_complete_get_result, &result);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (result == NULL);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_service_lookup_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "111");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_object_unref (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lookup_locked (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "tres",
|
|
|
|
"number", 3,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert_no_error (error);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "3333");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 4);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_lookup_no_match (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-30 13:26:44 +00:00
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", TRUE,
|
|
|
|
"string", "one",
|
|
|
|
NULL);
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
/* Won't match anything */
|
2012-06-28 11:15:06 +00:00
|
|
|
value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (value == NULL);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
static void
|
|
|
|
test_lookup_no_name (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes;
|
2012-03-18 18:04:44 +00:00
|
|
|
SecretValue *value;
|
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"number", 5,
|
|
|
|
NULL);
|
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
/* should return null, because nothing with mock schema and 5 */
|
2012-06-28 11:15:06 +00:00
|
|
|
value = secret_service_lookup_sync (test->service, &MOCK_SCHEMA, attributes, NULL, &error);
|
2012-03-18 18:04:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (value == NULL);
|
|
|
|
|
|
|
|
/* should return an item, because we have a prime schema with 5, and flags not to match name */
|
2012-06-28 11:15:06 +00:00
|
|
|
value = secret_service_lookup_sync (test->service, &NO_NAME_SCHEMA, attributes, NULL, &error);
|
2012-03-18 18:04:44 +00:00
|
|
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (value != NULL);
|
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "555");
|
|
|
|
g_assert_cmpuint (length, ==, 3);
|
|
|
|
|
|
|
|
secret_value_unref (value);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-03-18 18:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
static void
|
|
|
|
test_store_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *attributes;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **paths;
|
|
|
|
gboolean ret;
|
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "seventeen",
|
|
|
|
"number", 17,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
|
|
|
|
"New Item Label", value, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "even", "false");
|
|
|
|
g_hash_table_insert (attributes, "string", "seventeen");
|
|
|
|
g_hash_table_insert (attributes, "number", "17");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&paths, NULL, &error);
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (paths != NULL);
|
|
|
|
g_assert (paths[0] != NULL);
|
|
|
|
g_assert (paths[1] == NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_service_get_secret_for_path_sync (test->service, paths[0],
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 9);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_store_replace (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
|
2012-01-30 13:26:44 +00:00
|
|
|
GHashTable *attributes;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **paths;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "seventeen",
|
|
|
|
"number", 17,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
|
|
|
|
"New Item Label", value, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
ret = secret_service_store_sync (test->service, &MOCK_SCHEMA, attributes, collection_path,
|
|
|
|
"Another Label", value, NULL, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "even", "false");
|
|
|
|
g_hash_table_insert (attributes, "string", "seventeen");
|
|
|
|
g_hash_table_insert (attributes, "number", "17");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&paths, NULL, &error);
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (paths != NULL);
|
|
|
|
g_assert (paths[0] != NULL);
|
|
|
|
g_assert (paths[1] == NULL);
|
|
|
|
|
|
|
|
g_strfreev (paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_store_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value = secret_value_new ("apassword", -1, "text/plain");
|
2012-01-30 13:26:44 +00:00
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GHashTable *attributes;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar **paths;
|
|
|
|
gboolean ret;
|
|
|
|
gsize length;
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = secret_attributes_build (&MOCK_SCHEMA,
|
|
|
|
"even", FALSE,
|
|
|
|
"string", "seventeen",
|
|
|
|
"number", 17,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
secret_service_store (test->service, &MOCK_SCHEMA, attributes, collection_path,
|
|
|
|
"New Item Label", value, NULL, on_complete_get_result, &result);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert (result == NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-06-28 11:15:06 +00:00
|
|
|
g_hash_table_unref (attributes);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
egg_test_wait ();
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_store_finish (test->service, result, &error);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
g_hash_table_insert (attributes, "even", "false");
|
|
|
|
g_hash_table_insert (attributes, "string", "seventeen");
|
|
|
|
g_hash_table_insert (attributes, "number", "17");
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
|
2012-01-30 13:26:44 +00:00
|
|
|
&paths, NULL, &error);
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
g_assert (paths != NULL);
|
|
|
|
g_assert (paths[0] != NULL);
|
|
|
|
g_assert (paths[1] == NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
value = secret_service_get_secret_for_path_sync (test->service, paths[0],
|
2012-01-30 13:26:44 +00:00
|
|
|
NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
g_assert (value != NULL);
|
2012-02-01 12:34:08 +00:00
|
|
|
g_assert_cmpstr (secret_value_get (value, &length), ==, "apassword");
|
2012-01-30 13:26:44 +00:00
|
|
|
g_assert_cmpuint (length, ==, 9);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (value);
|
2012-01-30 13:26:44 +00:00
|
|
|
g_strfreev (paths);
|
|
|
|
}
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
static void
|
|
|
|
test_read_alias_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path;
|
|
|
|
SecretCollection *collection;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
collection = secret_service_read_alias_sync (test->service, "default", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
|
|
|
g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
|
|
|
|
g_object_unref (collection);
|
|
|
|
|
|
|
|
collection = secret_service_read_alias_sync (test->service, "unknown", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (collection == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_read_alias_async (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
const gchar *collection_path;
|
|
|
|
SecretCollection *collection;
|
|
|
|
GAsyncResult *result = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
secret_service_read_alias (test->service, "default", NULL,
|
|
|
|
on_complete_get_result, &result);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
|
|
|
collection = secret_service_read_alias_finish (test->service, result, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_object_unref (result);
|
|
|
|
|
|
|
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
|
|
|
g_assert_cmpstr (collection_path, ==, "/org/freedesktop/secrets/collection/english");
|
|
|
|
g_object_unref (collection);
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
secret_service_read_alias (test->service, "unknown", NULL,
|
|
|
|
on_complete_get_result, &result);
|
|
|
|
g_assert (result == NULL);
|
|
|
|
egg_test_wait ();
|
|
|
|
|
|
|
|
collection = secret_service_read_alias_finish (test->service, result, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (collection == NULL);
|
|
|
|
g_object_unref (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_set_alias_sync (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
SecretCollection *collection;
|
|
|
|
SecretCollection *blah;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
blah = secret_service_read_alias_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (blah == NULL);
|
|
|
|
|
|
|
|
collection = secret_collection_new_sync (test->service, "/org/freedesktop/secrets/collection/english", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (SECRET_IS_COLLECTION (collection));
|
|
|
|
|
|
|
|
ret = secret_service_set_alias_sync (test->service, "blah", collection, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
blah = secret_service_read_alias_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert_cmpstr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (blah)), ==, g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)));
|
|
|
|
g_object_unref (blah);
|
|
|
|
|
|
|
|
ret = secret_service_set_alias_sync (test->service, "blah", NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
blah = secret_service_read_alias_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (blah == NULL);
|
|
|
|
|
|
|
|
g_object_unref (collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_set_alias_path (Test *test,
|
|
|
|
gconstpointer used)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
path = secret_service_read_alias_path_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path == NULL);
|
|
|
|
|
|
|
|
ret = secret_service_set_alias_path_sync (test->service, "blah", "/org/freedesktop/secrets/collection/english", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
path = secret_service_read_alias_path_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert_cmpstr (path, ==, "/org/freedesktop/secrets/collection/english");
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
ret = secret_service_set_alias_path_sync (test->service, "blah", NULL, NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (ret == TRUE);
|
|
|
|
|
|
|
|
path = secret_service_read_alias_path_sync (test->service, "blah", NULL, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
g_assert (path == NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
g_set_prgname ("test-service");
|
|
|
|
g_type_init ();
|
|
|
|
|
|
|
|
g_test_add ("/service/search-for-paths", Test, "mock-service-normal.py", setup, test_search_paths_sync, teardown);
|
|
|
|
g_test_add ("/service/search-for-paths-async", Test, "mock-service-normal.py", setup, test_search_paths_async, teardown);
|
|
|
|
g_test_add ("/service/search-for-paths-nulls", Test, "mock-service-normal.py", setup, test_search_paths_nulls, teardown);
|
|
|
|
g_test_add ("/service/search-sync", Test, "mock-service-normal.py", setup, test_search_sync, teardown);
|
|
|
|
g_test_add ("/service/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown);
|
|
|
|
g_test_add ("/service/search-nulls", Test, "mock-service-normal.py", setup, test_search_nulls, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/secret-for-path-sync", Test, "mock-service-normal.py", setup, test_secret_for_path_sync, teardown);
|
|
|
|
g_test_add ("/service/secret-for-path-plain", Test, "mock-service-only-plain.py", setup, test_secret_for_path_sync, teardown);
|
|
|
|
g_test_add ("/service/secret-for-path-async", Test, "mock-service-normal.py", setup, test_secret_for_path_async, teardown);
|
|
|
|
g_test_add ("/service/secrets-for-paths-sync", Test, "mock-service-normal.py", setup, test_secrets_for_paths_sync, teardown);
|
|
|
|
g_test_add ("/service/secrets-for-paths-async", Test, "mock-service-normal.py", setup, test_secrets_for_paths_async, teardown);
|
|
|
|
g_test_add ("/service/secrets-sync", Test, "mock-service-normal.py", setup, test_secrets_sync, teardown);
|
|
|
|
g_test_add ("/service/secrets-async", Test, "mock-service-normal.py", setup, test_secrets_async, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/delete-for-path", Test, "mock-service-delete.py", setup, test_delete_for_path_sync, teardown);
|
|
|
|
g_test_add ("/service/delete-for-path-with-prompt", Test, "mock-service-delete.py", setup, test_delete_for_path_sync_prompt, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/lock-paths-sync", Test, "mock-service-lock.py", setup, test_lock_paths_sync, teardown);
|
|
|
|
g_test_add ("/service/lock-prompt-sync", Test, "mock-service-lock.py", setup, test_lock_prompt_sync, teardown);
|
|
|
|
g_test_add ("/service/lock-sync", Test, "mock-service-lock.py", setup, test_lock_sync, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/unlock-paths-sync", Test, "mock-service-lock.py", setup, test_unlock_paths_sync, teardown);
|
|
|
|
g_test_add ("/service/unlock-prompt-sync", Test, "mock-service-lock.py", setup, test_unlock_prompt_sync, teardown);
|
|
|
|
g_test_add ("/service/unlock-sync", Test, "mock-service-lock.py", setup, test_unlock_sync, teardown);
|
|
|
|
|
2012-01-30 15:07:55 +00:00
|
|
|
g_test_add ("/service/create-collection-sync", Test, "mock-service-normal.py", setup, test_collection_sync, teardown);
|
|
|
|
g_test_add ("/service/create-collection-async", Test, "mock-service-normal.py", setup, test_collection_async, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/create-item-sync", Test, "mock-service-normal.py", setup, test_item_sync, teardown);
|
|
|
|
g_test_add ("/service/create-item-async", Test, "mock-service-normal.py", setup, test_item_async, teardown);
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
g_test_add ("/service/lookup-sync", Test, "mock-service-normal.py", setup, test_lookup_sync, teardown);
|
|
|
|
g_test_add ("/service/lookup-async", Test, "mock-service-normal.py", setup, test_lookup_async, teardown);
|
|
|
|
g_test_add ("/service/lookup-locked", Test, "mock-service-normal.py", setup, test_lookup_locked, teardown);
|
|
|
|
g_test_add ("/service/lookup-no-match", Test, "mock-service-normal.py", setup, test_lookup_no_match, teardown);
|
2012-03-18 18:04:44 +00:00
|
|
|
g_test_add ("/service/lookup-no-name", Test, "mock-service-normal.py", setup, test_lookup_no_name, teardown);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_test_add ("/service/remove-sync", Test, "mock-service-delete.py", setup, test_remove_sync, teardown);
|
|
|
|
g_test_add ("/service/remove-async", Test, "mock-service-delete.py", setup, test_remove_async, teardown);
|
|
|
|
g_test_add ("/service/remove-locked", Test, "mock-service-delete.py", setup, test_remove_locked, teardown);
|
|
|
|
g_test_add ("/service/remove-no-match", Test, "mock-service-delete.py", setup, test_remove_no_match, teardown);
|
2012-03-18 18:04:44 +00:00
|
|
|
g_test_add ("/service/remove-no-name", Test, "mock-service-delete.py", setup, test_remove_no_name, teardown);
|
2012-01-30 13:26:44 +00:00
|
|
|
|
|
|
|
g_test_add ("/service/store-sync", Test, "mock-service-normal.py", setup, test_store_sync, teardown);
|
|
|
|
g_test_add ("/service/store-async", Test, "mock-service-normal.py", setup, test_store_async, teardown);
|
|
|
|
g_test_add ("/service/store-replace", Test, "mock-service-normal.py", setup, test_store_replace, teardown);
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
g_test_add ("/service/read-alias-sync", Test, "mock-service-normal.py", setup, test_read_alias_sync, teardown);
|
|
|
|
g_test_add ("/service/read-alias-async", Test, "mock-service-normal.py", setup, test_read_alias_async, teardown);
|
|
|
|
|
|
|
|
g_test_add ("/service/set-alias-sync", Test, "mock-service-normal.py", setup, test_set_alias_sync, teardown);
|
|
|
|
g_test_add ("/service/set-alias-path", Test, "mock-service-normal.py", setup, test_set_alias_path, teardown);
|
|
|
|
|
2012-01-30 13:26:44 +00:00
|
|
|
return egg_tests_run_with_loop ();
|
|
|
|
}
|