Separate path based functionality

* Move the dbus object path based functionality into its
   own file and own section of the documentation.
This commit is contained in:
Stef Walter 2012-07-05 16:41:28 +02:00
parent 6f4a53f08b
commit f962662b09
15 changed files with 3077 additions and 2630 deletions

View File

@ -30,6 +30,7 @@
<xi:include href="xml/secret-attributes.xml"/>
<xi:include href="xml/secret-prompt.xml"/>
<xi:include href="xml/secret-error.xml"/>
<xi:include href="xml/secret-paths.xml"/>
</part>
<xi:include href="xml/annotation-glossary.xml">

View File

@ -186,30 +186,15 @@ secret_service_ensure_collections_sync
secret_service_search
secret_service_search_finish
secret_service_search_sync
secret_service_search_for_paths
secret_service_search_for_paths_finish
secret_service_search_for_paths_sync
secret_service_get_secrets
secret_service_get_secrets_finish
secret_service_get_secrets_sync
secret_service_get_secrets_for_paths
secret_service_get_secrets_for_paths_finish
secret_service_get_secrets_for_paths_sync
secret_service_get_secret_for_path
secret_service_get_secret_for_path_finish
secret_service_get_secret_for_path_sync
secret_service_lock
secret_service_lock_finish
secret_service_lock_sync
secret_service_lock_paths
secret_service_lock_paths_finish
secret_service_lock_paths_sync
secret_service_unlock
secret_service_unlock_finish
secret_service_unlock_sync
secret_service_unlock_paths
secret_service_unlock_paths_finish
secret_service_unlock_paths_sync
secret_service_store
secret_service_store_finish
secret_service_store_sync
@ -222,6 +207,43 @@ secret_service_remove_sync
secret_service_prompt
secret_service_prompt_finish
secret_service_prompt_sync
secret_service_read_alias
secret_service_read_alias_finish
secret_service_read_alias_sync
secret_service_set_alias
secret_service_set_alias_finish
secret_service_set_alias_sync
<SUBSECTION Standard>
SECRET_IS_SERVICE
SECRET_IS_SERVICE_CLASS
SECRET_SERVICE
SECRET_SERVICE_CLASS
SECRET_SERVICE_GET_CLASS
SECRET_TYPE_SERVICE
SECRET_TYPE_SERVICE_FLAGS
SecretServicePrivate
secret_service_flags_get_type
secret_service_get_type
</SECTION>
<SECTION>
<FILE>secret-paths</FILE>
<INCLUDE>secret/secret-unstable.h</INCLUDE>
secret_service_search_for_paths
secret_service_search_for_paths_finish
secret_service_search_for_paths_sync
secret_service_get_secrets_for_paths
secret_service_get_secrets_for_paths_finish
secret_service_get_secrets_for_paths_sync
secret_service_get_secret_for_path
secret_service_get_secret_for_path_finish
secret_service_get_secret_for_path_sync
secret_service_lock_paths
secret_service_lock_paths_finish
secret_service_lock_paths_sync
secret_service_unlock_paths
secret_service_unlock_paths_finish
secret_service_unlock_paths_sync
secret_service_prompt_path
secret_service_prompt_path_finish
secret_service_prompt_path_sync
@ -234,29 +256,12 @@ secret_service_create_item_path_sync
secret_service_delete_path
secret_service_delete_path_finish
secret_service_delete_path_sync
secret_service_read_alias
secret_service_read_alias_finish
secret_service_read_alias_sync
secret_service_read_alias_path
secret_service_read_alias_path_finish
secret_service_read_alias_path_sync
secret_service_set_alias
secret_service_set_alias_finish
secret_service_set_alias_sync
secret_service_set_alias_path
secret_service_set_alias_path_finish
secret_service_set_alias_path_sync
<SUBSECTION Standard>
SECRET_IS_SERVICE
SECRET_IS_SERVICE_CLASS
SECRET_SERVICE
SECRET_SERVICE_CLASS
SECRET_SERVICE_GET_CLASS
SECRET_TYPE_SERVICE
SECRET_TYPE_SERVICE_FLAGS
SecretServicePrivate
secret_service_flags_get_type
secret_service_get_type
</SECTION>
<SECTION>

View File

@ -26,6 +26,7 @@ HEADER_FILES = \
secret-collection.h \
secret-item.h \
secret-password.h \
secret-paths.h \
secret-prompt.h \
secret-schema.h \
secret-schemas.h \
@ -51,6 +52,7 @@ PUBLIC_FILES = \
secret-item.h secret-item.c \
secret-methods.c \
secret-password.h secret-password.c \
secret-paths.h secret-paths.c \
secret-prompt.h secret-prompt.c \
secret-schema.h secret-schema.c \
secret-schemas.h secret-schemas.c \

View File

@ -17,6 +17,7 @@
#include "secret-collection.h"
#include "secret-dbus-generated.h"
#include "secret-item.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-service.h"
#include "secret-types.h"

View File

@ -18,6 +18,7 @@
#include "secret-dbus-generated.h"
#include "secret-enum-types.h"
#include "secret-item.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-service.h"
#include "secret-types.h"

File diff suppressed because it is too large Load Diff

2054
library/secret-paths.c Normal file

File diff suppressed because it is too large Load Diff

219
library/secret-paths.h Normal file
View File

@ -0,0 +1,219 @@
/* libsecret - GLib wrapper for Secret Service
*
* Copyright 2011 Collabora Ltd.
* Copyright 2012 Red Hat Inc.
*
* 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.1 of the licence or (at
* your option) any later version.
*
* See the included COPYING file for more information.
*
* Author: Stef Walter <stefw@gnome.org>
*/
#if !defined (__SECRET_INSIDE_HEADER__) && !defined (SECRET_COMPILATION)
#error "Only <secret/secret.h> or <secret/secret-unstable.h> can be included directly."
#endif
#ifndef __SECRET_PATHS_H__
#define __SECRET_PATHS_H__
#include <gio/gio.h>
#include "secret-prompt.h"
#include "secret-schema.h"
#include "secret-types.h"
#include "secret-value.h"
G_BEGIN_DECLS
void secret_service_search_for_paths (SecretService *self,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_search_for_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***unlocked,
gchar ***locked,
GError **error);
gboolean secret_service_search_for_paths_sync (SecretService *self,
GHashTable *attributes,
GCancellable *cancellable,
gchar ***unlocked,
gchar ***locked,
GError **error);
void secret_service_get_secret_for_path (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
SecretValue * secret_service_get_secret_for_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
SecretValue * secret_service_get_secret_for_path_sync (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GError **error);
void secret_service_get_secrets_for_paths (SecretService *self,
const gchar **item_paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GHashTable * secret_service_get_secrets_for_paths_finish (SecretService *self,
GAsyncResult *result,
GError **error);
GHashTable * secret_service_get_secrets_for_paths_sync (SecretService *self,
const gchar **item_paths,
GCancellable *cancellable,
GError **error);
gint secret_service_lock_paths_sync (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
gchar ***locked,
GError **error);
void secret_service_lock_paths (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gint secret_service_lock_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***locked,
GError **error);
gint secret_service_unlock_paths_sync (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
gchar ***unlocked,
GError **error);
void secret_service_unlock_paths (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gint secret_service_unlock_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***unlocked,
GError **error);
GVariant * secret_service_prompt_path_sync (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
const GVariantType *return_type,
GError **error);
void secret_service_prompt_path (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GVariant * secret_service_prompt_path_finish (SecretService *self,
GAsyncResult *result,
const GVariantType *return_type,
GError **error);
void secret_service_delete_path (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_delete_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gboolean secret_service_delete_path_sync (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GError **error);
void secret_service_create_collection_path (SecretService *self,
GHashTable *properties,
const gchar *alias,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_create_collection_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_create_collection_path_sync (SecretService *self,
GHashTable *properties,
const gchar *alias,
GCancellable *cancellable,
GError **error);
void secret_service_create_item_path (SecretService *self,
const gchar *collection_path,
GHashTable *properties,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_create_item_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_create_item_path_sync (SecretService *self,
const gchar *collection_path,
GHashTable *properties,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
GError **error);
void secret_service_read_alias_path (SecretService *self,
const gchar *alias,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_read_alias_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_read_alias_path_sync (SecretService *self,
const gchar *alias,
GCancellable *cancellable,
GError **error);
void secret_service_set_alias_path (SecretService *self,
const gchar *alias,
const gchar *collection_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_set_alias_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gboolean secret_service_set_alias_path_sync (SecretService *self,
const gchar *alias,
const gchar *collection_path,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* __SECRET_SERVICE_H___ */

View File

@ -139,6 +139,12 @@ SecretItem * _secret_service_find_item_instance (SecretService *se
SecretCollection * _secret_service_find_collection_instance (SecretService *self,
const gchar *collection_path);
SecretValue * _secret_service_decode_get_secrets_first (SecretService *self,
GVariant *out);
GHashTable * _secret_service_decode_get_secrets_all (SecretService *self,
GVariant *out);
SecretItem * _secret_collection_find_item_instance (SecretCollection *self,
const gchar *item_path);

View File

@ -19,6 +19,7 @@
#include "secret-dbus-generated.h"
#include "secret-enum-types.h"
#include "secret-item.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-service.h"
#include "secret-types.h"
@ -1648,89 +1649,3 @@ secret_service_prompt_finish (SecretService *self,
return (klass->prompt_finish) (self, result, return_type, error);
}
GVariant *
secret_service_prompt_path_sync (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
const GVariantType *return_type,
GError **error)
{
SecretPrompt *prompt;
GVariant *retval;
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
g_return_val_if_fail (prompt_path != NULL, NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
prompt = _secret_prompt_instance (self, prompt_path);
retval = secret_service_prompt_sync (self, prompt, cancellable, return_type, error);
g_object_unref (prompt);
return retval;
}
/**
* secret_service_prompt_path:
* @self: the secret service
* @prompt_path: the D-Bus object path of the prompt
* @cancellable: optional cancellation object
* @callback: called when the operation completes
* @user_data: data to be passed to the callback
*
* Perform prompting for a #SecretPrompt.
*
* This function is called by other parts of this library to handle prompts
* for the various actions that can require prompting.
*
* Override the #SecretServiceClass <literal>prompt_async</literal> virtual method
* to change the behavior of the propmting. The default behavior is to simply
* run secret_prompt_perform() on the prompt.
*/
void
secret_service_prompt_path (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
SecretPrompt *prompt;
g_return_if_fail (SECRET_IS_SERVICE (self));
g_return_if_fail (prompt_path != NULL);
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
prompt = _secret_prompt_instance (self, prompt_path);
secret_service_prompt (self, prompt, cancellable, callback, user_data);
g_object_unref (prompt);
}
/**
* secret_service_prompt_path_finish:
* @self: the secret service
* @result: the asynchronous result passed to the callback
* @return_type: the variant type of the prompt result
* @error: location to place an error on failure
*
* Complete asynchronous operation to perform prompting for a #SecretPrompt.
*
* Returns a variant result if the prompt was completed and not dismissed. The
* type of result depends on the action the prompt is completing, and is defined
* in the Secret Service DBus API specification.
*
* Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred,
* a variant result if the prompt was successful
*/
GVariant *
secret_service_prompt_path_finish (SecretService *self,
GAsyncResult *result,
const GVariantType *return_type,
GError **error)
{
g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return secret_service_prompt_finish (self, result, return_type, error);
}

View File

@ -162,55 +162,6 @@ gboolean secret_service_search_sync (SecretService
GList **locked,
GError **error);
void secret_service_search_for_paths (SecretService *self,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_search_for_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***unlocked,
gchar ***locked,
GError **error);
gboolean secret_service_search_for_paths_sync (SecretService *self,
GHashTable *attributes,
GCancellable *cancellable,
gchar ***unlocked,
gchar ***locked,
GError **error);
void secret_service_get_secret_for_path (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
SecretValue * secret_service_get_secret_for_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
SecretValue * secret_service_get_secret_for_path_sync (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GError **error);
void secret_service_get_secrets_for_paths (SecretService *self,
const gchar **item_paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GHashTable * secret_service_get_secrets_for_paths_finish (SecretService *self,
GAsyncResult *result,
GError **error);
GHashTable * secret_service_get_secrets_for_paths_sync (SecretService *self,
const gchar **item_paths,
GCancellable *cancellable,
GError **error);
void secret_service_get_secrets (SecretService *self,
GList *items,
GCancellable *cancellable,
@ -243,23 +194,6 @@ gint secret_service_lock_sync (SecretService
GList **locked,
GError **error);
gint secret_service_lock_paths_sync (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
gchar ***locked,
GError **error);
void secret_service_lock_paths (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gint secret_service_lock_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***locked,
GError **error);
void secret_service_unlock (SecretService *self,
GList *objects,
GCancellable *cancellable,
@ -277,23 +211,6 @@ gint secret_service_unlock_sync (SecretService
GList **unlocked,
GError **error);
gint secret_service_unlock_paths_sync (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
gchar ***unlocked,
GError **error);
void secret_service_unlock_paths (SecretService *self,
const gchar **paths,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gint secret_service_unlock_paths_finish (SecretService *self,
GAsyncResult *result,
gchar ***unlocked,
GError **error);
GVariant * secret_service_prompt_sync (SecretService *self,
SecretPrompt *prompt,
GCancellable *cancellable,
@ -311,23 +228,6 @@ GVariant * secret_service_prompt_finish (SecretService
const GVariantType *return_type,
GError **error);
GVariant * secret_service_prompt_path_sync (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
const GVariantType *return_type,
GError **error);
void secret_service_prompt_path (SecretService *self,
const gchar *prompt_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GVariant * secret_service_prompt_path_finish (SecretService *self,
GAsyncResult *result,
const GVariantType *return_type,
GError **error);
void secret_service_store (SecretService *self,
const SecretSchema *schema,
GHashTable *attributes,
@ -368,21 +268,6 @@ SecretValue * secret_service_lookup_sync (SecretService
GCancellable *cancellable,
GError **error);
void secret_service_delete_path (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_delete_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gboolean secret_service_delete_path_sync (SecretService *self,
const gchar *item_path,
GCancellable *cancellable,
GError **error);
void secret_service_remove (SecretService *self,
const SecretSchema *schema,
GHashTable *attributes,
@ -400,44 +285,6 @@ gboolean secret_service_remove_sync (SecretService
GCancellable *cancellable,
GError **error);
void secret_service_create_collection_path (SecretService *self,
GHashTable *properties,
const gchar *alias,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_create_collection_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_create_collection_path_sync (SecretService *self,
GHashTable *properties,
const gchar *alias,
GCancellable *cancellable,
GError **error);
void secret_service_create_item_path (SecretService *self,
const gchar *collection_path,
GHashTable *properties,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_create_item_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_create_item_path_sync (SecretService *self,
const gchar *collection_path,
GHashTable *properties,
SecretValue *value,
gboolean replace,
GCancellable *cancellable,
GError **error);
void secret_service_read_alias (SecretService *self,
const gchar *alias,
GCancellable *cancellable,
@ -453,21 +300,6 @@ SecretCollection * secret_service_read_alias_sync (SecretService
GCancellable *cancellable,
GError **error);
void secret_service_read_alias_path (SecretService *self,
const gchar *alias,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_service_read_alias_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gchar * secret_service_read_alias_path_sync (SecretService *self,
const gchar *alias,
GCancellable *cancellable,
GError **error);
void secret_service_set_alias (SecretService *self,
const gchar *alias,
SecretCollection *collection,
@ -485,23 +317,6 @@ gboolean secret_service_set_alias_sync (SecretService
GCancellable *cancellable,
GError **error);
void secret_service_set_alias_path (SecretService *self,
const gchar *alias,
const gchar *collection_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_service_set_alias_path_finish (SecretService *self,
GAsyncResult *result,
GError **error);
gboolean secret_service_set_alias_path_sync (SecretService *self,
const gchar *alias,
const gchar *collection_path,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* __SECRET_SERVICE_H___ */

View File

@ -29,6 +29,7 @@
#include <secret/secret-collection.h>
#include <secret/secret-enum-types.h>
#include <secret/secret-item.h>
#include <secret/secret-paths.h>
#include <secret/secret-prompt.h>
#include <secret/secret-service.h>
#include <secret/secret-value.h>

View File

@ -36,6 +36,7 @@ C_TESTS = \
test-prompt \
test-service \
test-session \
test-paths \
test-methods \
test-password \
test-item \

View File

@ -16,8 +16,9 @@
#include "secret-attributes.h"
#include "secret-collection.h"
#include "secret-item.h"
#include "secret-service.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-service.h"
#include "mock-service.h"
@ -115,147 +116,6 @@ on_complete_get_result (GObject *source,
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");
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
&unlocked, &locked, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (locked);
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_assert (unlocked);
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
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");
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
&unlocked, &locked,
&error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (locked);
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_assert (unlocked);
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
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");
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
&paths, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
g_strfreev (paths);
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
NULL, &paths, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_strfreev (paths);
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
NULL, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
&paths, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
g_strfreev (paths);
g_clear_object (&result);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
NULL, &paths, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_strfreev (paths);
g_clear_object (&result);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
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)
@ -397,154 +257,6 @@ test_search_nulls (Test *test,
g_hash_table_unref (attributes);
}
static void
test_secret_for_path_sync (Test *test,
gconstpointer used)
{
SecretValue *value;
GError *error = NULL;
const gchar *path;
const gchar *password;
gsize length;
path = "/org/freedesktop/secrets/collection/english/1";
value = secret_service_get_secret_for_path_sync (test->service, path, NULL, &error);
g_assert_no_error (error);
g_assert (value != NULL);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
password = secret_value_get (value, NULL);
g_assert_cmpstr (password, ==, "111");
secret_value_unref (value);
}
static void
test_secret_for_path_async (Test *test,
gconstpointer used)
{
SecretValue *value;
GError *error = NULL;
const gchar *path;
const gchar *password;
GAsyncResult *result = NULL;
gsize length;
path = "/org/freedesktop/secrets/collection/english/1";
secret_service_get_secret_for_path (test->service, path, NULL,
on_complete_get_result, &result);
g_assert (result == NULL);
egg_test_wait ();
value = secret_service_get_secret_for_path_finish (test->service, result, &error);
g_assert_no_error (error);
g_assert (value != NULL);
g_object_unref (result);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
password = secret_value_get (value, NULL);
g_assert_cmpstr (password, ==, "111");
secret_value_unref (value);
}
static void
test_secrets_for_paths_sync (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
const gchar *paths[] = {
path_item_one,
path_item_two,
/* This one is locked, and not returned */
"/org/freedesktop/secrets/collection/spanish/10",
NULL
};
SecretValue *value;
GHashTable *values;
GError *error = NULL;
const gchar *password;
gsize length;
values = secret_service_get_secrets_for_paths_sync (test->service, paths, NULL, &error);
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);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
value = g_hash_table_lookup (values, path_item_two);
g_assert (value != NULL);
password = secret_value_get (value, &length);
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)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
const gchar *paths[] = {
path_item_one,
path_item_two,
/* This one is locked, and not returned */
"/org/freedesktop/secrets/collection/spanish/10",
NULL
};
SecretValue *value;
GHashTable *values;
GError *error = NULL;
const gchar *password;
GAsyncResult *result = NULL;
gsize length;
secret_service_get_secrets_for_paths (test->service, paths, NULL,
on_complete_get_result, &result);
g_assert (result == NULL);
egg_test_wait ();
values = secret_service_get_secrets_for_paths_finish (test->service, result, &error);
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);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
value = g_hash_table_lookup (values, path_item_two);
g_assert (value != NULL);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "222");
g_hash_table_unref (values);
}
static void
test_secrets_sync (Test *test,
gconstpointer used)
@ -655,82 +367,6 @@ test_secrets_async (Test *test,
g_object_unref (item_three);
}
static void
test_delete_for_path_sync (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/item";
GError *error = NULL;
gboolean ret;
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
}
static void
test_delete_for_path_sync_prompt (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/confirm";
GError *error = NULL;
gboolean ret;
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
}
static void
test_lock_paths_sync (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **locked = NULL;
gboolean ret;
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
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)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **locked = NULL;
gboolean ret;
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
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)
@ -760,54 +396,6 @@ test_lock_sync (Test *test,
g_object_unref (collection);
}
static void
test_unlock_paths_sync (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **unlocked = NULL;
gboolean ret;
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
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)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **unlocked = NULL;
gboolean ret;
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
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)
@ -837,152 +425,6 @@ test_unlock_sync (Test *test,
g_object_unref (collection);
}
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
path = secret_service_create_collection_path_sync (test->service, properties,
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
secret_service_create_collection_path (test->service, properties,
NULL, NULL, on_complete_get_result, &result);
g_hash_table_unref (properties);
g_assert (result == NULL);
egg_test_wait ();
path = secret_service_create_collection_path_finish (test->service, result, &error);
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;
SecretValue *value;
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
g_variant_ref_sink (_secret_attributes_to_variant (attributes, "org.gnome.Test")));
g_hash_table_unref (attributes);
value = secret_value_new ("andmoreandmore", -1, "text/plain");
path = secret_service_create_item_path_sync (test->service, collection_path,
properties, value, FALSE,
NULL, &error);
secret_value_unref (value);
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;
SecretValue *value;
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
g_variant_ref_sink (_secret_attributes_to_variant (attributes, NULL)));
g_hash_table_unref (attributes);
value = secret_value_new ("andmoreandmore", -1, "text/plain");
secret_service_create_item_path (test->service, collection_path,
properties, value, FALSE,
NULL, on_complete_get_result, &result);
g_assert (result == NULL);
secret_value_unref (value);
g_hash_table_unref (properties);
egg_test_wait ();
path = secret_service_create_item_path_finish (test->service, result, &error);
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);
}
static void
test_remove_sync (Test *test,
gconstpointer used)
@ -1485,36 +927,6 @@ test_set_alias_sync (Test *test,
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);
}
int
main (int argc, char **argv)
{
@ -1522,38 +934,17 @@ main (int argc, char **argv)
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);
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);
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);
@ -1574,7 +965,6 @@ main (int argc, char **argv)
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);
return egg_tests_run_with_loop ();
}

743
library/tests/test-paths.c Normal file
View File

@ -0,0 +1,743 @@
/* libsecret - GLib wrapper for Secret Service
*
* 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"
#include "secret-attributes.h"
#include "secret-collection.h"
#include "secret-item.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-service.h"
#include "mock-service.h"
#include "egg/egg-testing.h"
#include <glib.h>
#include <errno.h>
#include <stdlib.h>
static const SecretSchema MOCK_SCHEMA = {
"org.mock.Schema",
SECRET_SCHEMA_NONE,
{
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
}
};
static const SecretSchema PRIME_SCHEMA = {
"org.mock.Prime",
SECRET_SCHEMA_NONE,
{
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "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 },
}
};
typedef struct {
SecretService *service;
} 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);
test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
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");
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
&unlocked, &locked, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (locked);
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_assert (unlocked);
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
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");
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
&unlocked, &locked,
&error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (locked);
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_assert (unlocked);
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
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");
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
&paths, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
g_strfreev (paths);
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
NULL, &paths, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_strfreev (paths);
ret = secret_service_search_for_paths_sync (test->service, attributes, NULL,
NULL, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
&paths, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
g_strfreev (paths);
g_clear_object (&result);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
NULL, &paths, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_assert (paths != NULL);
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
g_strfreev (paths);
g_clear_object (&result);
secret_service_search_for_paths (test->service, attributes, NULL,
on_complete_get_result, &result);
egg_test_wait ();
g_assert (G_IS_ASYNC_RESULT (result));
ret = secret_service_search_for_paths_finish (test->service, result,
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)
{
SecretValue *value;
GError *error = NULL;
const gchar *path;
const gchar *password;
gsize length;
path = "/org/freedesktop/secrets/collection/english/1";
value = secret_service_get_secret_for_path_sync (test->service, path, NULL, &error);
g_assert_no_error (error);
g_assert (value != NULL);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
password = secret_value_get (value, NULL);
g_assert_cmpstr (password, ==, "111");
secret_value_unref (value);
}
static void
test_secret_for_path_async (Test *test,
gconstpointer used)
{
SecretValue *value;
GError *error = NULL;
const gchar *path;
const gchar *password;
GAsyncResult *result = NULL;
gsize length;
path = "/org/freedesktop/secrets/collection/english/1";
secret_service_get_secret_for_path (test->service, path, NULL,
on_complete_get_result, &result);
g_assert (result == NULL);
egg_test_wait ();
value = secret_service_get_secret_for_path_finish (test->service, result, &error);
g_assert_no_error (error);
g_assert (value != NULL);
g_object_unref (result);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
password = secret_value_get (value, NULL);
g_assert_cmpstr (password, ==, "111");
secret_value_unref (value);
}
static void
test_secrets_for_paths_sync (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
const gchar *paths[] = {
path_item_one,
path_item_two,
/* This one is locked, and not returned */
"/org/freedesktop/secrets/collection/spanish/10",
NULL
};
SecretValue *value;
GHashTable *values;
GError *error = NULL;
const gchar *password;
gsize length;
values = secret_service_get_secrets_for_paths_sync (test->service, paths, NULL, &error);
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);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
value = g_hash_table_lookup (values, path_item_two);
g_assert (value != NULL);
password = secret_value_get (value, &length);
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)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
const gchar *paths[] = {
path_item_one,
path_item_two,
/* This one is locked, and not returned */
"/org/freedesktop/secrets/collection/spanish/10",
NULL
};
SecretValue *value;
GHashTable *values;
GError *error = NULL;
const gchar *password;
GAsyncResult *result = NULL;
gsize length;
secret_service_get_secrets_for_paths (test->service, paths, NULL,
on_complete_get_result, &result);
g_assert (result == NULL);
egg_test_wait ();
values = secret_service_get_secrets_for_paths_finish (test->service, result, &error);
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);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "111");
value = g_hash_table_lookup (values, path_item_two);
g_assert (value != NULL);
password = secret_value_get (value, &length);
g_assert_cmpuint (length, ==, 3);
g_assert_cmpstr (password, ==, "222");
g_hash_table_unref (values);
}
static void
test_delete_for_path_sync (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/item";
GError *error = NULL;
gboolean ret;
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
}
static void
test_delete_for_path_sync_prompt (Test *test,
gconstpointer used)
{
const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/confirm";
GError *error = NULL;
gboolean ret;
ret = secret_service_delete_path_sync (test->service, path_item_one, NULL, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
}
static void
test_lock_paths_sync (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **locked = NULL;
gboolean ret;
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
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)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **locked = NULL;
gboolean ret;
ret = secret_service_lock_paths_sync (test->service, paths, NULL, &locked, &error);
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_unlock_paths_sync (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **unlocked = NULL;
gboolean ret;
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
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)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
const gchar *paths[] = {
collection_path,
NULL,
};
GError *error = NULL;
gchar **unlocked = NULL;
gboolean ret;
ret = secret_service_unlock_paths_sync (test->service, paths, NULL, &unlocked, &error);
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_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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
path = secret_service_create_collection_path_sync (test->service, properties,
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
secret_service_create_collection_path (test->service, properties,
NULL, NULL, on_complete_get_result, &result);
g_hash_table_unref (properties);
g_assert (result == NULL);
egg_test_wait ();
path = secret_service_create_collection_path_finish (test->service, result, &error);
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;
SecretValue *value;
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
g_variant_ref_sink (_secret_attributes_to_variant (attributes, "org.gnome.Test")));
g_hash_table_unref (attributes);
value = secret_value_new ("andmoreandmore", -1, "text/plain");
path = secret_service_create_item_path_sync (test->service, collection_path,
properties, value, FALSE,
NULL, &error);
secret_value_unref (value);
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;
SecretValue *value;
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);
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
g_variant_ref_sink (g_variant_new_string ("Wheeee")));
g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
g_variant_ref_sink (_secret_attributes_to_variant (attributes, NULL)));
g_hash_table_unref (attributes);
value = secret_value_new ("andmoreandmore", -1, "text/plain");
secret_service_create_item_path (test->service, collection_path,
properties, value, FALSE,
NULL, on_complete_get_result, &result);
g_assert (result == NULL);
secret_value_unref (value);
g_hash_table_unref (properties);
egg_test_wait ();
path = secret_service_create_item_path_finish (test->service, result, &error);
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);
}
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);
}
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/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/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/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/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);
g_test_add ("/service/set-alias-path", Test, "mock-service-normal.py", setup, test_set_alias_path, teardown);
return egg_tests_run_with_loop ();
}