telepathy-mission-control: Default account backend: test that *all* passwords are deleted

Simon McVittie smcv at kemper.freedesktop.org
Fri Aug 31 07:27:02 PDT 2012


Module: telepathy-mission-control
Branch: master
Commit: 2e3360a39c4a9202d3ba473292f90ef5a821b10c
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=2e3360a39c4a9202d3ba473292f90ef5a821b10c

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Thu Aug 30 19:32:19 2012 +0100

Default account backend: test that *all* passwords are deleted

Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=42088

---

 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)



More information about the telepathy-commits mailing list