| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
| 6 |
| 7 #include <memory> |
| 5 #include <vector> | 8 #include <vector> |
| 6 | 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 13 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 14 #include "crypto/ec_private_key.h" | 17 #include "crypto/ec_private_key.h" |
| 15 #include "net/base/test_data_directory.h" | 18 #include "net/base/test_data_directory.h" |
| 16 #include "net/cert/asn1_util.h" | 19 #include "net/cert/asn1_util.h" |
| 17 #include "net/extras/sqlite/sqlite_channel_id_store.h" | |
| 18 #include "net/ssl/channel_id_service.h" | 20 #include "net/ssl/channel_id_service.h" |
| 19 #include "net/ssl/ssl_client_cert_type.h" | 21 #include "net/ssl/ssl_client_cert_type.h" |
| 20 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
| 21 #include "net/test/channel_id_test_util.h" | 23 #include "net/test/channel_id_test_util.h" |
| 22 #include "sql/statement.h" | 24 #include "sql/statement.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 25 namespace net { | 27 namespace net { |
| 26 | 28 |
| 27 const base::FilePath::CharType kTestChannelIDFilename[] = | 29 const base::FilePath::CharType kTestChannelIDFilename[] = |
| 28 FILE_PATH_LITERAL("ChannelID"); | 30 FILE_PATH_LITERAL("ChannelID"); |
| 29 | 31 |
| 30 class SQLiteChannelIDStoreTest : public testing::Test { | 32 class SQLiteChannelIDStoreTest : public testing::Test { |
| 31 public: | 33 public: |
| 32 void Load( | 34 void Load(std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>>* |
| 33 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids) { | 35 channel_ids) { |
| 34 base::RunLoop run_loop; | 36 base::RunLoop run_loop; |
| 35 store_->Load(base::Bind(&SQLiteChannelIDStoreTest::OnLoaded, | 37 store_->Load(base::Bind(&SQLiteChannelIDStoreTest::OnLoaded, |
| 36 base::Unretained(this), | 38 base::Unretained(this), |
| 37 &run_loop)); | 39 &run_loop)); |
| 38 run_loop.Run(); | 40 run_loop.Run(); |
| 39 channel_ids->swap(channel_ids_); | 41 channel_ids->swap(channel_ids_); |
| 40 channel_ids_.clear(); | 42 channel_ids_.clear(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void OnLoaded( | 45 void OnLoaded( |
| 44 base::RunLoop* run_loop, | 46 base::RunLoop* run_loop, |
| 45 scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>> | 47 std::unique_ptr<std::vector< |
| 46 channel_ids) { | 48 std::unique_ptr<DefaultChannelIDStore::ChannelID>>> channel_ids) { |
| 47 channel_ids_.swap(*channel_ids); | 49 channel_ids_.swap(*channel_ids); |
| 48 run_loop->Quit(); | 50 run_loop->Quit(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 protected: | 53 protected: |
| 52 static void ReadTestKeyAndCert(std::string* key_data, | 54 static void ReadTestKeyAndCert(std::string* key_data, |
| 53 std::string* cert_data, | 55 std::string* cert_data, |
| 54 scoped_ptr<crypto::ECPrivateKey>* key) { | 56 std::unique_ptr<crypto::ECPrivateKey>* key) { |
| 55 base::FilePath key_path = | 57 base::FilePath key_path = |
| 56 GetTestCertsDirectory().AppendASCII("unittest.originbound.key.der"); | 58 GetTestCertsDirectory().AppendASCII("unittest.originbound.key.der"); |
| 57 base::FilePath cert_path = | 59 base::FilePath cert_path = |
| 58 GetTestCertsDirectory().AppendASCII("unittest.originbound.der"); | 60 GetTestCertsDirectory().AppendASCII("unittest.originbound.der"); |
| 59 ASSERT_TRUE(base::ReadFileToString(key_path, key_data)); | 61 ASSERT_TRUE(base::ReadFileToString(key_path, key_data)); |
| 60 ASSERT_TRUE(base::ReadFileToString(cert_path, cert_data)); | 62 ASSERT_TRUE(base::ReadFileToString(cert_path, cert_data)); |
| 61 std::vector<uint8_t> private_key(key_data->size()); | 63 std::vector<uint8_t> private_key(key_data->size()); |
| 62 memcpy(private_key.data(), key_data->data(), key_data->size()); | 64 memcpy(private_key.data(), key_data->data(), key_data->size()); |
| 63 base::StringPiece spki; | 65 base::StringPiece spki; |
| 64 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(*cert_data, &spki)); | 66 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(*cert_data, &spki)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 exploded_time.second = 39; | 100 exploded_time.second = 39; |
| 99 exploded_time.millisecond = 0; | 101 exploded_time.millisecond = 0; |
| 100 return base::Time::FromUTCExploded(exploded_time); | 102 return base::Time::FromUTCExploded(exploded_time); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void SetUp() override { | 105 void SetUp() override { |
| 104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 106 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 105 store_ = new SQLiteChannelIDStore( | 107 store_ = new SQLiteChannelIDStore( |
| 106 temp_dir_.path().Append(kTestChannelIDFilename), | 108 temp_dir_.path().Append(kTestChannelIDFilename), |
| 107 base::ThreadTaskRunnerHandle::Get()); | 109 base::ThreadTaskRunnerHandle::Get()); |
| 108 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 110 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 109 Load(&channel_ids); | 111 Load(&channel_ids); |
| 110 ASSERT_EQ(0u, channel_ids.size()); | 112 ASSERT_EQ(0u, channel_ids.size()); |
| 111 // Make sure the store gets written at least once. | 113 // Make sure the store gets written at least once. |
| 112 google_key_.reset(crypto::ECPrivateKey::Create()); | 114 google_key_.reset(crypto::ECPrivateKey::Create()); |
| 113 store_->AddChannelID(DefaultChannelIDStore::ChannelID( | 115 store_->AddChannelID(DefaultChannelIDStore::ChannelID( |
| 114 "google.com", base::Time::FromInternalValue(1), | 116 "google.com", base::Time::FromInternalValue(1), |
| 115 make_scoped_ptr(google_key_->Copy()))); | 117 base::WrapUnique(google_key_->Copy()))); |
| 116 } | 118 } |
| 117 | 119 |
| 118 base::ScopedTempDir temp_dir_; | 120 base::ScopedTempDir temp_dir_; |
| 119 scoped_refptr<SQLiteChannelIDStore> store_; | 121 scoped_refptr<SQLiteChannelIDStore> store_; |
| 120 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids_; | 122 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids_; |
| 121 scoped_ptr<crypto::ECPrivateKey> google_key_; | 123 std::unique_ptr<crypto::ECPrivateKey> google_key_; |
| 122 }; | 124 }; |
| 123 | 125 |
| 124 // Test if data is stored as expected in the SQLite database. | 126 // Test if data is stored as expected in the SQLite database. |
| 125 TEST_F(SQLiteChannelIDStoreTest, TestPersistence) { | 127 TEST_F(SQLiteChannelIDStoreTest, TestPersistence) { |
| 126 scoped_ptr<crypto::ECPrivateKey> foo_key(crypto::ECPrivateKey::Create()); | 128 std::unique_ptr<crypto::ECPrivateKey> foo_key(crypto::ECPrivateKey::Create()); |
| 127 store_->AddChannelID(DefaultChannelIDStore::ChannelID( | 129 store_->AddChannelID(DefaultChannelIDStore::ChannelID( |
| 128 "foo.com", base::Time::FromInternalValue(3), | 130 "foo.com", base::Time::FromInternalValue(3), |
| 129 make_scoped_ptr(foo_key->Copy()))); | 131 base::WrapUnique(foo_key->Copy()))); |
| 130 | 132 |
| 131 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 133 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 132 // Replace the store effectively destroying the current one and forcing it | 134 // Replace the store effectively destroying the current one and forcing it |
| 133 // to write its data to disk. Then we can see if after loading it again it | 135 // to write its data to disk. Then we can see if after loading it again it |
| 134 // is still there. | 136 // is still there. |
| 135 store_ = NULL; | 137 store_ = NULL; |
| 136 // Make sure we wait until the destructor has run. | 138 // Make sure we wait until the destructor has run. |
| 137 base::RunLoop().RunUntilIdle(); | 139 base::RunLoop().RunUntilIdle(); |
| 138 store_ = | 140 store_ = |
| 139 new SQLiteChannelIDStore(temp_dir_.path().Append(kTestChannelIDFilename), | 141 new SQLiteChannelIDStore(temp_dir_.path().Append(kTestChannelIDFilename), |
| 140 base::ThreadTaskRunnerHandle::Get()); | 142 base::ThreadTaskRunnerHandle::Get()); |
| 141 | 143 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Close the store. | 177 // Close the store. |
| 176 store_ = NULL; | 178 store_ = NULL; |
| 177 // Make sure we wait until the destructor has run. | 179 // Make sure we wait until the destructor has run. |
| 178 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
| 179 } | 181 } |
| 180 | 182 |
| 181 // Test if data is stored as expected in the SQLite database. | 183 // Test if data is stored as expected in the SQLite database. |
| 182 TEST_F(SQLiteChannelIDStoreTest, TestDeleteAll) { | 184 TEST_F(SQLiteChannelIDStoreTest, TestDeleteAll) { |
| 183 store_->AddChannelID(DefaultChannelIDStore::ChannelID( | 185 store_->AddChannelID(DefaultChannelIDStore::ChannelID( |
| 184 "foo.com", base::Time::FromInternalValue(3), | 186 "foo.com", base::Time::FromInternalValue(3), |
| 185 make_scoped_ptr(crypto::ECPrivateKey::Create()))); | 187 base::WrapUnique(crypto::ECPrivateKey::Create()))); |
| 186 | 188 |
| 187 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 189 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 188 // Replace the store effectively destroying the current one and forcing it | 190 // Replace the store effectively destroying the current one and forcing it |
| 189 // to write its data to disk. Then we can see if after loading it again it | 191 // to write its data to disk. Then we can see if after loading it again it |
| 190 // is still there. | 192 // is still there. |
| 191 store_ = NULL; | 193 store_ = NULL; |
| 192 // Make sure we wait until the destructor has run. | 194 // Make sure we wait until the destructor has run. |
| 193 base::RunLoop().RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
| 194 store_ = | 196 store_ = |
| 195 new SQLiteChannelIDStore(temp_dir_.path().Append(kTestChannelIDFilename), | 197 new SQLiteChannelIDStore(temp_dir_.path().Append(kTestChannelIDFilename), |
| 196 base::ThreadTaskRunnerHandle::Get()); | 198 base::ThreadTaskRunnerHandle::Get()); |
| 197 | 199 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 224 } | 226 } |
| 225 | 227 |
| 226 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV1) { | 228 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV1) { |
| 227 // Reset the store. We'll be using a different database for this test. | 229 // Reset the store. We'll be using a different database for this test. |
| 228 store_ = NULL; | 230 store_ = NULL; |
| 229 | 231 |
| 230 base::FilePath v1_db_path(temp_dir_.path().AppendASCII("v1db")); | 232 base::FilePath v1_db_path(temp_dir_.path().AppendASCII("v1db")); |
| 231 | 233 |
| 232 std::string key_data; | 234 std::string key_data; |
| 233 std::string cert_data; | 235 std::string cert_data; |
| 234 scoped_ptr<crypto::ECPrivateKey> key; | 236 std::unique_ptr<crypto::ECPrivateKey> key; |
| 235 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); | 237 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); |
| 236 | 238 |
| 237 // Create a version 1 database. | 239 // Create a version 1 database. |
| 238 { | 240 { |
| 239 sql::Connection db; | 241 sql::Connection db; |
| 240 ASSERT_TRUE(db.Open(v1_db_path)); | 242 ASSERT_TRUE(db.Open(v1_db_path)); |
| 241 ASSERT_TRUE(db.Execute( | 243 ASSERT_TRUE(db.Execute( |
| 242 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," | 244 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 243 "value LONGVARCHAR);" | 245 "value LONGVARCHAR);" |
| 244 "INSERT INTO \"meta\" VALUES('version','1');" | 246 "INSERT INTO \"meta\" VALUES('version','1');" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 259 "INSERT INTO \"origin_bound_certs\" VALUES(" | 261 "INSERT INTO \"origin_bound_certs\" VALUES(" |
| 260 "'foo.com',X'AA',X'BB');")); | 262 "'foo.com',X'AA',X'BB');")); |
| 261 } | 263 } |
| 262 | 264 |
| 263 // Load and test the DB contents twice. First time ensures that we can use | 265 // Load and test the DB contents twice. First time ensures that we can use |
| 264 // the updated values immediately. Second time ensures that the updated | 266 // the updated values immediately. Second time ensures that the updated |
| 265 // values are stored and read correctly on next load. | 267 // values are stored and read correctly on next load. |
| 266 for (int i = 0; i < 2; ++i) { | 268 for (int i = 0; i < 2; ++i) { |
| 267 SCOPED_TRACE(i); | 269 SCOPED_TRACE(i); |
| 268 | 270 |
| 269 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 271 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 270 store_ = new SQLiteChannelIDStore(v1_db_path, | 272 store_ = new SQLiteChannelIDStore(v1_db_path, |
| 271 base::ThreadTaskRunnerHandle::Get()); | 273 base::ThreadTaskRunnerHandle::Get()); |
| 272 | 274 |
| 273 // Load the database. Because the existing v1 certs are implicitly of type | 275 // Load the database. Because the existing v1 certs are implicitly of type |
| 274 // RSA, which is unsupported, they're discarded. | 276 // RSA, which is unsupported, they're discarded. |
| 275 Load(&channel_ids); | 277 Load(&channel_ids); |
| 276 ASSERT_EQ(0U, channel_ids.size()); | 278 ASSERT_EQ(0U, channel_ids.size()); |
| 277 | 279 |
| 278 store_ = NULL; | 280 store_ = NULL; |
| 279 base::RunLoop().RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 292 } | 294 } |
| 293 | 295 |
| 294 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV2) { | 296 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV2) { |
| 295 // Reset the store. We'll be using a different database for this test. | 297 // Reset the store. We'll be using a different database for this test. |
| 296 store_ = NULL; | 298 store_ = NULL; |
| 297 | 299 |
| 298 base::FilePath v2_db_path(temp_dir_.path().AppendASCII("v2db")); | 300 base::FilePath v2_db_path(temp_dir_.path().AppendASCII("v2db")); |
| 299 | 301 |
| 300 std::string key_data; | 302 std::string key_data; |
| 301 std::string cert_data; | 303 std::string cert_data; |
| 302 scoped_ptr<crypto::ECPrivateKey> key; | 304 std::unique_ptr<crypto::ECPrivateKey> key; |
| 303 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); | 305 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); |
| 304 | 306 |
| 305 // Create a version 2 database. | 307 // Create a version 2 database. |
| 306 { | 308 { |
| 307 sql::Connection db; | 309 sql::Connection db; |
| 308 ASSERT_TRUE(db.Open(v2_db_path)); | 310 ASSERT_TRUE(db.Open(v2_db_path)); |
| 309 ASSERT_TRUE(db.Execute( | 311 ASSERT_TRUE(db.Execute( |
| 310 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," | 312 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 311 "value LONGVARCHAR);" | 313 "value LONGVARCHAR);" |
| 312 "INSERT INTO \"meta\" VALUES('version','2');" | 314 "INSERT INTO \"meta\" VALUES('version','2');" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 331 "INSERT INTO \"origin_bound_certs\" VALUES(" | 333 "INSERT INTO \"origin_bound_certs\" VALUES(" |
| 332 "'foo.com',X'AA',X'BB',64);")); | 334 "'foo.com',X'AA',X'BB',64);")); |
| 333 } | 335 } |
| 334 | 336 |
| 335 // Load and test the DB contents twice. First time ensures that we can use | 337 // Load and test the DB contents twice. First time ensures that we can use |
| 336 // the updated values immediately. Second time ensures that the updated | 338 // the updated values immediately. Second time ensures that the updated |
| 337 // values are saved and read correctly on next load. | 339 // values are saved and read correctly on next load. |
| 338 for (int i = 0; i < 2; ++i) { | 340 for (int i = 0; i < 2; ++i) { |
| 339 SCOPED_TRACE(i); | 341 SCOPED_TRACE(i); |
| 340 | 342 |
| 341 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 343 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 342 store_ = new SQLiteChannelIDStore(v2_db_path, | 344 store_ = new SQLiteChannelIDStore(v2_db_path, |
| 343 base::ThreadTaskRunnerHandle::Get()); | 345 base::ThreadTaskRunnerHandle::Get()); |
| 344 | 346 |
| 345 // Load the database and ensure the certs can be read. | 347 // Load the database and ensure the certs can be read. |
| 346 Load(&channel_ids); | 348 Load(&channel_ids); |
| 347 ASSERT_EQ(1U, channel_ids.size()); | 349 ASSERT_EQ(1U, channel_ids.size()); |
| 348 | 350 |
| 349 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); | 351 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); |
| 350 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); | 352 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); |
| 351 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); | 353 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 368 } | 370 } |
| 369 | 371 |
| 370 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV3) { | 372 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV3) { |
| 371 // Reset the store. We'll be using a different database for this test. | 373 // Reset the store. We'll be using a different database for this test. |
| 372 store_ = NULL; | 374 store_ = NULL; |
| 373 | 375 |
| 374 base::FilePath v3_db_path(temp_dir_.path().AppendASCII("v3db")); | 376 base::FilePath v3_db_path(temp_dir_.path().AppendASCII("v3db")); |
| 375 | 377 |
| 376 std::string key_data; | 378 std::string key_data; |
| 377 std::string cert_data; | 379 std::string cert_data; |
| 378 scoped_ptr<crypto::ECPrivateKey> key; | 380 std::unique_ptr<crypto::ECPrivateKey> key; |
| 379 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); | 381 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); |
| 380 | 382 |
| 381 // Create a version 3 database. | 383 // Create a version 3 database. |
| 382 { | 384 { |
| 383 sql::Connection db; | 385 sql::Connection db; |
| 384 ASSERT_TRUE(db.Open(v3_db_path)); | 386 ASSERT_TRUE(db.Open(v3_db_path)); |
| 385 ASSERT_TRUE(db.Execute( | 387 ASSERT_TRUE(db.Execute( |
| 386 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," | 388 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 387 "value LONGVARCHAR);" | 389 "value LONGVARCHAR);" |
| 388 "INSERT INTO \"meta\" VALUES('version','3');" | 390 "INSERT INTO \"meta\" VALUES('version','3');" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 409 "INSERT INTO \"origin_bound_certs\" VALUES(" | 411 "INSERT INTO \"origin_bound_certs\" VALUES(" |
| 410 "'foo.com',X'AA',X'BB',64,2000);")); | 412 "'foo.com',X'AA',X'BB',64,2000);")); |
| 411 } | 413 } |
| 412 | 414 |
| 413 // Load and test the DB contents twice. First time ensures that we can use | 415 // Load and test the DB contents twice. First time ensures that we can use |
| 414 // the updated values immediately. Second time ensures that the updated | 416 // the updated values immediately. Second time ensures that the updated |
| 415 // values are saved and read correctly on next load. | 417 // values are saved and read correctly on next load. |
| 416 for (int i = 0; i < 2; ++i) { | 418 for (int i = 0; i < 2; ++i) { |
| 417 SCOPED_TRACE(i); | 419 SCOPED_TRACE(i); |
| 418 | 420 |
| 419 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 421 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 420 store_ = new SQLiteChannelIDStore(v3_db_path, | 422 store_ = new SQLiteChannelIDStore(v3_db_path, |
| 421 base::ThreadTaskRunnerHandle::Get()); | 423 base::ThreadTaskRunnerHandle::Get()); |
| 422 | 424 |
| 423 // Load the database and ensure the certs can be read. | 425 // Load the database and ensure the certs can be read. |
| 424 Load(&channel_ids); | 426 Load(&channel_ids); |
| 425 ASSERT_EQ(1U, channel_ids.size()); | 427 ASSERT_EQ(1U, channel_ids.size()); |
| 426 | 428 |
| 427 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); | 429 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); |
| 428 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); | 430 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); |
| 429 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); | 431 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 446 } | 448 } |
| 447 | 449 |
| 448 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV4) { | 450 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV4) { |
| 449 // Reset the store. We'll be using a different database for this test. | 451 // Reset the store. We'll be using a different database for this test. |
| 450 store_ = NULL; | 452 store_ = NULL; |
| 451 | 453 |
| 452 base::FilePath v4_db_path(temp_dir_.path().AppendASCII("v4db")); | 454 base::FilePath v4_db_path(temp_dir_.path().AppendASCII("v4db")); |
| 453 | 455 |
| 454 std::string key_data; | 456 std::string key_data; |
| 455 std::string cert_data; | 457 std::string cert_data; |
| 456 scoped_ptr<crypto::ECPrivateKey> key; | 458 std::unique_ptr<crypto::ECPrivateKey> key; |
| 457 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); | 459 ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key)); |
| 458 | 460 |
| 459 // Create a version 4 database. | 461 // Create a version 4 database. |
| 460 { | 462 { |
| 461 sql::Connection db; | 463 sql::Connection db; |
| 462 ASSERT_TRUE(db.Open(v4_db_path)); | 464 ASSERT_TRUE(db.Open(v4_db_path)); |
| 463 ASSERT_TRUE(db.Execute( | 465 ASSERT_TRUE(db.Execute( |
| 464 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," | 466 "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," |
| 465 "value LONGVARCHAR);" | 467 "value LONGVARCHAR);" |
| 466 "INSERT INTO \"meta\" VALUES('version','4');" | 468 "INSERT INTO \"meta\" VALUES('version','4');" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 "INSERT INTO \"origin_bound_certs\" VALUES(" | 505 "INSERT INTO \"origin_bound_certs\" VALUES(" |
| 504 "'bar.com',X'AA',X'BB',64,2000,3000);")); | 506 "'bar.com',X'AA',X'BB',64,2000,3000);")); |
| 505 } | 507 } |
| 506 | 508 |
| 507 // Load and test the DB contents twice. First time ensures that we can use | 509 // Load and test the DB contents twice. First time ensures that we can use |
| 508 // the updated values immediately. Second time ensures that the updated | 510 // the updated values immediately. Second time ensures that the updated |
| 509 // values are saved and read correctly on next load. | 511 // values are saved and read correctly on next load. |
| 510 for (int i = 0; i < 2; ++i) { | 512 for (int i = 0; i < 2; ++i) { |
| 511 SCOPED_TRACE(i); | 513 SCOPED_TRACE(i); |
| 512 | 514 |
| 513 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; | 515 std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids; |
| 514 store_ = new SQLiteChannelIDStore(v4_db_path, | 516 store_ = new SQLiteChannelIDStore(v4_db_path, |
| 515 base::ThreadTaskRunnerHandle::Get()); | 517 base::ThreadTaskRunnerHandle::Get()); |
| 516 | 518 |
| 517 // Load the database and ensure the certs can be read. | 519 // Load the database and ensure the certs can be read. |
| 518 Load(&channel_ids); | 520 Load(&channel_ids); |
| 519 ASSERT_EQ(1U, channel_ids.size()); | 521 ASSERT_EQ(1U, channel_ids.size()); |
| 520 | 522 |
| 521 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); | 523 ASSERT_EQ("google.com", channel_ids[0]->server_identifier()); |
| 522 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); | 524 ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time()); |
| 523 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); | 525 EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key())); |
| 524 | 526 |
| 525 store_ = NULL; | 527 store_ = NULL; |
| 526 // Make sure we wait until the destructor has run. | 528 // Make sure we wait until the destructor has run. |
| 527 base::RunLoop().RunUntilIdle(); | 529 base::RunLoop().RunUntilIdle(); |
| 528 | 530 |
| 529 // Verify the database version is updated. | 531 // Verify the database version is updated. |
| 530 { | 532 { |
| 531 sql::Connection db; | 533 sql::Connection db; |
| 532 ASSERT_TRUE(db.Open(v4_db_path)); | 534 ASSERT_TRUE(db.Open(v4_db_path)); |
| 533 sql::Statement smt(db.GetUniqueStatement( | 535 sql::Statement smt(db.GetUniqueStatement( |
| 534 "SELECT value FROM meta WHERE key = \"version\"")); | 536 "SELECT value FROM meta WHERE key = \"version\"")); |
| 535 ASSERT_TRUE(smt.Step()); | 537 ASSERT_TRUE(smt.Step()); |
| 536 EXPECT_EQ(5, smt.ColumnInt(0)); | 538 EXPECT_EQ(5, smt.ColumnInt(0)); |
| 537 EXPECT_FALSE(smt.Step()); | 539 EXPECT_FALSE(smt.Step()); |
| 538 } | 540 } |
| 539 } | 541 } |
| 540 } | 542 } |
| 541 | 543 |
| 542 } // namespace net | 544 } // namespace net |
| OLD | NEW |