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

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: 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..e4012dc90bbca073ffd75bea7a356aef337808c2 100644
--- a/net/base/keygen_handler_unittest.cc
+++ b/net/base/keygen_handler_unittest.cc
@@ -10,11 +10,13 @@
#include "base/bind.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,10 +32,16 @@ class KeygenHandlerTest : public ::testing::Test {
KeygenHandlerTest() {}
virtual ~KeygenHandlerTest() {}
- private:
-#if defined(OS_CHROMEOS) && defined(USE_NSS)
+ protected:
+#if defined(USE_NSS)
+ crypto::ScopedPK11Slot GetKeySlot() {
+ return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot());
+ }
+
+#if defined(OS_CHROMEOS)
Ryan Sleevi 2014/07/14 21:54:25 Is there any reason you restrict this to ChromeOS?
pneubeck (no reviews) 2014/07/15 13:22:22 Ack. Not sure why the restriction was there before
crypto::ScopedTestNSSDB test_nss_db_;
#endif
+#endif
};
// Assert that |result| is a valid output for KeygenHandler given challenge
@@ -74,6 +82,9 @@ void AssertValidSignedPublicKeyAndChallenge(const std::string& result,
TEST_F(KeygenHandlerTest, SmokeTest) {
KeygenHandler handler(768, "some challenge", GURL("http://www.example.com"));
+#if defined(USE_NSS)
+ handler.set_key_slot(GetKeySlot().get());
+#endif
handler.set_stores_key(false); // Don't leave the key-pair behind
std::string result = handler.GenKeyAndSignChallenge();
VLOG(1) << "KeygenHandler produced: " << result;
@@ -82,11 +93,17 @@ TEST_F(KeygenHandlerTest, SmokeTest) {
void ConcurrencyTestCallback(base::WaitableEvent* event,
const std::string& challenge,
+#if defined(USE_NSS)
+ PK11SlotInfo* slot,
+#endif
Ryan Sleevi 2014/07/14 21:54:25 I'm not at all a fan of embedding #ifdefs# like th
pneubeck (no reviews) 2014/07/15 13:22:21 Yeah, this was a rather quick hack to see whether
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"));
+#if defined(USE_NSS)
+ handler.set_key_slot(slot);
+#endif
handler.set_stores_key(false); // Don't leave the key-pair behind.
*result = handler.GenKeyAndSignChallenge();
event->Signal();
@@ -105,16 +122,23 @@ void ConcurrencyTestCallback(base::WaitableEvent* event,
// We asynchronously generate the keys so as not to hang up the IO thread. This
// test tries to catch concurrency problems in the keygen implementation.
TEST_F(KeygenHandlerTest, ConcurrencyTest) {
+#if defined(USE_NSS)
+ crypto::ScopedPK11Slot slot = GetKeySlot();
+#endif
const int NUM_HANDLERS = 5;
base::WaitableEvent* events[NUM_HANDLERS] = { NULL };
std::string results[NUM_HANDLERS];
for (int i = 0; i < NUM_HANDLERS; i++) {
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],
+ "some challenge",
+#if defined(USE_NSS)
+ slot.get(),
+#endif
+ &results[i]),
Ryan Sleevi 2014/07/14 21:54:25 Perhaps wrapping this base::Bind()ing into a helpe
pneubeck (no reviews) 2014/07/15 13:22:22 The handler doesn't have to be constructed in on t
+ 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