summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 04:37:51 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 04:37:51 +0000
commit0274629c9983144bc161bb88a7e9436d28301e6d (patch)
treeb66495bbb20df46562644fe5587254b313036c63 /crypto
parent527516c019a53b8417b3e4ba3612083efe4e29ce (diff)
downloadchromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.zip
chromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.tar.gz
chromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.tar.bz2
CertDatabaseNSSTest: Don't delete test DB dir since we don't close the DB (broke in r108543).
Refactor test DB code so that nss_util owns the test DB dir. Keeping the test DB dir until exit prevents later tests that would use the test DB from failing. The dir will still be deleted by the LazyInstance atexit handler. BUG=108748 TEST=see bug Review URL: http://codereview.chromium.org/9255034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto')
-rw-r--r--crypto/nss_util.cc23
-rw-r--r--crypto/nss_util.h13
2 files changed, 22 insertions, 14 deletions
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index c60b7ea..4a48db1 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -30,6 +30,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/native_library.h"
+#include "base/scoped_temp_dir.h"
#include "base/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
@@ -220,6 +221,11 @@ class NSPRInitSingleton {
base::LazyInstance<NSPRInitSingleton>::Leaky
g_nspr_singleton = LAZY_INSTANCE_INITIALIZER;
+// This is a LazyInstance so that it will be deleted automatically when the
+// unittest exits. NSSInitSingleton is a LeakySingleton, so it would not be
+// deleted if it were a regular member.
+base::LazyInstance<ScopedTempDir> g_test_nss_db_dir = LAZY_INSTANCE_INITIALIZER;
+
class NSSInitSingleton {
public:
#if defined(OS_CHROMEOS)
@@ -343,8 +349,12 @@ class NSSInitSingleton {
#endif // defined(OS_CHROMEOS)
- bool OpenTestNSSDB(const FilePath& path, const char* description) {
- test_slot_ = OpenUserDB(path, description);
+ bool OpenTestNSSDB() {
+ if (test_slot_)
+ return true;
+ if (!g_test_nss_db_dir.Get().CreateUniqueTempDir())
+ return false;
+ test_slot_ = OpenUserDB(g_test_nss_db_dir.Get().path(), "Test DB");
return !!test_slot_;
}
@@ -355,6 +365,7 @@ class NSSInitSingleton {
PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
PK11_FreeSlot(test_slot_);
test_slot_ = NULL;
+ ignore_result(g_test_nss_db_dir.Get().Delete());
}
}
@@ -698,12 +709,8 @@ bool CheckNSSVersion(const char* version) {
}
#if defined(USE_NSS)
-bool OpenTestNSSDB(const FilePath& path, const char* description) {
- return g_nss_singleton.Get().OpenTestNSSDB(path, description);
-}
-
-void CloseTestNSSDB() {
- g_nss_singleton.Get().CloseTestNSSDB();
+bool OpenTestNSSDB() {
+ return g_nss_singleton.Get().OpenTestNSSDB();
}
base::Lock* GetNSSWriteLock() {
diff --git a/crypto/nss_util.h b/crypto/nss_util.h
index 746691d..9cfdf0b 100644
--- a/crypto/nss_util.h
+++ b/crypto/nss_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -154,11 +154,12 @@ CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime);
CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time);
#if defined(USE_NSS)
-// Exposed for unittests only. |path| should be an existing directory under
-// which the DB files will be placed. |description| is a user-visible name for
-// the DB, as a utf8 string, which will be truncated at 32 bytes.
-CRYPTO_EXPORT bool OpenTestNSSDB(const FilePath& path, const char* description);
-CRYPTO_EXPORT void CloseTestNSSDB();
+// Exposed for unittests only.
+// TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is
+// fixed, switch back to using a separate userdb for each test. (Maybe refactor
+// to provide a ScopedTestNSSDB instead of open/close methods.)
+CRYPTO_EXPORT bool OpenTestNSSDB();
+// NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB.
// NSS has a bug which can cause a deadlock or stall in some cases when writing
// to the certDB and keyDB. It also has a bug which causes concurrent key pair