gnome-keyring r1486 - in trunk: . daemon/keyrings daemon/keyrings/tests



Author: nnielsen
Date: Fri Jan 30 21:45:06 2009
New Revision: 1486
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1486&view=rev

Log:
	* daemon/keyrings/gkr-keyring.c:
	* daemon/keyrings/tests/unit-test-keyring-file.c: Don't assert when 
	trying to lock a keyring without a password. Fixes bug #569253


Modified:
   trunk/ChangeLog
   trunk/daemon/keyrings/gkr-keyring.c
   trunk/daemon/keyrings/tests/unit-test-keyring-file.c

Modified: trunk/daemon/keyrings/gkr-keyring.c
==============================================================================
--- trunk/daemon/keyrings/gkr-keyring.c	(original)
+++ trunk/daemon/keyrings/gkr-keyring.c	Fri Jan 30 21:45:06 2009
@@ -501,10 +501,12 @@
 	if (!keyring->location)
 		return TRUE;
 
-	g_assert (keyring->password != NULL);
+	/* Password will be null for textual keyrings */
+	if (keyring->password != NULL) {
+		egg_secure_strfree (keyring->password);
+		keyring->password = NULL;
+	}
 	
-	egg_secure_strfree (keyring->password);
-	keyring->password = NULL;
 	if (!gkr_keyring_update_from_disk (keyring)) {
 		/* Failed to re-read, remove the keyring */
 		g_warning ("Couldn't re-read keyring %s\n", keyring->keyring_name);
@@ -520,7 +522,7 @@
 	if (!keyring->locked)
 		return TRUE;
 		
-	g_assert (keyring->password == NULL);
+	g_return_val_if_fail (keyring->password == NULL, FALSE);
 		
 	keyring->password = egg_secure_strdup (password);
 	if (!gkr_keyring_update_from_disk (keyring)) {

Modified: trunk/daemon/keyrings/tests/unit-test-keyring-file.c
==============================================================================
--- trunk/daemon/keyrings/tests/unit-test-keyring-file.c	(original)
+++ trunk/daemon/keyrings/tests/unit-test-keyring-file.c	Fri Jan 30 21:45:06 2009
@@ -25,6 +25,8 @@
 
 #include "run-auto-test.h"
 
+#include "common/gkr-location.h"
+
 #include "egg/egg-secure-memory.h"
 
 #include "keyrings/gkr-keyring.h"
@@ -46,6 +48,23 @@
  * 
  * Tests be run in the order specified here.
  */
+
+static GQuark
+location_for_test_data (const gchar *filename)
+{
+	GQuark quark;
+	gchar *dir;
+	gchar *path;
+	
+	dir = g_get_current_dir ();
+	g_assert (dir);
+	
+	path = g_build_filename (dir, "test-data", filename, NULL);
+	quark = gkr_location_from_path (path);
+	g_free (path);
+	
+	return quark;
+}
  
 static void
 validate_keyring_contents (GkrKeyring *keyring, CuTest *cu)
@@ -173,3 +192,44 @@
 	
 	validate_keyring_contents (keyring, cu);
 }
+
+void unit_test_keyring_double_lock_encrypted (CuTest *cu)
+{
+	GkrKeyring *encrypted;
+	gboolean ret;
+	
+	encrypted = gkr_keyring_new ("encrypted", location_for_test_data ("encrypted.keyring"));
+	encrypted->password = egg_secure_strdup ("my-keyring-password");
+	ret = gkr_keyring_update_from_disk (encrypted);
+	CuAssert (cu, "couldn't parse generated textual data", ret == TRUE);
+	
+	/* Lock it */
+	gkr_keyring_lock (encrypted);
+	CuAssert (cu, "locked", encrypted->locked);
+	
+	/* Should succeed */
+	gkr_keyring_lock (encrypted);
+	CuAssert (cu, "locked", encrypted->locked);
+	
+	g_object_unref (encrypted);
+}
+
+void unit_test_keyring_double_lock_plain (CuTest *cu)
+{
+	GkrKeyring *keyring;
+	gboolean ret;
+	
+	keyring = gkr_keyring_new ("plain", location_for_test_data ("plain.keyring"));
+	ret = gkr_keyring_update_from_disk (keyring);
+	CuAssert (cu, "couldn't parse generated textual data", ret == TRUE);
+
+	/* Lock it, shouldn't actually work, no way to lock */
+	gkr_keyring_lock (keyring);
+	CuAssert (cu, "locked", !keyring->locked);
+	
+	/* Shouldn't crash */
+	gkr_keyring_lock (keyring);
+	CuAssert (cu, "locked", !keyring->locked);
+	
+	g_object_unref (keyring);
+}



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