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

Unified Diff: net/ssl/client_cert_store_chromeos_unittest.cc

Issue 394013005: Remove NSSCertDatabase from ClientCertStoreChromeOS unittest. (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
Index: net/ssl/client_cert_store_chromeos_unittest.cc
diff --git a/net/ssl/client_cert_store_chromeos_unittest.cc b/net/ssl/client_cert_store_chromeos_unittest.cc
index 65b668dbb25d21696337db71aeef49b0d5c58ded..0207a82e1a041898449d10591c1cf8de7daa4b0a 100644
--- a/net/ssl/client_cert_store_chromeos_unittest.cc
+++ b/net/ssl/client_cert_store_chromeos_unittest.cc
@@ -11,8 +11,8 @@
#include "base/strings/utf_string_conversions.h"
#include "crypto/nss_util.h"
#include "crypto/nss_util_internal.h"
-#include "net/cert/nss_cert_database.h"
#include "net/ssl/client_cert_store_unittest-inl.h"
+#include "net/test/cert_test_util.h"
namespace net {
@@ -20,40 +20,50 @@ class ClientCertStoreChromeOSTest : public ::testing::Test {
public:
scoped_refptr<X509Certificate> ImportCertForUser(
const std::string& username_hash,
- const std::string& filename,
- const std::string& password) {
+ const std::string& cert_filename,
+ const std::string& key_filename) {
crypto::ScopedPK11Slot slot(
crypto::GetPublicSlotForChromeOSUser(username_hash));
EXPECT_TRUE(slot.get());
if (!slot.get())
return NULL;
- net::CertificateList cert_list;
+ ImportSensitiveKeyFromFile(
+ GetTestCertsDirectory(), key_filename, slot.get());
- base::FilePath p12_path = GetTestCertsDirectory().AppendASCII(filename);
- std::string p12_data;
- if (!base::ReadFileToString(p12_path, &p12_data)) {
- EXPECT_TRUE(false);
- return NULL;
- }
+ scoped_refptr<X509Certificate> cert(
+ ImportCertFromFile(GetTestCertsDirectory(), cert_filename));
- scoped_refptr<net::CryptoModule> module(
- net::CryptoModule::CreateFromHandle(slot.get()));
- int rv = NSSCertDatabase::GetInstance()->ImportFromPKCS12(
- module.get(), p12_data, base::UTF8ToUTF16(password), false, &cert_list);
+ EXPECT_TRUE(cert) << "Failed to parse cert from file " << cert_filename;
+ if (!cert)
+ return NULL;
- EXPECT_EQ(0, rv);
- EXPECT_EQ(1U, cert_list.size());
- if (rv || cert_list.size() != 1)
+ CK_OBJECT_HANDLE key;
+ crypto::ScopedPK11Slot key_slot(
+ PK11_KeyForCertExists(cert->os_cert_handle(), &key, NULL));
+ EXPECT_EQ(slot.get(), key_slot.get())
+ << "Did not find key in the right slot, for cert file "
+ << cert_filename;
Ryan Sleevi 2014/07/16 19:32:18 Note: This is generally a dangerous pattern to put
pneubeck (no reviews) 2014/07/16 19:49:44 I followed the existing style. I'd actually would
Ryan Sleevi 2014/07/16 19:59:00 I think it's fine, but it means that you need to w
pneubeck (no reviews) 2014/07/17 13:26:43 Yeah, but that would still mean that there are red
+ if (slot.get() != key_slot.get())
return NULL;
- return cert_list[0];
+ // Use some nickname that is unique within this test.
+ std::string nickname = cert_filename;
+ {
+ crypto::AutoNSSWriteLock lock;
+ SECStatus rv = PK11_ImportCert(
+ slot.get(), cert->os_cert_handle(), key, nickname.c_str(), PR_FALSE);
+ EXPECT_EQ(SECSuccess, rv) << "Could not import cert from file "
+ << cert_filename;
+ if (rv != SECSuccess)
+ return NULL;
+ }
+
+ return cert;
}
};
-// TODO(mattm): Do better testing of cert_authorities matching below. Update
-// net/data/ssl/scripts/generate-client-certificates.sh so that it actually
-// saves the .p12 files, and regenerate them.
+// TODO(mattm): Do better testing of cert_authorities matching below.
TEST_F(ClientCertStoreChromeOSTest, WaitForNSSInit) {
crypto::ScopedTestNSSChromeOSUser user("scopeduser");
@@ -61,14 +71,15 @@ TEST_F(ClientCertStoreChromeOSTest, WaitForNSSInit) {
ClientCertStoreChromeOS store(
user.username_hash(), ClientCertStoreChromeOS::PasswordDelegateFactory());
scoped_refptr<X509Certificate> cert_1(
- ImportCertForUser(user.username_hash(), "client.p12", "12345"));
+ ImportCertForUser(user.username_hash(), "client_1.pem", "client_1.pk8"));
+ ASSERT_TRUE(cert_1);
scoped_refptr<X509Certificate> cert_2(
- ImportCertForUser(user.username_hash(), "websocket_client_cert.p12", ""));
+ ImportCertForUser(user.username_hash(), "client_2.pem", "client_2.pk8"));
+ ASSERT_TRUE(cert_2);
- std::vector<std::string> authority_1(
- 1,
- std::string(reinterpret_cast<const char*>(kAuthority1DN),
- sizeof(kAuthority1DN)));
+ std::vector<std::string> authority_1;
+ authority_1.push_back(std::string(
+ reinterpret_cast<const char*>(kAuthority1DN), sizeof(kAuthority1DN)));
scoped_refptr<SSLCertRequestInfo> request_1(new SSLCertRequestInfo());
request_1->cert_authorities = authority_1;
@@ -87,7 +98,7 @@ TEST_F(ClientCertStoreChromeOSTest, WaitForNSSInit) {
run_loop_1.Run();
run_loop_all.Run();
- ASSERT_EQ(0u, request_1->client_certs.size());
+ ASSERT_EQ(1u, request_1->client_certs.size());
Ryan Sleevi 2014/07/16 19:32:18 Why... is this? Seems wrong to update the test exp
pneubeck (no reviews) 2014/07/16 19:49:44 Because they were wrong? :-) See Matt's comment ab
Ryan Sleevi 2014/07/16 19:59:00 I don't know what comment you're referring to.
pneubeck (no reviews) 2014/07/16 20:01:39 Line 54 of the old file: // TODO(mattm): Do bett
pneubeck (no reviews) 2014/07/16 20:15:23 That's fair. My reasoning was: Matt commented tha
Ryan Sleevi 2014/07/16 20:46:07 I guess this highlights poor documentation. I don
pneubeck (no reviews) 2014/07/16 21:29:58 Ok. Let me explain that part then too. Another thi
ASSERT_EQ(2u, request_all->client_certs.size());
}
@@ -99,9 +110,11 @@ TEST_F(ClientCertStoreChromeOSTest, NSSAlreadyInitialized) {
ClientCertStoreChromeOS store(
user.username_hash(), ClientCertStoreChromeOS::PasswordDelegateFactory());
scoped_refptr<X509Certificate> cert_1(
- ImportCertForUser(user.username_hash(), "client.p12", "12345"));
+ ImportCertForUser(user.username_hash(), "client_1.pem", "client_1.pk8"));
+ ASSERT_TRUE(cert_1);
scoped_refptr<X509Certificate> cert_2(
- ImportCertForUser(user.username_hash(), "websocket_client_cert.p12", ""));
+ ImportCertForUser(user.username_hash(), "client_2.pem", "client_2.pk8"));
+ ASSERT_TRUE(cert_2);
std::vector<std::string> authority_1(
1,
@@ -122,7 +135,7 @@ TEST_F(ClientCertStoreChromeOSTest, NSSAlreadyInitialized) {
run_loop_1.Run();
run_loop_all.Run();
- ASSERT_EQ(0u, request_1->client_certs.size());
+ ASSERT_EQ(1u, request_1->client_certs.size());
ASSERT_EQ(2u, request_all->client_certs.size());
}
@@ -138,15 +151,18 @@ TEST_F(ClientCertStoreChromeOSTest, TwoUsers) {
user2.username_hash(),
ClientCertStoreChromeOS::PasswordDelegateFactory());
scoped_refptr<X509Certificate> cert_1(
- ImportCertForUser(user1.username_hash(), "client.p12", "12345"));
- scoped_refptr<X509Certificate> cert_2(ImportCertForUser(
- user2.username_hash(), "websocket_client_cert.p12", ""));
+ ImportCertForUser(user1.username_hash(), "client_1.pem", "client_1.pk8"));
+ ASSERT_TRUE(cert_1);
+ scoped_refptr<X509Certificate> cert_2(
+ ImportCertForUser(user2.username_hash(), "client_2.pem", "client_2.pk8"));
+ ASSERT_TRUE(cert_2);
scoped_refptr<SSLCertRequestInfo> request_1(new SSLCertRequestInfo());
scoped_refptr<SSLCertRequestInfo> request_2(new SSLCertRequestInfo());
base::RunLoop run_loop_1;
base::RunLoop run_loop_2;
+
store1.GetClientCerts(
*request_1, &request_1->client_certs, run_loop_1.QuitClosure());
store2.GetClientCerts(
@@ -161,8 +177,8 @@ TEST_F(ClientCertStoreChromeOSTest, TwoUsers) {
ASSERT_EQ(1u, request_1->client_certs.size());
EXPECT_TRUE(cert_1->Equals(request_1->client_certs[0]));
- // TODO(mattm): Request for second user will have zero results due to
- // crbug.com/315285. Update the test once that is fixed.
+ ASSERT_EQ(1u, request_2->client_certs.size());
+ EXPECT_TRUE(cert_2->Equals(request_2->client_certs[0]));
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698