summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-31 01:09:44 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-31 01:09:44 +0000
commita8e0ab9d8e47f6344ef4e28c88b0d76b0eb8aadc (patch)
tree4e197a13ac440b7dd1fc83d78a389116c0f69fc0
parent5e027b2d0c6749b0181fa01156f9080dac10ad95 (diff)
downloadchromium_src-a8e0ab9d8e47f6344ef4e28c88b0d76b0eb8aadc.zip
chromium_src-a8e0ab9d8e47f6344ef4e28c88b0d76b0eb8aadc.tar.gz
chromium_src-a8e0ab9d8e47f6344ef4e28c88b0d76b0eb8aadc.tar.bz2
Make all the things use cert_test_util.h.
BUG=none TEST=trybots Review URL: https://chromiumcodereview.appspot.com/9960002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130018 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/net/x509_certificate_model_unittest.cc70
-rw-r--r--net/base/cert_database_nss_unittest.cc69
-rw-r--r--net/socket/ssl_server_socket_unittest.cc8
-rw-r--r--remoting/protocol/authenticator_test_base.cc8
-rw-r--r--remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc8
-rw-r--r--remoting/remoting.gyp1
6 files changed, 50 insertions, 114 deletions
diff --git a/chrome/common/net/x509_certificate_model_unittest.cc b/chrome/common/net/x509_certificate_model_unittest.cc
index 1ef36fa..233475e 100644
--- a/chrome/common/net/x509_certificate_model_unittest.cc
+++ b/chrome/common/net/x509_certificate_model_unittest.cc
@@ -8,47 +8,22 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "net/base/cert_database.h"
+#include "net/base/cert_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-class X509CertificateModelTest : public testing::Test {
- protected:
- static std::string ReadTestFile(const std::string& name) {
- std::string result;
- FilePath cert_path = GetTestCertsDirectory().AppendASCII(name);
- EXPECT_TRUE(file_util::ReadFileToString(cert_path, &result));
- return result;
- }
-
- private:
- // Returns a FilePath object representing the src/net/data/ssl/certificates
- // directory in the source tree.
- static FilePath GetTestCertsDirectory() {
- FilePath certs_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
- certs_dir = certs_dir.AppendASCII("net");
- certs_dir = certs_dir.AppendASCII("data");
- certs_dir = certs_dir.AppendASCII("ssl");
- certs_dir = certs_dir.AppendASCII("certificates");
- return certs_dir;
- }
-};
-
-TEST_F(X509CertificateModelTest, GetTypeCA) {
- std::string cert_data = ReadTestFile("root_ca_cert.crt");
-
- net::CertificateList certs =
- net::X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(),
- net::X509Certificate::FORMAT_AUTO);
- ASSERT_EQ(1U, certs.size());
+TEST(X509CertificateModelTest, GetTypeCA) {
+ scoped_refptr<net::X509Certificate> cert(
+ net::ImportCertFromFile(net::GetTestCertsDirectory(),
+ "root_ca_cert.crt"));
+ ASSERT_TRUE(cert.get());
#if defined(USE_OPENSSL)
// Remove this when OpenSSL build implements the necessary functions.
EXPECT_EQ(net::UNKNOWN_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
#else
EXPECT_EQ(net::CA_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
// Test that explicitly distrusted CA certs are still returned as CA_CERT
// type. See http://crbug.com/96654.
@@ -58,44 +33,41 @@ TEST_F(X509CertificateModelTest, GetTypeCA) {
// distrusted (trust set to CERTDB_TERMINAL_RECORD). See
// http://crbug.com/116411. When I fix that bug I'll also add a way to set
// this directly.
- EXPECT_TRUE(cert_db.SetCertTrust(certs[0], net::SERVER_CERT,
+ EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
net::CertDatabase::UNTRUSTED));
EXPECT_EQ(net::CA_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
#endif
}
-TEST_F(X509CertificateModelTest, GetTypeServer) {
- std::string cert_data = ReadTestFile("google.single.der");
-
- net::CertificateList certs =
- net::X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(),
- net::X509Certificate::FORMAT_AUTO);
- ASSERT_EQ(1U, certs.size());
+TEST(X509CertificateModelTest, GetTypeServer) {
+ scoped_refptr<net::X509Certificate> cert(
+ net::ImportCertFromFile(net::GetTestCertsDirectory(),
+ "google.single.der"));
+ ASSERT_TRUE(cert.get());
#if defined(USE_OPENSSL)
// Remove this when OpenSSL build implements the necessary functions.
EXPECT_EQ(net::UNKNOWN_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
#else
// TODO(mattm): make GetCertType smarter so we can tell server certs even if
// they have no trust bits set.
EXPECT_EQ(net::UNKNOWN_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
net::CertDatabase cert_db;
- EXPECT_TRUE(cert_db.SetCertTrust(certs[0], net::SERVER_CERT,
+ EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
net::CertDatabase::TRUSTED_SSL));
EXPECT_EQ(net::SERVER_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
- EXPECT_TRUE(cert_db.SetCertTrust(certs[0], net::SERVER_CERT,
+ EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
net::CertDatabase::UNTRUSTED));
EXPECT_EQ(net::SERVER_CERT,
- x509_certificate_model::GetType(certs[0]->os_cert_handle()));
+ x509_certificate_model::GetType(cert->os_cert_handle()));
#endif
}
diff --git a/net/base/cert_database_nss_unittest.cc b/net/base/cert_database_nss_unittest.cc
index 8ed8251b..75ea641 100644
--- a/net/base/cert_database_nss_unittest.cc
+++ b/net/base/cert_database_nss_unittest.cc
@@ -20,6 +20,7 @@
#include "crypto/scoped_nss_types.h"
#include "net/base/cert_database.h"
#include "net/base/cert_status_flags.h"
+#include "net/base/cert_test_util.h"
#include "net/base/cert_verify_proc.h"
#include "net/base/cert_verify_result.h"
#include "net/base/crypto_module.h"
@@ -77,13 +78,9 @@ class CertDatabaseNSSTest : public testing::Test {
static bool ReadCertIntoList(const std::string& name,
CertificateList* certs) {
- std::string cert_data = ReadTestFile(name);
- if (cert_data.empty())
- return false;
-
- X509Certificate* cert = X509Certificate::CreateFromBytes(
- cert_data.data(), cert_data.size());
- if (!cert)
+ scoped_refptr<X509Certificate> cert(
+ ImportCertFromFile(GetTestCertsDirectory(), name));
+ if (!cert.get())
return false;
certs->push_back(cert);
@@ -110,18 +107,6 @@ class CertDatabaseNSSTest : public testing::Test {
CertDatabase cert_db_;
private:
- // Returns a FilePath object representing the src/net/data/ssl/certificates
- // directory in the source tree.
- static FilePath GetTestCertsDirectory() {
- FilePath certs_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
- certs_dir = certs_dir.AppendASCII("net");
- certs_dir = certs_dir.AppendASCII("data");
- certs_dir = certs_dir.AppendASCII("ssl");
- certs_dir = certs_dir.AppendASCII("certificates");
- return certs_dir;
- }
-
static bool CleanupSlotContents(PK11SlotInfo* slot) {
CertDatabase cert_db;
bool ok = true;
@@ -269,11 +254,9 @@ TEST_F(CertDatabaseNSSTest, ImportFromPKCS12InvalidFile) {
}
TEST_F(CertDatabaseNSSTest, ImportCACert_SSLTrust) {
- std::string cert_data = ReadTestFile("root_ca_cert.crt");
-
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "root_ca_cert.crt",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(1U, certs.size());
EXPECT_FALSE(certs[0]->os_cert_handle()->isperm);
@@ -301,11 +284,9 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_SSLTrust) {
}
TEST_F(CertDatabaseNSSTest, ImportCACert_EmailTrust) {
- std::string cert_data = ReadTestFile("root_ca_cert.crt");
-
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "root_ca_cert.crt",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(1U, certs.size());
EXPECT_FALSE(certs[0]->os_cert_handle()->isperm);
@@ -332,11 +313,9 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_EmailTrust) {
}
TEST_F(CertDatabaseNSSTest, ImportCACert_ObjSignTrust) {
- std::string cert_data = ReadTestFile("root_ca_cert.crt");
-
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "root_ca_cert.crt",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(1U, certs.size());
EXPECT_FALSE(certs[0]->os_cert_handle()->isperm);
@@ -363,11 +342,9 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_ObjSignTrust) {
}
TEST_F(CertDatabaseNSSTest, ImportCA_NotCACert) {
- std::string cert_data = ReadTestFile("google.single.pem");
-
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "google.single.pem",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(1U, certs.size());
EXPECT_FALSE(certs[0]->os_cert_handle()->isperm);
@@ -495,10 +472,9 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchyTree) {
}
TEST_F(CertDatabaseNSSTest, ImportCACertNotHierarchy) {
- std::string cert_data = ReadTestFile("root_ca_cert.crt");
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "root_ca_cert.crt",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(1U, certs.size());
ASSERT_TRUE(ReadCertIntoList("dod_ca_13_cert.der", &certs));
ASSERT_TRUE(ReadCertIntoList("dod_ca_17_cert.der", &certs));
@@ -528,10 +504,9 @@ TEST_F(CertDatabaseNSSTest, DISABLED_ImportServerCert) {
// Need to import intermediate cert for the verify of google cert, otherwise
// it will try to fetch it automatically with cert_pi_useAIACertFetch, which
// will cause OCSPCreateSession on the main thread, which is not allowed.
- std::string cert_data = ReadTestFile("google.chain.pem");
- CertificateList certs =
- X509Certificate::CreateCertificateListFromBytes(
- cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ CertificateList certs = CreateCertificateListFromFile(
+ GetTestCertsDirectory(), "google.chain.pem",
+ X509Certificate::FORMAT_AUTO);
ASSERT_EQ(2U, certs.size());
CertDatabase::ImportCertFailureList failed;
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index ccb8ac1..e800cc6 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -28,6 +28,7 @@
#include "crypto/rsa_private_key.h"
#include "net/base/address_list.h"
#include "net/base/cert_status_flags.h"
+#include "net/base/cert_test_util.h"
#include "net/base/cert_verifier.h"
#include "net/base/completion_callback.h"
#include "net/base/host_port_pair.h"
@@ -254,12 +255,7 @@ class SSLServerSocketTest : public PlatformTest {
FakeSocket* fake_client_socket = new FakeSocket(&channel_1_, &channel_2_);
FakeSocket* fake_server_socket = new FakeSocket(&channel_2_, &channel_1_);
- FilePath certs_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
- certs_dir = certs_dir.AppendASCII("net");
- certs_dir = certs_dir.AppendASCII("data");
- certs_dir = certs_dir.AppendASCII("ssl");
- certs_dir = certs_dir.AppendASCII("certificates");
+ FilePath certs_dir(GetTestCertsDirectory());
FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
std::string cert_der;
diff --git a/remoting/protocol/authenticator_test_base.cc b/remoting/protocol/authenticator_test_base.cc
index f83d385..edff6d3 100644
--- a/remoting/protocol/authenticator_test_base.cc
+++ b/remoting/protocol/authenticator_test_base.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "crypto/rsa_private_key.h"
+#include "net/base/cert_test_util.h"
#include "remoting/protocol/authenticator.h"
#include "remoting/protocol/channel_authenticator.h"
#include "remoting/protocol/fake_session.h"
@@ -31,12 +32,7 @@ AuthenticatorTestBase::~AuthenticatorTestBase() {
}
void AuthenticatorTestBase::SetUp() {
- FilePath certs_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
- certs_dir = certs_dir.AppendASCII("net");
- certs_dir = certs_dir.AppendASCII("data");
- certs_dir = certs_dir.AppendASCII("ssl");
- certs_dir = certs_dir.AppendASCII("certificates");
+ FilePath certs_dir(net::GetTestCertsDirectory());
FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
ASSERT_TRUE(file_util::ReadFileToString(cert_path, &host_cert_));
diff --git a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
index 5af5299..49e4c1e 100644
--- a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
+++ b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "crypto/rsa_private_key.h"
+#include "net/base/cert_test_util.h"
#include "net/base/net_errors.h"
#include "remoting/protocol/connection_tester.h"
#include "remoting/protocol/fake_session.h"
@@ -45,12 +46,7 @@ class SslHmacChannelAuthenticatorTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
- FilePath certs_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
- certs_dir = certs_dir.AppendASCII("net");
- certs_dir = certs_dir.AppendASCII("data");
- certs_dir = certs_dir.AppendASCII("ssl");
- certs_dir = certs_dir.AppendASCII("certificates");
+ FilePath certs_dir(net::GetTestCertsDirectory());
FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
ASSERT_TRUE(file_util::ReadFileToString(cert_path, &host_cert_));
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 379a4ab..2b3cf7e 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -1236,6 +1236,7 @@
'../base/base.gyp:base_i18n',
'../base/base.gyp:test_support_base',
'../media/media.gyp:media',
+ '../net/net.gyp:net_test_support',
'../ppapi/ppapi.gyp:ppapi_cpp',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',