| Index: net/util/sqlite/sqlite_server_bound_cert_store_unittest.cc
|
| diff --git a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc b/net/util/sqlite/sqlite_server_bound_cert_store_unittest.cc
|
| similarity index 77%
|
| rename from chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
|
| rename to net/util/sqlite/sqlite_server_bound_cert_store_unittest.cc
|
| index 5afb73de23efa529c79e524964b7ce6e5ed04773..d59f50054bd3a643912713f67f36abc8e2de2e62 100644
|
| --- a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc
|
| +++ b/net/util/sqlite/sqlite_server_bound_cert_store_unittest.cc
|
| @@ -10,20 +10,21 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/stl_util.h"
|
| -#include "chrome/browser/net/sqlite_server_bound_cert_store.h"
|
| -#include "chrome/common/chrome_constants.h"
|
| -#include "content/public/test/mock_special_storage_policy.h"
|
| -#include "content/public/test/test_browser_thread_bundle.h"
|
| #include "net/base/test_data_directory.h"
|
| #include "net/ssl/ssl_client_cert_type.h"
|
| #include "net/test/cert_test_util.h"
|
| +#include "net/util/sqlite/sqlite_server_bound_cert_store.h"
|
| #include "sql/statement.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +namespace net {
|
| +
|
| +const base::FilePath::CharType kTestOBCertFilename[] =
|
| + FILE_PATH_LITERAL("Origin Bound Certs");
|
| +
|
| class SQLiteServerBoundCertStoreTest : public testing::Test {
|
| public:
|
| - void Load(
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>* certs) {
|
| + void Load(ScopedVector<DefaultServerBoundCertStore::ServerBoundCert>* certs) {
|
| base::RunLoop run_loop;
|
| store_->Load(base::Bind(&SQLiteServerBoundCertStoreTest::OnLoaded,
|
| base::Unretained(this),
|
| @@ -35,18 +36,18 @@ class SQLiteServerBoundCertStoreTest : public testing::Test {
|
|
|
| void OnLoaded(
|
| base::RunLoop* run_loop,
|
| - scoped_ptr<ScopedVector<
|
| - net::DefaultServerBoundCertStore::ServerBoundCert> > certs) {
|
| + scoped_ptr<ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> >
|
| + certs) {
|
| certs_.swap(*certs);
|
| run_loop->Quit();
|
| }
|
|
|
| protected:
|
| static void ReadTestKeyAndCert(std::string* key, std::string* cert) {
|
| - base::FilePath key_path = net::GetTestCertsDirectory().AppendASCII(
|
| - "unittest.originbound.key.der");
|
| - base::FilePath cert_path = net::GetTestCertsDirectory().AppendASCII(
|
| - "unittest.originbound.der");
|
| + base::FilePath key_path =
|
| + GetTestCertsDirectory().AppendASCII("unittest.originbound.key.der");
|
| + base::FilePath cert_path =
|
| + GetTestCertsDirectory().AppendASCII("unittest.originbound.der");
|
| ASSERT_TRUE(base::ReadFileToString(key_path, key));
|
| ASSERT_TRUE(base::ReadFileToString(cert_path, cert));
|
| }
|
| @@ -76,37 +77,35 @@ class SQLiteServerBoundCertStoreTest : public testing::Test {
|
| virtual void SetUp() {
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| store_ = new SQLiteServerBoundCertStore(
|
| - temp_dir_.path().Append(chrome::kOBCertFilename),
|
| - base::MessageLoopProxy::current(),
|
| - NULL);
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + temp_dir_.path().Append(kTestOBCertFilename),
|
| + base::MessageLoopProxy::current());
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| Load(&certs);
|
| ASSERT_EQ(0u, certs.size());
|
| // Make sure the store gets written at least once.
|
| - store_->AddServerBoundCert(
|
| - net::DefaultServerBoundCertStore::ServerBoundCert(
|
| - "google.com",
|
| - base::Time::FromInternalValue(1),
|
| - base::Time::FromInternalValue(2),
|
| - "a", "b"));
|
| + store_->AddServerBoundCert(DefaultServerBoundCertStore::ServerBoundCert(
|
| + "google.com",
|
| + base::Time::FromInternalValue(1),
|
| + base::Time::FromInternalValue(2),
|
| + "a",
|
| + "b"));
|
| }
|
|
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| base::ScopedTempDir temp_dir_;
|
| scoped_refptr<SQLiteServerBoundCertStore> store_;
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs_;
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs_;
|
| };
|
|
|
| // Test if data is stored as expected in the SQLite database.
|
| TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
|
| - store_->AddServerBoundCert(
|
| - net::DefaultServerBoundCertStore::ServerBoundCert(
|
| - "foo.com",
|
| - base::Time::FromInternalValue(3),
|
| - base::Time::FromInternalValue(4),
|
| - "c", "d"));
|
| -
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + store_->AddServerBoundCert(DefaultServerBoundCertStore::ServerBoundCert(
|
| + "foo.com",
|
| + base::Time::FromInternalValue(3),
|
| + base::Time::FromInternalValue(4),
|
| + "c",
|
| + "d"));
|
| +
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| // Replace the store effectively destroying the current one and forcing it
|
| // to write its data to disk. Then we can see if after loading it again it
|
| // is still there.
|
| @@ -114,15 +113,14 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
|
| // Make sure we wait until the destructor has run.
|
| base::RunLoop().RunUntilIdle();
|
| store_ = new SQLiteServerBoundCertStore(
|
| - temp_dir_.path().Append(chrome::kOBCertFilename),
|
| - base::MessageLoopProxy::current(),
|
| - NULL);
|
| + temp_dir_.path().Append(kTestOBCertFilename),
|
| + base::MessageLoopProxy::current());
|
|
|
| // Reload and test for persistence
|
| Load(&certs);
|
| ASSERT_EQ(2U, certs.size());
|
| - net::DefaultServerBoundCertStore::ServerBoundCert* goog_cert;
|
| - net::DefaultServerBoundCertStore::ServerBoundCert* foo_cert;
|
| + DefaultServerBoundCertStore::ServerBoundCert* goog_cert;
|
| + DefaultServerBoundCertStore::ServerBoundCert* foo_cert;
|
| if (certs[0]->server_identifier() == "google.com") {
|
| goog_cert = certs[0];
|
| foo_cert = certs[1];
|
| @@ -149,9 +147,8 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
|
| base::RunLoop().RunUntilIdle();
|
| certs.clear();
|
| store_ = new SQLiteServerBoundCertStore(
|
| - temp_dir_.path().Append(chrome::kOBCertFilename),
|
| - base::MessageLoopProxy::current(),
|
| - NULL);
|
| + temp_dir_.path().Append(kTestOBCertFilename),
|
| + base::MessageLoopProxy::current());
|
|
|
| // Reload and check if the cert has been removed.
|
| Load(&certs);
|
| @@ -174,12 +171,12 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) {
|
| ASSERT_TRUE(db.Open(v1_db_path));
|
| ASSERT_TRUE(db.Execute(
|
| "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
|
| - "value LONGVARCHAR);"
|
| + "value LONGVARCHAR);"
|
| "INSERT INTO \"meta\" VALUES('version','1');"
|
| "INSERT INTO \"meta\" VALUES('last_compatible_version','1');"
|
| "CREATE TABLE origin_bound_certs ("
|
| - "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| - "private_key BLOB NOT NULL,cert BLOB NOT NULL);"));
|
| + "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| + "private_key BLOB NOT NULL,cert BLOB NOT NULL);"));
|
|
|
| sql::Statement add_smt(db.GetUniqueStatement(
|
| "INSERT INTO origin_bound_certs (origin, private_key, cert) "
|
| @@ -191,8 +188,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) {
|
|
|
| ASSERT_TRUE(db.Execute(
|
| "INSERT INTO \"origin_bound_certs\" VALUES("
|
| - "'foo.com',X'AA',X'BB');"
|
| - ));
|
| + "'foo.com',X'AA',X'BB');"));
|
| }
|
|
|
| // Load and test the DB contents twice. First time ensures that we can use
|
| @@ -201,9 +197,9 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) {
|
| for (int i = 0; i < 2; ++i) {
|
| SCOPED_TRACE(i);
|
|
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| - store_ = new SQLiteServerBoundCertStore(
|
| - v1_db_path, base::MessageLoopProxy::current(), NULL);
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + store_ = new SQLiteServerBoundCertStore(v1_db_path,
|
| + base::MessageLoopProxy::current());
|
|
|
| // Load the database. Because the existing v1 certs are implicitly of type
|
| // RSA, which is unsupported, they're discarded.
|
| @@ -242,15 +238,14 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) {
|
| ASSERT_TRUE(db.Open(v2_db_path));
|
| ASSERT_TRUE(db.Execute(
|
| "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
|
| - "value LONGVARCHAR);"
|
| + "value LONGVARCHAR);"
|
| "INSERT INTO \"meta\" VALUES('version','2');"
|
| "INSERT INTO \"meta\" VALUES('last_compatible_version','1');"
|
| "CREATE TABLE origin_bound_certs ("
|
| - "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| - "private_key BLOB NOT NULL,"
|
| - "cert BLOB NOT NULL,"
|
| - "cert_type INTEGER);"
|
| - ));
|
| + "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| + "private_key BLOB NOT NULL,"
|
| + "cert BLOB NOT NULL,"
|
| + "cert_type INTEGER);"));
|
|
|
| sql::Statement add_smt(db.GetUniqueStatement(
|
| "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type) "
|
| @@ -263,8 +258,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) {
|
|
|
| ASSERT_TRUE(db.Execute(
|
| "INSERT INTO \"origin_bound_certs\" VALUES("
|
| - "'foo.com',X'AA',X'BB',64);"
|
| - ));
|
| + "'foo.com',X'AA',X'BB',64);"));
|
| }
|
|
|
| // Load and test the DB contents twice. First time ensures that we can use
|
| @@ -273,17 +267,16 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) {
|
| for (int i = 0; i < 2; ++i) {
|
| SCOPED_TRACE(i);
|
|
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| - store_ = new SQLiteServerBoundCertStore(
|
| - v2_db_path, base::MessageLoopProxy::current(), NULL);
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + store_ = new SQLiteServerBoundCertStore(v2_db_path,
|
| + base::MessageLoopProxy::current());
|
|
|
| // Load the database and ensure the certs can be read.
|
| Load(&certs);
|
| ASSERT_EQ(2U, certs.size());
|
|
|
| ASSERT_EQ("google.com", certs[0]->server_identifier());
|
| - ASSERT_EQ(GetTestCertExpirationTime(),
|
| - certs[0]->expiration_time());
|
| + ASSERT_EQ(GetTestCertExpirationTime(), certs[0]->expiration_time());
|
| ASSERT_EQ(key_data, certs[0]->private_key());
|
| ASSERT_EQ(cert_data, certs[0]->cert());
|
|
|
| @@ -326,16 +319,15 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) {
|
| ASSERT_TRUE(db.Open(v3_db_path));
|
| ASSERT_TRUE(db.Execute(
|
| "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
|
| - "value LONGVARCHAR);"
|
| + "value LONGVARCHAR);"
|
| "INSERT INTO \"meta\" VALUES('version','3');"
|
| "INSERT INTO \"meta\" VALUES('last_compatible_version','1');"
|
| "CREATE TABLE origin_bound_certs ("
|
| - "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| - "private_key BLOB NOT NULL,"
|
| - "cert BLOB NOT NULL,"
|
| - "cert_type INTEGER,"
|
| - "expiration_time INTEGER);"
|
| - ));
|
| + "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| + "private_key BLOB NOT NULL,"
|
| + "cert BLOB NOT NULL,"
|
| + "cert_type INTEGER,"
|
| + "expiration_time INTEGER);"));
|
|
|
| sql::Statement add_smt(db.GetUniqueStatement(
|
| "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, "
|
| @@ -349,8 +341,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) {
|
|
|
| ASSERT_TRUE(db.Execute(
|
| "INSERT INTO \"origin_bound_certs\" VALUES("
|
| - "'foo.com',X'AA',X'BB',64,2000);"
|
| - ));
|
| + "'foo.com',X'AA',X'BB',64,2000);"));
|
| }
|
|
|
| // Load and test the DB contents twice. First time ensures that we can use
|
| @@ -359,9 +350,9 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) {
|
| for (int i = 0; i < 2; ++i) {
|
| SCOPED_TRACE(i);
|
|
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| - store_ = new SQLiteServerBoundCertStore(
|
| - v3_db_path, base::MessageLoopProxy::current(), NULL);
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + store_ = new SQLiteServerBoundCertStore(v3_db_path,
|
| + base::MessageLoopProxy::current());
|
|
|
| // Load the database and ensure the certs can be read.
|
| Load(&certs);
|
| @@ -369,8 +360,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) {
|
|
|
| ASSERT_EQ("google.com", certs[0]->server_identifier());
|
| ASSERT_EQ(1000, certs[0]->expiration_time().ToInternalValue());
|
| - ASSERT_EQ(GetTestCertCreationTime(),
|
| - certs[0]->creation_time());
|
| + ASSERT_EQ(GetTestCertCreationTime(), certs[0]->creation_time());
|
| ASSERT_EQ(key_data, certs[0]->private_key());
|
| ASSERT_EQ(cert_data, certs[0]->cert());
|
|
|
| @@ -414,17 +404,16 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestRSADiscarded) {
|
| ASSERT_TRUE(db.Open(v4_db_path));
|
| ASSERT_TRUE(db.Execute(
|
| "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
|
| - "value LONGVARCHAR);"
|
| + "value LONGVARCHAR);"
|
| "INSERT INTO \"meta\" VALUES('version','4');"
|
| "INSERT INTO \"meta\" VALUES('last_compatible_version','1');"
|
| "CREATE TABLE origin_bound_certs ("
|
| - "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| - "private_key BLOB NOT NULL,"
|
| - "cert BLOB NOT NULL,"
|
| - "cert_type INTEGER,"
|
| - "expiration_time INTEGER,"
|
| - "creation_time INTEGER);"
|
| - ));
|
| + "origin TEXT NOT NULL UNIQUE PRIMARY KEY,"
|
| + "private_key BLOB NOT NULL,"
|
| + "cert BLOB NOT NULL,"
|
| + "cert_type INTEGER,"
|
| + "expiration_time INTEGER,"
|
| + "creation_time INTEGER);"));
|
|
|
| sql::Statement add_smt(db.GetUniqueStatement(
|
| "INSERT INTO origin_bound_certs "
|
| @@ -452,9 +441,9 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestRSADiscarded) {
|
| ASSERT_TRUE(add_smt.Run());
|
| }
|
|
|
| - ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| - store_ = new SQLiteServerBoundCertStore(
|
| - v4_db_path, base::MessageLoopProxy::current(), NULL);
|
| + ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> certs;
|
| + store_ = new SQLiteServerBoundCertStore(v4_db_path,
|
| + base::MessageLoopProxy::current());
|
|
|
| // Load the database and ensure the certs can be read.
|
| Load(&certs);
|
| @@ -462,8 +451,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestRSADiscarded) {
|
| ASSERT_EQ(1U, certs.size());
|
|
|
| ASSERT_EQ("google.com", certs[0]->server_identifier());
|
| - ASSERT_EQ(GetTestCertExpirationTime(),
|
| - certs[0]->expiration_time());
|
| + ASSERT_EQ(GetTestCertExpirationTime(), certs[0]->expiration_time());
|
| ASSERT_EQ(key_data, certs[0]->private_key());
|
| ASSERT_EQ(cert_data, certs[0]->cert());
|
|
|
| @@ -471,3 +459,5 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestRSADiscarded) {
|
| // Make sure we wait until the destructor has run.
|
| base::RunLoop().RunUntilIdle();
|
| }
|
| +
|
| +} // namespace net
|
|
|