Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Unified Diff: net/base/keygen_handler_unittest.cc

Issue 384413004: Remove default key slot from KeygenHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compilation, addressed suggestions. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/base/keygen_handler.h ('K') | « net/base/keygen_handler_nss.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/keygen_handler_unittest.cc
diff --git a/net/base/keygen_handler_unittest.cc b/net/base/keygen_handler_unittest.cc
index a868b2925c8745ee9362f8cf1a6dee84df208028..df8ed6a4fb8c1ee7dc955a0ea8679456f1e3d2f6 100644
--- a/net/base/keygen_handler_unittest.cc
+++ b/net/base/keygen_handler_unittest.cc
@@ -8,13 +8,16 @@
#include "base/base64.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/threading/worker_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/synchronization/waitable_event.h"
#include "build/build_config.h"
#include "crypto/nss_util.h"
+#include "crypto/nss_util_internal.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(USE_NSS)
@@ -30,8 +33,15 @@ class KeygenHandlerTest : public ::testing::Test {
KeygenHandlerTest() {}
virtual ~KeygenHandlerTest() {}
- private:
-#if defined(OS_CHROMEOS) && defined(USE_NSS)
+ protected:
+ void SetUpKeyHandler(KeygenHandler* handler) {
+#if defined(USE_NSS)
+ crypto::ScopedPK11Slot slot(crypto::GetPersistentNSSKeySlot());
+ handler->set_key_slot(slot.get());
+#endif
+ }
+
+#if defined(USE_NSS)
crypto::ScopedTestNSSDB test_nss_db_;
#endif
};
@@ -74,6 +84,7 @@ void AssertValidSignedPublicKeyAndChallenge(const std::string& result,
TEST_F(KeygenHandlerTest, SmokeTest) {
KeygenHandler handler(768, "some challenge", GURL("http://www.example.com"));
+ SetUpKeyHandler(&handler);
handler.set_stores_key(false); // Don't leave the key-pair behind
std::string result = handler.GenKeyAndSignChallenge();
VLOG(1) << "KeygenHandler produced: " << result;
@@ -81,14 +92,13 @@ TEST_F(KeygenHandlerTest, SmokeTest) {
}
void ConcurrencyTestCallback(base::WaitableEvent* event,
- const std::string& challenge,
+ scoped_ptr<KeygenHandler> handler,
std::string* result) {
// We allow Singleton use on the worker thread here since we use a
// WaitableEvent to synchronize, so it's safe.
base::ThreadRestrictions::ScopedAllowSingleton scoped_allow_singleton;
- KeygenHandler handler(768, challenge, GURL("http://www.example.com"));
- handler.set_stores_key(false); // Don't leave the key-pair behind.
- *result = handler.GenKeyAndSignChallenge();
+ handler->set_stores_key(false); // Don't leave the key-pair behind.
+ *result = handler->GenKeyAndSignChallenge();
event->Signal();
#if defined(USE_NSS)
// Detach the thread from NSPR.
@@ -106,15 +116,19 @@ void ConcurrencyTestCallback(base::WaitableEvent* event,
// test tries to catch concurrency problems in the keygen implementation.
TEST_F(KeygenHandlerTest, ConcurrencyTest) {
const int NUM_HANDLERS = 5;
- base::WaitableEvent* events[NUM_HANDLERS] = { NULL };
+ base::WaitableEvent* events[NUM_HANDLERS] = {NULL};
std::string results[NUM_HANDLERS];
for (int i = 0; i < NUM_HANDLERS; i++) {
+ scoped_ptr<KeygenHandler> handler(new KeygenHandler(
+ 768, "some challenge", GURL("http://www.example.com")));
+ SetUpKeyHandler(handler.get());
events[i] = new base::WaitableEvent(false, false);
- base::WorkerPool::PostTask(
- FROM_HERE,
- base::Bind(ConcurrencyTestCallback, events[i], "some challenge",
- &results[i]),
- true);
+ base::WorkerPool::PostTask(FROM_HERE,
+ base::Bind(ConcurrencyTestCallback,
+ events[i],
+ base::Passed(&handler),
+ &results[i]),
+ true);
}
for (int i = 0; i < NUM_HANDLERS; i++) {
« net/base/keygen_handler.h ('K') | « net/base/keygen_handler_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698