From 8dae5787146cde878e900822dae730517c849472 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 30 Aug 2012 19:32:19 +0100 Subject: [PATCH 8/8] Default account backend: test that *all* passwords are deleted Signed-off-by: Simon McVittie --- tests/account-store-default.c | 27 +++++++++++++++++++ tests/account-store-default.h | 2 ++ tests/account-store.c | 28 ++++++++++++++++++-- .../account-storage/default-keyring-storage.py | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/account-store-default.c b/tests/account-store-default.c index a569778..944bf2f 100644 --- a/tests/account-store-default.c +++ b/tests/account-store-default.c @@ -290,3 +290,30 @@ default_list (void) { return g_key_file_get_groups (default_keyfile (), NULL); } + +guint +default_count_passwords (void) +{ +#if ENABLE_GNOME_KEYRING + GnomeKeyringResult ok = GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON; + GnomeKeyringAttributeList *match = gnome_keyring_attribute_list_new (); + GList *items = NULL; + guint n = 0; + + ok = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET, + match, &items); + + if (ok != GNOME_KEYRING_RESULT_OK) + goto finished; + + n = g_list_length (items); + gnome_keyring_found_list_free (items); + + finished: + gnome_keyring_attribute_list_free (match); + + return n; +#else + return 0; +#endif +} diff --git a/tests/account-store-default.h b/tests/account-store-default.h index 739f95c..2436e93 100644 --- a/tests/account-store-default.h +++ b/tests/account-store-default.h @@ -38,4 +38,6 @@ gboolean default_exists (const gchar *account); GStrv default_list (void); +guint default_count_passwords (void); + #endif diff --git a/tests/account-store.c b/tests/account-store.c index 5483527..7e609a1 100644 --- a/tests/account-store.c +++ b/tests/account-store.c @@ -51,6 +51,7 @@ typedef struct { gboolean (*delete) (const gchar *account); gboolean (*exists) (const gchar *account); GStrv (*list) (void); + guint (*count_passwords) (void); } Backend; typedef enum { @@ -60,6 +61,7 @@ typedef enum { OP_DELETE, OP_EXISTS, OP_LIST, + OP_COUNT_PASSWORDS } Operation; const Backend backends[] = { @@ -68,7 +70,8 @@ const Backend backends[] = { default_set, default_delete, default_exists, - default_list, }, + default_list, + default_count_passwords }, #if ENABLE_LIBACCOUNTS_SSO { "libaccounts", @@ -76,7 +79,8 @@ const Backend backends[] = { libaccounts_set, libaccounts_delete, libaccounts_exists, - libaccounts_list, }, + libaccounts_list, + NULL }, #endif { NULL } @@ -164,6 +168,8 @@ int main (int argc, char **argv) op = OP_EXISTS; else if (g_str_equal (op_name, "list")) op = OP_LIST; + else if (g_str_equal (op_name, "count-passwords")) + op = OP_COUNT_PASSWORDS; switch (op) { @@ -202,6 +208,11 @@ int main (int argc, char **argv) usage (argv[0], "op '%s' requires an backend", op_name); break; + case OP_COUNT_PASSWORDS: + if (argc < 3) + usage (argv[0], "op '%s' requires an backend", op_name); + break; + case OP_UNKNOWN: usage (argv[0], "Unknown operation: %s", op_name); } @@ -239,6 +250,19 @@ int main (int argc, char **argv) g_strfreev (list); break; + case OP_COUNT_PASSWORDS: + if (store->count_passwords == NULL) + { + g_printerr ("Password-counting is unimplemented\n"); + } + else + { + guint n = store->count_passwords (); + output = g_strdup_printf ("%u", n); + success = TRUE; + } + break; + default: output = g_strdup ("Unknown operation"); } diff --git a/tests/twisted/account-storage/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py index 4ac8168..bab0b72 100644 --- a/tests/twisted/account-storage/default-keyring-storage.py +++ b/tests/twisted/account-storage/default-keyring-storage.py @@ -258,6 +258,8 @@ DisplayName=New and improved account assert 'param-password' not in kf[group] pwd = account_store('get', 'default', 'param-password') assertEquals(None, pwd) + pwd = account_store('count-passwords', 'default') + assertEquals('0', pwd) # Put it back, just so deleting all accounts won't raise errors account_manager, properties, interfaces = resuscitate_mc(q, bus, mc) -- 1.7.10.4