[gnome-keyring/dbus-api] [secret-store] Better tests for textual parsing, and fix bugs.



commit b668b4c4d0cfbce0d7fa1b4d480bbfb1fc192b35
Author: Stef Walter <stef memberwebs com>
Date:   Fri Aug 14 22:34:20 2009 +0000

    [secret-store] Better tests for textual parsing, and fix bugs.

 pkcs11/secret-store/gck-secret-textual.c           |    2 +
 pkcs11/secret-store/tests/test-secret-module.c     |  144 +++++++++++++++++++-
 pkcs11/secret-store/tests/test-secret-module.h     |    7 +
 .../secret-store/tests/unit-test-secret-textual.c  |   44 +------
 4 files changed, 156 insertions(+), 41 deletions(-)
---
diff --git a/pkcs11/secret-store/gck-secret-textual.c b/pkcs11/secret-store/gck-secret-textual.c
index 070ac64..51b24c9 100644
--- a/pkcs11/secret-store/gck-secret-textual.c
+++ b/pkcs11/secret-store/gck-secret-textual.c
@@ -161,6 +161,8 @@ parse_attributes (GKeyFile *file, GckSecretItem *item, const gchar **groups)
 		g_free (type);
 	}
 	
+	gck_secret_item_set_fields (item, attributes);
+	g_hash_table_unref (attributes);
 	g_free (prefix);
 } 
 
diff --git a/pkcs11/secret-store/tests/test-secret-module.c b/pkcs11/secret-store/tests/test-secret-module.c
index c020fc4..93b0f6b 100644
--- a/pkcs11/secret-store/tests/test-secret-module.c
+++ b/pkcs11/secret-store/tests/test-secret-module.c
@@ -24,9 +24,15 @@
 #include "config.h"
 #include "test-secret-module.h"
 
+#include "gck/gck-secret.h"
 #include "gck/gck-module.h"
 
-#include "secret-store/gck-secret-store.h"
+#include "gck-secret-collection.h"
+#include "gck-secret-data.h"
+#include "gck-secret-fields.h"
+#include "gck-secret-item.h"
+#include "gck-secret-object.h"
+#include "gck-secret-store.h"
 
 static GMutex *mutex = NULL;
 
@@ -103,3 +109,139 @@ test_secret_module_open_session (gboolean writable)
 
 	return session;
 }
+
+/* Validates plain.keyring and encrypted.keyring in test-data */
+void
+test_secret_collection_validate (GckSecretCollection *collection, GckSecretData *sdata)
+{
+	GckSecretItem* item;
+	GckSecretObject *obj;
+	GHashTable *fields;
+	const gchar *value;
+	GckSecret *secret;
+	GList *items;
+	glong when;
+	guint32 num;
+
+	obj = GCK_SECRET_OBJECT (collection);
+
+	/* The keyring itself */
+	/* "Missing keyring name" */
+	value = gck_secret_object_get_label (obj);
+	g_assert (value != NULL);
+	/* "Invalid keyring name" */
+	g_assert_cmpstr (value, ==, "unit-test-keyring");
+#if 0
+	/* "Bad lock settings" */
+	g_assert (!keyring->lock_on_idle && keyring->lock_timeout == 0);
+#endif
+	/* "Bad Creation Time" */
+	when = gck_secret_object_get_created (obj);
+	g_assert (when == 1198027852);
+	/* "Bad Modification Time" */
+	when = gck_secret_object_get_modified (obj);
+	g_assert (when == 1198027852);
+	/* "Wrong number of items" */
+	items = gck_secret_collection_get_items (collection);
+	g_assert_cmpint (g_list_length (items), ==, 2);
+	g_list_free (items);
+
+	/* Item #2 */
+	item = gck_secret_collection_get_item (collection, "2");
+	obj = GCK_SECRET_OBJECT (item);
+	/* "Couldn't find item" */
+	g_assert (item != NULL);
+#if 0
+	/* "Invalid item type" */
+	g_assert_cmpint (item->type, ==, GNOME_KEYRING_ITEM_GENERIC_SECRET);
+#endif
+	/* "Missing secret" */
+	secret = gck_secret_data_get_secret (sdata, "2");
+	g_assert (secret != NULL);
+	/* "Wrong secret" */
+	g_assert (gck_secret_equals (secret, (guchar*)"item-secret", -1));
+	/* "Bad Creation Time" */
+	when = gck_secret_object_get_created (obj);
+	g_assert_cmpint (when, ==, 1198027852);
+
+#if 0
+	/* Item #2 ACL */
+	/* "Bad ACLs" */
+	g_assert_cmpint (g_list_length (item->acl), ==, 1);
+	ac = (GnomeKeyringAccessControl*)item->acl->data;
+	/* "Invalid ACL" */
+	g_assert (ac && ac->application);
+	/* "Invalid ACL Path" */
+	g_assert (ac->application->pathname && strstr (ac->application->pathname, "run-auto-test"));
+	/* "Invalid ACL Display Name" */
+	g_assert (ac->application->display_name);
+	g_assert_cmpstr (ac->application->display_name, ==, "run-auto-test");
+	/* "Invalid ACL Access Type" */
+	g_assert_cmpint (ac->types_allowed, ==, (GNOME_KEYRING_ACCESS_READ | GNOME_KEYRING_ACCESS_WRITE | GNOME_KEYRING_ACCESS_REMOVE));
+#endif
+
+	/* Item #3 */
+	item = gck_secret_collection_get_item (collection, "3");
+	obj = GCK_SECRET_OBJECT (item);
+	/* "Couldn't find item #3" */
+	g_assert (item != NULL);
+	fields = gck_secret_item_get_fields (item);
+	g_assert (fields != NULL);
+	/* Make fields are the same */
+	value = gck_secret_fields_get (fields, "dog");
+	g_assert_cmpstr (value, ==, "woof");
+	value = gck_secret_fields_get (fields, "bird");
+	g_assert_cmpstr (value, ==, "cheep");
+	value = gck_secret_fields_get (fields, "iguana");
+	g_assert_cmpstr (value, ==, "");
+	g_assert (gck_secret_fields_get_compat_uint32 (fields, "num", &num));
+	g_assert_cmpuint (num, ==, 3);
+#if 0
+	/* "Invalid item type" */
+	g_assert_cmpint (item->type, ==, GNOME_KEYRING_ITEM_GENERIC_SECRET);
+#endif
+	/* "Missing secret" */
+	secret = gck_secret_data_get_secret (sdata, "3");
+	g_assert (secret != NULL);
+	/* "Wrong secret" */
+	g_assert (gck_secret_equals (secret, (guchar*)"item-secret", -1));
+}
+
+/* Fills a collection with some junk data */
+void
+test_secret_collection_populate (GckSecretCollection *collection, GckSecretData *sdata)
+{
+	GckSecretItem *item;
+	GHashTable *fields;
+	GckSecret *secret;
+
+	item = gck_secret_collection_create_item (collection, "4");
+	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Noises");
+	secret = gck_secret_new_from_password ("4's secret");
+	gck_secret_data_set_secret (sdata, "4", secret);
+	g_object_unref (secret);
+	fields = gck_secret_item_get_fields (item);
+	gck_secret_fields_add (fields, "doggy", "fart");
+	gck_secret_fields_add (fields, "pig", "grunt");
+	gck_secret_fields_add_compat_uint32 (fields, "how-many", 292929);
+
+	item = gck_secret_collection_create_item (collection, "5");
+	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Colors");
+	secret = gck_secret_new_from_password ("5's secret");
+	gck_secret_data_set_secret (sdata, "5", secret);
+	g_object_unref (secret);
+	fields = gck_secret_item_get_fields (item);
+	gck_secret_fields_add (fields, "barney", "purple");
+	gck_secret_fields_add (fields, "piglet", "pink");
+	gck_secret_fields_add_compat_uint32 (fields, "number", 8);
+
+	item = gck_secret_collection_create_item (collection, "6");
+	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Binary Secret");
+	secret = gck_secret_new ((guchar*)"binary\0secret", 13);
+	gck_secret_data_set_secret (sdata, "6", secret);
+	g_object_unref (secret);
+	fields = gck_secret_item_get_fields (item);
+	gck_secret_fields_add (fields, "train", "zoom");
+	gck_secret_fields_add (fields, "hummer", NULL);
+	gck_secret_fields_add_compat_uint32 (fields, "number", 2);
+}
diff --git a/pkcs11/secret-store/tests/test-secret-module.h b/pkcs11/secret-store/tests/test-secret-module.h
index 60d8b9f..2c31e4e 100644
--- a/pkcs11/secret-store/tests/test-secret-module.h
+++ b/pkcs11/secret-store/tests/test-secret-module.h
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include "gck/gck-types.h"
+#include "gck-secret-types.h"
 
 #include "pkcs11.h"
 
@@ -40,4 +41,10 @@ void                   test_secret_module_leave_and_finalize       (void);
 
 GckSession*            test_secret_module_open_session             (gboolean writable);
 
+void                   test_secret_collection_validate             (GckSecretCollection *collection,
+                                                                    GckSecretData *sdata);
+
+void                   test_secret_collection_populate             (GckSecretCollection *collection,
+                                                                    GckSecretData *sdata);
+
 #endif /* TEST_SECRET_MODULE_H_ */
diff --git a/pkcs11/secret-store/tests/unit-test-secret-textual.c b/pkcs11/secret-store/tests/unit-test-secret-textual.c
index 0736673..ba0c0ab 100644
--- a/pkcs11/secret-store/tests/unit-test-secret-textual.c
+++ b/pkcs11/secret-store/tests/unit-test-secret-textual.c
@@ -79,44 +79,6 @@ DEFINE_TEARDOWN(textual)
 	session = NULL;
 }
 
-static void
-fill_in_collection (void)
-{
-	GckSecretItem *item;
-	GHashTable *fields;
-	GckSecret *secret;
-
-	item = gck_secret_collection_create_item (collection, "4");
-	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Noises");
-	secret = gck_secret_new_from_password ("4's secret");
-	gck_secret_data_set_secret (sdata, "4", secret);
-	g_object_unref (secret);
-	fields = gck_secret_item_get_fields (item);
-	gck_secret_fields_add (fields, "doggy", "fart");
-	gck_secret_fields_add (fields, "pig", "grunt");
-	gck_secret_fields_add_compat_uint32 (fields, "how-many", 292929);
-
-	item = gck_secret_collection_create_item (collection, "5");
-	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Colors");
-	secret = gck_secret_new_from_password ("5's secret");
-	gck_secret_data_set_secret (sdata, "5", secret);
-	g_object_unref (secret);
-	fields = gck_secret_item_get_fields (item);
-	gck_secret_fields_add (fields, "barney", "purple");
-	gck_secret_fields_add (fields, "piglet", "pink");
-	gck_secret_fields_add_compat_uint32 (fields, "number", 8);
-
-	item = gck_secret_collection_create_item (collection, "6");
-	gck_secret_object_set_label (GCK_SECRET_OBJECT (item), "Binary Secret");
-	secret = gck_secret_new ((guchar*)"binary\0secret", 13);
-	gck_secret_data_set_secret (sdata, "6", secret);
-	g_object_unref (secret);
-	fields = gck_secret_item_get_fields (item);
-	gck_secret_fields_add (fields, "train", "zoom");
-	gck_secret_fields_add (fields, "hummer", NULL);
-	gck_secret_fields_add_compat_uint32 (fields, "number", 2);
-}
-
 DEFINE_TEST(textual_read)
 {
 	GckDataResult res;
@@ -127,6 +89,8 @@ DEFINE_TEST(textual_read)
 	res = gck_secret_textual_read (collection, sdata, data, n_data);
 	g_free (data);
 
+	test_secret_collection_validate (collection, sdata);
+
 	g_assert (res == GCK_DATA_SUCCESS);
 }
 
@@ -171,7 +135,7 @@ DEFINE_TEST(textual_write)
 	guchar *data;
 	gsize n_data;
 
-	fill_in_collection ();
+	test_secret_collection_populate (collection, sdata);
 
 	res = gck_secret_textual_write (collection, sdata, &data, &n_data);
 	g_assert (res == GCK_DATA_SUCCESS);
@@ -200,7 +164,7 @@ DEFINE_TEST(textual_remove_unavailable)
 	g_list_free (items);
 
 	/* Fill in some more data */
-	fill_in_collection ();
+	test_secret_collection_populate (collection, sdata);
 
 	/* Should have added three more */
 	items = gck_secret_collection_get_items (collection);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]