From 33d7a61fdb081adb26475c5785ce3a79e31f4af0 Mon Sep 17 00:00:00 2001 From: Jakob Kuki Date: Mon, 3 Jun 2019 14:18:54 -0700 Subject: [PATCH] Change sqlite index to correct column Add schema to query string Fixes brave/brave-browser#4663 --- .../browser/publisher_info_database.cc | 12 +-- .../publisher_info_database_unittest.cc | 86 +++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/components/brave_rewards/browser/publisher_info_database.cc b/components/brave_rewards/browser/publisher_info_database.cc index d83579963569..cc79589d68a1 100644 --- a/components/brave_rewards/browser/publisher_info_database.cc +++ b/components/brave_rewards/browser/publisher_info_database.cc @@ -748,7 +748,9 @@ bool PublisherInfoDatabase::GetExcludedList( } // We will use every attribute from publisher_info - std::string query = "SELECT * FROM publisher_info WHERE excluded = 1"; + std::string query = "SELECT publisher_id, verified, name," + "favicon, url, provider " + "FROM publisher_info WHERE excluded = 1"; sql::Statement info_sql(db_.GetUniqueStatement(query.c_str())); @@ -758,10 +760,10 @@ bool PublisherInfoDatabase::GetExcludedList( auto info = ledger::PublisherInfo::New(); info->id = info_sql.ColumnString(0); info->verified = info_sql.ColumnBool(1); - info->name = info_sql.ColumnString(3); - info->favicon_url = info_sql.ColumnString(4); - info->url = info_sql.ColumnString(5); - info->provider = info_sql.ColumnString(9); + info->name = info_sql.ColumnString(2); + info->favicon_url = info_sql.ColumnString(3); + info->url = info_sql.ColumnString(4); + info->provider = info_sql.ColumnString(5); list->push_back(std::move(info)); } diff --git a/components/brave_rewards/browser/publisher_info_database_unittest.cc b/components/brave_rewards/browser/publisher_info_database_unittest.cc index d05f6317fd52..3bbfaf943206 100644 --- a/components/brave_rewards/browser/publisher_info_database_unittest.cc +++ b/components/brave_rewards/browser/publisher_info_database_unittest.cc @@ -287,6 +287,92 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdatePublisherInfo) { EXPECT_FALSE(info_sql_4.Step()); } +TEST_F(PublisherInfoDatabaseTest, GetExcludedList) { + /** + * Good path + */ + base::ScopedTempDir temp_dir; + base::FilePath db_file; + CreateTempDatabase(&temp_dir, &db_file); + + std::string excluded_id = "ABCD"; + bool excluded_verified = false; + ledger::PUBLISHER_EXCLUDE excluded = ledger::PUBLISHER_EXCLUDE::EXCLUDED; + std::string excluded_name = "excluded_publisher"; + std::string excluded_url = "https://iamexcluded.com"; + std::string excluded_provider = "exclusion"; + std::string excluded_favicon = "0"; + + std::string included_id = "EFGH"; + bool included_verified = false; + ledger::PUBLISHER_EXCLUDE included = ledger::PUBLISHER_EXCLUDE::INCLUDED; + std::string included_name = "included_publisher"; + std::string included_url = "https://iamincluded.com"; + std::string included_provider = "inclusion"; + std::string included_favicon = "1"; + + /** + * Insert Excluded Publisher + */ + ledger::PublisherInfo info; + info.id = excluded_id; + info.verified = excluded_verified; + info.excluded = excluded; + info.name = excluded_name; + info.url = excluded_url; + info.provider = excluded_provider; + info.favicon_url = excluded_favicon; + + bool success = publisher_info_database_->InsertOrUpdateActivityInfo(info); + EXPECT_TRUE(success); + + /** + * Insert Included Publisher + */ + info.id = included_id; + info.verified = included_verified; + info.excluded = included; + info.name = included_name; + info.url = included_url; + info.provider = included_provider; + info.favicon_url = included_favicon; + + success = publisher_info_database_->InsertOrUpdateActivityInfo(info); + EXPECT_TRUE(success); + /** + * Check Excluded List is correct + */ + ledger::PublisherInfoList pub_list; + success = publisher_info_database_->GetExcludedList(&pub_list); + EXPECT_TRUE(success); + EXPECT_EQ(1UL, pub_list.size()); + + ASSERT_EQ(pub_list.at(0)->id, excluded_id); + ASSERT_EQ(pub_list.at(0)->verified, excluded_verified); + ASSERT_EQ(pub_list.at(0)->name, excluded_name); + ASSERT_EQ(pub_list.at(0)->url, excluded_url); + ASSERT_EQ(pub_list.at(0)->provider, excluded_provider); + ASSERT_EQ(pub_list.at(0)->favicon_url, excluded_favicon); + pub_list.clear(); + + /** + * Check Included List is correct + */ + ledger::ActivityInfoFilter filter; + filter.excluded = ledger::EXCLUDE_FILTER::FILTER_INCLUDED; + success = publisher_info_database_->GetActivityList(0, 0, filter, &pub_list); + EXPECT_TRUE(success); + EXPECT_EQ(1UL, pub_list.size()); + + + ASSERT_EQ(pub_list.at(0)->id, included_id); + ASSERT_EQ(pub_list.at(0)->verified, included_verified); + ASSERT_EQ(pub_list.at(0)->name, included_name); + ASSERT_EQ(pub_list.at(0)->url, included_url); + ASSERT_EQ(pub_list.at(0)->provider, included_provider); + ASSERT_EQ(pub_list.at(0)->favicon_url, included_favicon); +} + TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) { /** * Good path