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

Unified Diff: net/extras/sqlite/sqlite_channel_id_store_unittest.cc

Issue 2798743002: Migrate SQLiteChannelIDStore away from using deprecated ECPrivateKey functions (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « net/extras/sqlite/sqlite_channel_id_store.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/extras/sqlite/sqlite_channel_id_store_unittest.cc
diff --git a/net/extras/sqlite/sqlite_channel_id_store_unittest.cc b/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
index 7c9b223e3e12757e35c20aa8c3a552caa51b0a3b..87f6083cd36d2272f93acca722703985ae26cdd0 100644
--- a/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
+++ b/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
@@ -288,7 +288,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV1) {
sql::Statement smt(db.GetUniqueStatement(
"SELECT value FROM meta WHERE key = \"version\""));
ASSERT_TRUE(smt.Step());
- EXPECT_EQ(5, smt.ColumnInt(0));
+ EXPECT_EQ(6, smt.ColumnInt(0));
EXPECT_FALSE(smt.Step());
}
}
@@ -364,7 +364,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV2) {
sql::Statement smt(db.GetUniqueStatement(
"SELECT value FROM meta WHERE key = \"version\""));
ASSERT_TRUE(smt.Step());
- EXPECT_EQ(5, smt.ColumnInt(0));
+ EXPECT_EQ(6, smt.ColumnInt(0));
EXPECT_FALSE(smt.Step());
}
}
@@ -442,7 +442,7 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV3) {
sql::Statement smt(db.GetUniqueStatement(
"SELECT value FROM meta WHERE key = \"version\""));
ASSERT_TRUE(smt.Step());
- EXPECT_EQ(5, smt.ColumnInt(0));
+ EXPECT_EQ(6, smt.ColumnInt(0));
EXPECT_FALSE(smt.Step());
}
}
@@ -536,7 +536,83 @@ TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV4) {
sql::Statement smt(db.GetUniqueStatement(
"SELECT value FROM meta WHERE key = \"version\""));
ASSERT_TRUE(smt.Step());
- EXPECT_EQ(5, smt.ColumnInt(0));
+ EXPECT_EQ(6, smt.ColumnInt(0));
+ EXPECT_FALSE(smt.Step());
+ }
+ }
+}
+
+TEST_F(SQLiteChannelIDStoreTest, TestUpgradeV5) {
+ // Reset the store. We'll be using a different database for this test.
+ store_ = NULL;
+
+ base::FilePath v5_db_path(temp_dir_.GetPath().AppendASCII("v5db"));
+
+ std::string key_data;
+ std::string cert_data;
+ std::unique_ptr<crypto::ECPrivateKey> key;
+ ASSERT_NO_FATAL_FAILURE(ReadTestKeyAndCert(&key_data, &cert_data, &key));
+
+ // Create a version 5 database.
+ {
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(v5_db_path));
+ ASSERT_TRUE(db.Execute(
+ "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
+ "value LONGVARCHAR);"
+ "INSERT INTO \"meta\" VALUES('version','5');"
+ "INSERT INTO \"meta\" VALUES('last_compatible_version','5');"
+ "CREATE TABLE channel_id ("
+ "host TEXT NOT NULL UNIQUE PRIMARY KEY,"
+ "private_key BLOB NOT NULL,"
+ "public_key BLOB NOT NULL,"
+ "creation_time INTEGER);"));
+
+ sql::Statement add_smt(db.GetUniqueStatement(
+ "INSERT INTO channel_id (host, private_key, public_key, creation_time) "
+ "VALUES (?,?,?,?)"));
+ add_smt.BindString(0, "google.com");
+ add_smt.BindBlob(1, key_data.data(), key_data.size());
+ add_smt.BindBlob(2, "", 0);
+ add_smt.BindInt64(3, GetTestCertCreationTime().ToInternalValue());
+ ASSERT_TRUE(add_smt.Run());
+
+ // Malformed keys will be ignored and not migrated.
+ ASSERT_TRUE(
+ db.Execute("INSERT INTO \"channel_id\" VALUES("
+ "'bar.com',X'AA',X'BB',3000);"));
+ }
+
+ // Load and test the DB contents twice. First time ensures that we can use
+ // the updated values immediately. Second time ensures that the updated
+ // values are saved and read correctly on next load.
+ for (int i = 0; i < 2; ++i) {
+ SCOPED_TRACE(i);
+
+ std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>> channel_ids;
+ store_ = new SQLiteChannelIDStore(v5_db_path,
+ base::ThreadTaskRunnerHandle::Get());
+
+ // Load the database and ensure the certs can be read.
+ Load(&channel_ids);
+ ASSERT_EQ(1U, channel_ids.size());
+
+ ASSERT_EQ("google.com", channel_ids[0]->server_identifier());
+ ASSERT_EQ(GetTestCertCreationTime(), channel_ids[0]->creation_time());
+ EXPECT_TRUE(KeysEqual(key.get(), channel_ids[0]->key()));
+
+ store_ = NULL;
+ // Make sure we wait until the destructor has run.
+ base::RunLoop().RunUntilIdle();
+
+ // Verify the database version is updated.
+ {
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(v5_db_path));
+ sql::Statement smt(db.GetUniqueStatement(
+ "SELECT value FROM meta WHERE key = \"version\""));
+ ASSERT_TRUE(smt.Step());
+ EXPECT_EQ(6, smt.ColumnInt(0));
EXPECT_FALSE(smt.Step());
}
}
« no previous file with comments | « net/extras/sqlite/sqlite_channel_id_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698