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

Side by Side Diff: chrome/browser/net/sqlite_channel_id_store_unittest.cc

Issue 356713005: Rename ServerBoundCert => ChannelID to reflect the current name (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix cookies_list.js 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" 13 #include "chrome/browser/net/sqlite_channel_id_store.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "content/public/test/mock_special_storage_policy.h" 15 #include "content/public/test/mock_special_storage_policy.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/base/test_data_directory.h" 17 #include "net/base/test_data_directory.h"
18 #include "net/ssl/ssl_client_cert_type.h" 18 #include "net/ssl/ssl_client_cert_type.h"
19 #include "net/test/cert_test_util.h" 19 #include "net/test/cert_test_util.h"
20 #include "sql/statement.h" 20 #include "sql/statement.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 class SQLiteServerBoundCertStoreTest : public testing::Test { 23 class SQLiteChannelIDStoreTest : public testing::Test {
24 public: 24 public:
25 void Load( 25 void Load(
26 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>* certs) { 26 ScopedVector<net::DefaultChannelIDStore::ChannelID>* channel_ids) {
27 base::RunLoop run_loop; 27 base::RunLoop run_loop;
28 store_->Load(base::Bind(&SQLiteServerBoundCertStoreTest::OnLoaded, 28 store_->Load(base::Bind(&SQLiteChannelIDStoreTest::OnLoaded,
29 base::Unretained(this), 29 base::Unretained(this),
30 &run_loop)); 30 &run_loop));
31 run_loop.Run(); 31 run_loop.Run();
32 certs->swap(certs_); 32 channel_ids->swap(channel_ids_);
33 certs_.clear(); 33 channel_ids_.clear();
34 } 34 }
35 35
36 void OnLoaded( 36 void OnLoaded(
37 base::RunLoop* run_loop, 37 base::RunLoop* run_loop,
38 scoped_ptr<ScopedVector< 38 scoped_ptr<ScopedVector<
39 net::DefaultServerBoundCertStore::ServerBoundCert> > certs) { 39 net::DefaultChannelIDStore::ChannelID> > channel_ids) {
40 certs_.swap(*certs); 40 channel_ids_.swap(*channel_ids);
41 run_loop->Quit(); 41 run_loop->Quit();
42 } 42 }
43 43
44 protected: 44 protected:
45 static void ReadTestKeyAndCert(std::string* key, std::string* cert) { 45 static void ReadTestKeyAndCert(std::string* key, std::string* cert) {
46 base::FilePath key_path = net::GetTestCertsDirectory().AppendASCII( 46 base::FilePath key_path = net::GetTestCertsDirectory().AppendASCII(
47 "unittest.originbound.key.der"); 47 "unittest.originbound.key.der");
48 base::FilePath cert_path = net::GetTestCertsDirectory().AppendASCII( 48 base::FilePath cert_path = net::GetTestCertsDirectory().AppendASCII(
49 "unittest.originbound.der"); 49 "unittest.originbound.der");
50 ASSERT_TRUE(base::ReadFileToString(key_path, key)); 50 ASSERT_TRUE(base::ReadFileToString(key_path, key));
(...skipping 17 matching lines...) Expand all
68 exploded_time.day_of_month = 13; 68 exploded_time.day_of_month = 13;
69 exploded_time.hour = 2; 69 exploded_time.hour = 2;
70 exploded_time.minute = 23; 70 exploded_time.minute = 23;
71 exploded_time.second = 45; 71 exploded_time.second = 45;
72 exploded_time.millisecond = 0; 72 exploded_time.millisecond = 0;
73 return base::Time::FromUTCExploded(exploded_time); 73 return base::Time::FromUTCExploded(exploded_time);
74 } 74 }
75 75
76 virtual void SetUp() { 76 virtual void SetUp() {
77 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 77 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
78 store_ = new SQLiteServerBoundCertStore( 78 store_ = new SQLiteChannelIDStore(
79 temp_dir_.path().Append(chrome::kOBCertFilename), 79 temp_dir_.path().Append(chrome::kChannelIDFilename),
80 base::MessageLoopProxy::current(), 80 base::MessageLoopProxy::current(),
81 NULL); 81 NULL);
82 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 82 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
83 Load(&certs); 83 Load(&channel_ids);
84 ASSERT_EQ(0u, certs.size()); 84 ASSERT_EQ(0u, channel_ids.size());
85 // Make sure the store gets written at least once. 85 // Make sure the store gets written at least once.
86 store_->AddServerBoundCert( 86 store_->AddChannelID(
87 net::DefaultServerBoundCertStore::ServerBoundCert( 87 net::DefaultChannelIDStore::ChannelID(
88 "google.com", 88 "google.com",
89 base::Time::FromInternalValue(1), 89 base::Time::FromInternalValue(1),
90 base::Time::FromInternalValue(2), 90 base::Time::FromInternalValue(2),
91 "a", "b")); 91 "a", "b"));
92 } 92 }
93 93
94 content::TestBrowserThreadBundle thread_bundle_; 94 content::TestBrowserThreadBundle thread_bundle_;
95 base::ScopedTempDir temp_dir_; 95 base::ScopedTempDir temp_dir_;
96 scoped_refptr<SQLiteServerBoundCertStore> store_; 96 scoped_refptr<SQLiteChannelIDStore> store_;
97 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs_; 97 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids_;
98 }; 98 };
99 99
100 // Test if data is stored as expected in the SQLite database. 100 // Test if data is stored as expected in the SQLite database.
101 TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) { 101 TEST_F(SQLiteChannelIDStoreTest, TestPersistence) {
102 store_->AddServerBoundCert( 102 store_->AddChannelID(
103 net::DefaultServerBoundCertStore::ServerBoundCert( 103 net::DefaultChannelIDStore::ChannelID(
104 "foo.com", 104 "foo.com",
105 base::Time::FromInternalValue(3), 105 base::Time::FromInternalValue(3),
106 base::Time::FromInternalValue(4), 106 base::Time::FromInternalValue(4),
107 "c", "d")); 107 "c", "d"));
108 108
109 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 109 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
110 // Replace the store effectively destroying the current one and forcing it 110 // Replace the store effectively destroying the current one and forcing it
111 // to write its data to disk. Then we can see if after loading it again it 111 // to write its data to disk. Then we can see if after loading it again it
112 // is still there. 112 // is still there.
113 store_ = NULL; 113 store_ = NULL;
114 // Make sure we wait until the destructor has run. 114 // Make sure we wait until the destructor has run.
115 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
116 store_ = new SQLiteServerBoundCertStore( 116 store_ = new SQLiteChannelIDStore(
117 temp_dir_.path().Append(chrome::kOBCertFilename), 117 temp_dir_.path().Append(chrome::kChannelIDFilename),
118 base::MessageLoopProxy::current(), 118 base::MessageLoopProxy::current(),
119 NULL); 119 NULL);
120 120
121 // Reload and test for persistence 121 // Reload and test for persistence
122 Load(&certs); 122 Load(&channel_ids);
123 ASSERT_EQ(2U, certs.size()); 123 ASSERT_EQ(2U, channel_ids.size());
124 net::DefaultServerBoundCertStore::ServerBoundCert* goog_cert; 124 net::DefaultChannelIDStore::ChannelID* goog_channel_id;
125 net::DefaultServerBoundCertStore::ServerBoundCert* foo_cert; 125 net::DefaultChannelIDStore::ChannelID* foo_channel_id;
126 if (certs[0]->server_identifier() == "google.com") { 126 if (channel_ids[0]->server_identifier() == "google.com") {
127 goog_cert = certs[0]; 127 goog_channel_id = channel_ids[0];
128 foo_cert = certs[1]; 128 foo_channel_id = channel_ids[1];
129 } else { 129 } else {
130 goog_cert = certs[1]; 130 goog_channel_id = channel_ids[1];
131 foo_cert = certs[0]; 131 foo_channel_id = channel_ids[0];
132 } 132 }
133 ASSERT_EQ("google.com", goog_cert->server_identifier()); 133 ASSERT_EQ("google.com", goog_channel_id->server_identifier());
134 ASSERT_STREQ("a", goog_cert->private_key().c_str()); 134 ASSERT_STREQ("a", goog_channel_id->private_key().c_str());
135 ASSERT_STREQ("b", goog_cert->cert().c_str()); 135 ASSERT_STREQ("b", goog_channel_id->cert().c_str());
136 ASSERT_EQ(1, goog_cert->creation_time().ToInternalValue()); 136 ASSERT_EQ(1, goog_channel_id->creation_time().ToInternalValue());
137 ASSERT_EQ(2, goog_cert->expiration_time().ToInternalValue()); 137 ASSERT_EQ(2, goog_channel_id->expiration_time().ToInternalValue());
138 ASSERT_EQ("foo.com", foo_cert->server_identifier()); 138 ASSERT_EQ("foo.com", foo_channel_id->server_identifier());
139 ASSERT_STREQ("c", foo_cert->private_key().c_str()); 139 ASSERT_STREQ("c", foo_channel_id->private_key().c_str());
140 ASSERT_STREQ("d", foo_cert->cert().c_str()); 140 ASSERT_STREQ("d", foo_channel_id->cert().c_str());
141 ASSERT_EQ(3, foo_cert->creation_time().ToInternalValue()); 141 ASSERT_EQ(3, foo_channel_id->creation_time().ToInternalValue());
142 ASSERT_EQ(4, foo_cert->expiration_time().ToInternalValue()); 142 ASSERT_EQ(4, foo_channel_id->expiration_time().ToInternalValue());
143 143
144 // Now delete the cert and check persistence again. 144 // Now delete the cert and check persistence again.
145 store_->DeleteServerBoundCert(*certs[0]); 145 store_->DeleteChannelID(*channel_ids[0]);
146 store_->DeleteServerBoundCert(*certs[1]); 146 store_->DeleteChannelID(*channel_ids[1]);
147 store_ = NULL; 147 store_ = NULL;
148 // Make sure we wait until the destructor has run. 148 // Make sure we wait until the destructor has run.
149 base::RunLoop().RunUntilIdle(); 149 base::RunLoop().RunUntilIdle();
150 certs.clear(); 150 channel_ids.clear();
151 store_ = new SQLiteServerBoundCertStore( 151 store_ = new SQLiteChannelIDStore(
152 temp_dir_.path().Append(chrome::kOBCertFilename), 152 temp_dir_.path().Append(chrome::kChannelIDFilename),
153 base::MessageLoopProxy::current(), 153 base::MessageLoopProxy::current(),
154 NULL); 154 NULL);
155 155
156 // Reload and check if the cert has been removed. 156 // Reload and check if the cert has been removed.
157 Load(&certs); 157 Load(&channel_ids);
158 ASSERT_EQ(0U, certs.size()); 158 ASSERT_EQ(0U, channel_ids.size());
159 } 159 }
160 160
161 TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) { 161 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV1) {
162 // Reset the store. We'll be using a different database for this test. 162 // Reset the store. We'll be using a different database for this test.
163 store_ = NULL; 163 store_ = NULL;
164 164
165 base::FilePath v1_db_path(temp_dir_.path().AppendASCII("v1db")); 165 base::FilePath v1_db_path(temp_dir_.path().AppendASCII("v1db"));
166 166
167 std::string key_data; 167 std::string key_data;
168 std::string cert_data; 168 std::string cert_data;
169 ReadTestKeyAndCert(&key_data, &cert_data); 169 ReadTestKeyAndCert(&key_data, &cert_data);
170 170
171 // Create a version 1 database. 171 // Create a version 1 database.
(...skipping 22 matching lines...) Expand all
194 "'foo.com',X'AA',X'BB');" 194 "'foo.com',X'AA',X'BB');"
195 )); 195 ));
196 } 196 }
197 197
198 // Load and test the DB contents twice. First time ensures that we can use 198 // Load and test the DB contents twice. First time ensures that we can use
199 // the updated values immediately. Second time ensures that the updated 199 // the updated values immediately. Second time ensures that the updated
200 // values are stored and read correctly on next load. 200 // values are stored and read correctly on next load.
201 for (int i = 0; i < 2; ++i) { 201 for (int i = 0; i < 2; ++i) {
202 SCOPED_TRACE(i); 202 SCOPED_TRACE(i);
203 203
204 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 204 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
205 store_ = new SQLiteServerBoundCertStore( 205 store_ = new SQLiteChannelIDStore(
206 v1_db_path, base::MessageLoopProxy::current(), NULL); 206 v1_db_path, base::MessageLoopProxy::current(), NULL);
207 207
208 // Load the database. Because the existing v1 certs are implicitly of type 208 // Load the database. Because the existing v1 certs are implicitly of type
209 // RSA, which is unsupported, they're discarded. 209 // RSA, which is unsupported, they're discarded.
210 Load(&certs); 210 Load(&channel_ids);
211 ASSERT_EQ(0U, certs.size()); 211 ASSERT_EQ(0U, channel_ids.size());
212 212
213 store_ = NULL; 213 store_ = NULL;
214 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
215 215
216 // Verify the database version is updated. 216 // Verify the database version is updated.
217 { 217 {
218 sql::Connection db; 218 sql::Connection db;
219 ASSERT_TRUE(db.Open(v1_db_path)); 219 ASSERT_TRUE(db.Open(v1_db_path));
220 sql::Statement smt(db.GetUniqueStatement( 220 sql::Statement smt(db.GetUniqueStatement(
221 "SELECT value FROM meta WHERE key = \"version\"")); 221 "SELECT value FROM meta WHERE key = \"version\""));
222 ASSERT_TRUE(smt.Step()); 222 ASSERT_TRUE(smt.Step());
223 EXPECT_EQ(4, smt.ColumnInt(0)); 223 EXPECT_EQ(4, smt.ColumnInt(0));
224 EXPECT_FALSE(smt.Step()); 224 EXPECT_FALSE(smt.Step());
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) { 229 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV2) {
230 // Reset the store. We'll be using a different database for this test. 230 // Reset the store. We'll be using a different database for this test.
231 store_ = NULL; 231 store_ = NULL;
232 232
233 base::FilePath v2_db_path(temp_dir_.path().AppendASCII("v2db")); 233 base::FilePath v2_db_path(temp_dir_.path().AppendASCII("v2db"));
234 234
235 std::string key_data; 235 std::string key_data;
236 std::string cert_data; 236 std::string cert_data;
237 ReadTestKeyAndCert(&key_data, &cert_data); 237 ReadTestKeyAndCert(&key_data, &cert_data);
238 238
239 // Create a version 2 database. 239 // Create a version 2 database.
(...skipping 26 matching lines...) Expand all
266 "'foo.com',X'AA',X'BB',64);" 266 "'foo.com',X'AA',X'BB',64);"
267 )); 267 ));
268 } 268 }
269 269
270 // Load and test the DB contents twice. First time ensures that we can use 270 // Load and test the DB contents twice. First time ensures that we can use
271 // the updated values immediately. Second time ensures that the updated 271 // the updated values immediately. Second time ensures that the updated
272 // values are saved and read correctly on next load. 272 // values are saved and read correctly on next load.
273 for (int i = 0; i < 2; ++i) { 273 for (int i = 0; i < 2; ++i) {
274 SCOPED_TRACE(i); 274 SCOPED_TRACE(i);
275 275
276 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 276 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
277 store_ = new SQLiteServerBoundCertStore( 277 store_ = new SQLiteChannelIDStore(
278 v2_db_path, base::MessageLoopProxy::current(), NULL); 278 v2_db_path, base::MessageLoopProxy::current(), NULL);
279 279
280 // Load the database and ensure the certs can be read. 280 // Load the database and ensure the certs can be read.
281 Load(&certs); 281 Load(&channel_ids);
282 ASSERT_EQ(2U, certs.size()); 282 ASSERT_EQ(2U, channel_ids.size());
283 283
284 ASSERT_EQ("google.com", certs[0]->server_identifier()); 284 ASSERT_EQ("google.com", channel_ids[0]->server_identifier());
285 ASSERT_EQ(GetTestCertExpirationTime(), 285 ASSERT_EQ(GetTestCertExpirationTime(),
286 certs[0]->expiration_time()); 286 channel_ids[0]->expiration_time());
287 ASSERT_EQ(key_data, certs[0]->private_key()); 287 ASSERT_EQ(key_data, channel_ids[0]->private_key());
288 ASSERT_EQ(cert_data, certs[0]->cert()); 288 ASSERT_EQ(cert_data, channel_ids[0]->cert());
289 289
290 ASSERT_EQ("foo.com", certs[1]->server_identifier()); 290 ASSERT_EQ("foo.com", channel_ids[1]->server_identifier());
291 // Undecodable cert, expiration time will be uninitialized. 291 // Undecodable cert, expiration time will be uninitialized.
292 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); 292 ASSERT_EQ(base::Time(), channel_ids[1]->expiration_time());
293 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); 293 ASSERT_STREQ("\xaa", channel_ids[1]->private_key().c_str());
294 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); 294 ASSERT_STREQ("\xbb", channel_ids[1]->cert().c_str());
295 295
296 store_ = NULL; 296 store_ = NULL;
297 // Make sure we wait until the destructor has run. 297 // Make sure we wait until the destructor has run.
298 base::RunLoop().RunUntilIdle(); 298 base::RunLoop().RunUntilIdle();
299 299
300 // Verify the database version is updated. 300 // Verify the database version is updated.
301 { 301 {
302 sql::Connection db; 302 sql::Connection db;
303 ASSERT_TRUE(db.Open(v2_db_path)); 303 ASSERT_TRUE(db.Open(v2_db_path));
304 sql::Statement smt(db.GetUniqueStatement( 304 sql::Statement smt(db.GetUniqueStatement(
305 "SELECT value FROM meta WHERE key = \"version\"")); 305 "SELECT value FROM meta WHERE key = \"version\""));
306 ASSERT_TRUE(smt.Step()); 306 ASSERT_TRUE(smt.Step());
307 EXPECT_EQ(4, smt.ColumnInt(0)); 307 EXPECT_EQ(4, smt.ColumnInt(0));
308 EXPECT_FALSE(smt.Step()); 308 EXPECT_FALSE(smt.Step());
309 } 309 }
310 } 310 }
311 } 311 }
312 312
313 TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) { 313 TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV3) {
314 // Reset the store. We'll be using a different database for this test. 314 // Reset the store. We'll be using a different database for this test.
315 store_ = NULL; 315 store_ = NULL;
316 316
317 base::FilePath v3_db_path(temp_dir_.path().AppendASCII("v3db")); 317 base::FilePath v3_db_path(temp_dir_.path().AppendASCII("v3db"));
318 318
319 std::string key_data; 319 std::string key_data;
320 std::string cert_data; 320 std::string cert_data;
321 ReadTestKeyAndCert(&key_data, &cert_data); 321 ReadTestKeyAndCert(&key_data, &cert_data);
322 322
323 // Create a version 3 database. 323 // Create a version 3 database.
(...skipping 28 matching lines...) Expand all
352 "'foo.com',X'AA',X'BB',64,2000);" 352 "'foo.com',X'AA',X'BB',64,2000);"
353 )); 353 ));
354 } 354 }
355 355
356 // Load and test the DB contents twice. First time ensures that we can use 356 // Load and test the DB contents twice. First time ensures that we can use
357 // the updated values immediately. Second time ensures that the updated 357 // the updated values immediately. Second time ensures that the updated
358 // values are saved and read correctly on next load. 358 // values are saved and read correctly on next load.
359 for (int i = 0; i < 2; ++i) { 359 for (int i = 0; i < 2; ++i) {
360 SCOPED_TRACE(i); 360 SCOPED_TRACE(i);
361 361
362 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 362 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
363 store_ = new SQLiteServerBoundCertStore( 363 store_ = new SQLiteChannelIDStore(
364 v3_db_path, base::MessageLoopProxy::current(), NULL); 364 v3_db_path, base::MessageLoopProxy::current(), NULL);
365 365
366 // Load the database and ensure the certs can be read. 366 // Load the database and ensure the certs can be read.
367 Load(&certs); 367 Load(&channel_ids);
368 ASSERT_EQ(2U, certs.size()); 368 ASSERT_EQ(2U, channel_ids.size());
369 369
370 ASSERT_EQ("google.com", certs[0]->server_identifier()); 370 ASSERT_EQ("google.com", channel_ids[0]->server_identifier());
371 ASSERT_EQ(1000, certs[0]->expiration_time().ToInternalValue()); 371 ASSERT_EQ(1000, channel_ids[0]->expiration_time().ToInternalValue());
372 ASSERT_EQ(GetTestCertCreationTime(), 372 ASSERT_EQ(GetTestCertCreationTime(),
373 certs[0]->creation_time()); 373 channel_ids[0]->creation_time());
374 ASSERT_EQ(key_data, certs[0]->private_key()); 374 ASSERT_EQ(key_data, channel_ids[0]->private_key());
375 ASSERT_EQ(cert_data, certs[0]->cert()); 375 ASSERT_EQ(cert_data, channel_ids[0]->cert());
376 376
377 ASSERT_EQ("foo.com", certs[1]->server_identifier()); 377 ASSERT_EQ("foo.com", channel_ids[1]->server_identifier());
378 ASSERT_EQ(2000, certs[1]->expiration_time().ToInternalValue()); 378 ASSERT_EQ(2000, channel_ids[1]->expiration_time().ToInternalValue());
379 // Undecodable cert, creation time will be uninitialized. 379 // Undecodable cert, creation time will be uninitialized.
380 ASSERT_EQ(base::Time(), certs[1]->creation_time()); 380 ASSERT_EQ(base::Time(), channel_ids[1]->creation_time());
381 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); 381 ASSERT_STREQ("\xaa", channel_ids[1]->private_key().c_str());
382 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); 382 ASSERT_STREQ("\xbb", channel_ids[1]->cert().c_str());
383 383
384 store_ = NULL; 384 store_ = NULL;
385 // Make sure we wait until the destructor has run. 385 // Make sure we wait until the destructor has run.
386 base::RunLoop().RunUntilIdle(); 386 base::RunLoop().RunUntilIdle();
387 387
388 // Verify the database version is updated. 388 // Verify the database version is updated.
389 { 389 {
390 sql::Connection db; 390 sql::Connection db;
391 ASSERT_TRUE(db.Open(v3_db_path)); 391 ASSERT_TRUE(db.Open(v3_db_path));
392 sql::Statement smt(db.GetUniqueStatement( 392 sql::Statement smt(db.GetUniqueStatement(
393 "SELECT value FROM meta WHERE key = \"version\"")); 393 "SELECT value FROM meta WHERE key = \"version\""));
394 ASSERT_TRUE(smt.Step()); 394 ASSERT_TRUE(smt.Step());
395 EXPECT_EQ(4, smt.ColumnInt(0)); 395 EXPECT_EQ(4, smt.ColumnInt(0));
396 EXPECT_FALSE(smt.Step()); 396 EXPECT_FALSE(smt.Step());
397 } 397 }
398 } 398 }
399 } 399 }
400 400
401 TEST_F(SQLiteServerBoundCertStoreTest, TestRSADiscarded) { 401 TEST_F(SQLiteChannelIDStoreTest, TestRSADiscarded) {
402 // Reset the store. We'll be using a different database for this test. 402 // Reset the store. We'll be using a different database for this test.
403 store_ = NULL; 403 store_ = NULL;
404 404
405 base::FilePath v4_db_path(temp_dir_.path().AppendASCII("v4dbrsa")); 405 base::FilePath v4_db_path(temp_dir_.path().AppendASCII("v4dbrsa"));
406 406
407 std::string key_data; 407 std::string key_data;
408 std::string cert_data; 408 std::string cert_data;
409 ReadTestKeyAndCert(&key_data, &cert_data); 409 ReadTestKeyAndCert(&key_data, &cert_data);
410 410
411 // Create a version 4 database with a mix of RSA and ECDSA certs. 411 // Create a version 4 database with a mix of RSA and ECDSA certs.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 " VALUES (?,?,?,?,?,?)")); 445 " VALUES (?,?,?,?,?,?)"));
446 add_smt.BindString(0, "foo.com"); 446 add_smt.BindString(0, "foo.com");
447 add_smt.BindBlob(1, key_data.data(), key_data.size()); 447 add_smt.BindBlob(1, key_data.data(), key_data.size());
448 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); 448 add_smt.BindBlob(2, cert_data.data(), cert_data.size());
449 add_smt.BindInt64(3, 1); 449 add_smt.BindInt64(3, 1);
450 add_smt.BindInt64(4, GetTestCertExpirationTime().ToInternalValue()); 450 add_smt.BindInt64(4, GetTestCertExpirationTime().ToInternalValue());
451 add_smt.BindInt64(5, base::Time::Now().ToInternalValue()); 451 add_smt.BindInt64(5, base::Time::Now().ToInternalValue());
452 ASSERT_TRUE(add_smt.Run()); 452 ASSERT_TRUE(add_smt.Run());
453 } 453 }
454 454
455 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 455 ScopedVector<net::DefaultChannelIDStore::ChannelID> channel_ids;
456 store_ = new SQLiteServerBoundCertStore( 456 store_ = new SQLiteChannelIDStore(
457 v4_db_path, base::MessageLoopProxy::current(), NULL); 457 v4_db_path, base::MessageLoopProxy::current(), NULL);
458 458
459 // Load the database and ensure the certs can be read. 459 // Load the database and ensure the certs can be read.
460 Load(&certs); 460 Load(&channel_ids);
461 // Only the ECDSA cert (for google.com) is read, the RSA one is discarded. 461 // Only the ECDSA cert (for google.com) is read, the RSA one is discarded.
462 ASSERT_EQ(1U, certs.size()); 462 ASSERT_EQ(1U, channel_ids.size());
463 463
464 ASSERT_EQ("google.com", certs[0]->server_identifier()); 464 ASSERT_EQ("google.com", channel_ids[0]->server_identifier());
465 ASSERT_EQ(GetTestCertExpirationTime(), 465 ASSERT_EQ(GetTestCertExpirationTime(),
466 certs[0]->expiration_time()); 466 channel_ids[0]->expiration_time());
467 ASSERT_EQ(key_data, certs[0]->private_key()); 467 ASSERT_EQ(key_data, channel_ids[0]->private_key());
468 ASSERT_EQ(cert_data, certs[0]->cert()); 468 ASSERT_EQ(cert_data, channel_ids[0]->cert());
469 469
470 store_ = NULL; 470 store_ = NULL;
471 // Make sure we wait until the destructor has run. 471 // Make sure we wait until the destructor has run.
472 base::RunLoop().RunUntilIdle(); 472 base::RunLoop().RunUntilIdle();
473 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698