summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/protocol_parser_unittest.cc
diff options
context:
space:
mode:
authorbryner@chromium.org <bryner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 21:22:19 +0000
committerbryner@chromium.org <bryner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 21:22:19 +0000
commitce82c057bf25ea69aede1a546eff032ef3a79c45 (patch)
tree66921c8fcb6ff572d6e8628f816a0acdd21dd27d /chrome/browser/safe_browsing/protocol_parser_unittest.cc
parentc7ebcb98313a3726a45325c30e468bf8efd4b80f (diff)
downloadchromium_src-ce82c057bf25ea69aede1a546eff032ef3a79c45.zip
chromium_src-ce82c057bf25ea69aede1a546eff032ef3a79c45.tar.gz
chromium_src-ce82c057bf25ea69aede1a546eff032ef3a79c45.tar.bz2
Replace SafeBrowsing MAC with downloads over SSL.
BUG=119662 TEST=updated unittests, ran Chrome and verified SB functionality on new profile Review URL: http://codereview.chromium.org/10069031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/protocol_parser_unittest.cc')
-rw-r--r--chrome/browser/safe_browsing/protocol_parser_unittest.cc324
1 files changed, 31 insertions, 293 deletions
diff --git a/chrome/browser/safe_browsing/protocol_parser_unittest.cc b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
index 3f77a06..8b7abe3 100644
--- a/chrome/browser/safe_browsing/protocol_parser_unittest.cc
+++ b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
@@ -16,15 +16,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddChunk) {
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 3U);
@@ -69,15 +67,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddFullChunk) {
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 1U);
@@ -100,15 +96,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddChunks) {
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 2U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 3U);
@@ -162,15 +156,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddBigChunk) {
add_chunk.append(base::StringPrintf("001%d", i));
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
@@ -190,14 +182,12 @@ TEST(SafeBrowsingProtocolParsingTest, TestTruncatedBinHashChunk) {
// This chunk delares there are 4 prefixes but actually only contains 2.
const char add_chunk[] = "a:1:4:16\n11112222";
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(safe_browsing_util::kBinHashList,
add_chunk,
static_cast<int>(sizeof(add_chunk)),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_FALSE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 0U);
}
@@ -206,34 +196,30 @@ TEST(SafeBrowsingProtocolParsingTest, TestTruncatedUrlHashChunk) {
// This chunk delares there are 4 prefixes but actually only contains 2.
const char add_chunk[] = "a:1:4:21\naaaa\00411112222";
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
// For safe_browsing_util::kMalwareList.
bool result = parser.ParseChunk(safe_browsing_util::kMalwareList,
add_chunk,
static_cast<int>(sizeof(add_chunk)),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_FALSE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 0U);
// For safe_browsing_util::kPhishingList.
result = parser.ParseChunk(safe_browsing_util::kPhishingList,
add_chunk,
static_cast<int>(sizeof(add_chunk)),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_FALSE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 0U);
// For safe_browsing_util::kBinUrlList.
result = parser.ParseChunk(safe_browsing_util::kBinUrlList,
add_chunk,
static_cast<int>(sizeof(add_chunk)),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_FALSE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 0U);
}
@@ -246,15 +232,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestSubChunk) {
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
sub_chunk.data(),
static_cast<int>(sub_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 9);
EXPECT_EQ(chunks[0].hosts.size(), 3U);
@@ -307,15 +291,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestSubFullChunk) {
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
sub_chunk.data(),
static_cast<int>(sub_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 1U);
@@ -338,17 +320,14 @@ TEST(SafeBrowsingProtocolParsingTest, TestChunkDelete) {
SafeBrowsingProtocolParser parser;
int next_query_sec = 0;
- bool re_key = false;
bool reset = false;
std::vector<SBChunkDelete> deletes;
std::vector<ChunkUrl> urls;
EXPECT_TRUE(parser.ParseUpdate(add_del.data(),
- static_cast<int>(add_del.length()), "",
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
+ static_cast<int>(add_del.length()),
+ &next_query_sec, &reset, &deletes, &urls));
EXPECT_TRUE(urls.empty());
- EXPECT_FALSE(re_key);
EXPECT_FALSE(reset);
EXPECT_EQ(next_query_sec, 1700);
EXPECT_EQ(deletes.size(), 2U);
@@ -371,9 +350,8 @@ TEST(SafeBrowsingProtocolParsingTest, TestChunkDelete) {
urls.clear();
add_del = "n:1700\nad:1-7,43-597,44444,99999\ni:malware\nsd:4,21-27171717\n";
EXPECT_FALSE(parser.ParseUpdate(add_del.data(),
- static_cast<int>(add_del.length()), "",
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
+ static_cast<int>(add_del.length()),
+ &next_query_sec, &reset, &deletes, &urls));
}
// Test parsing the SafeBrowsing update response.
@@ -387,16 +365,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestRedirects) {
SafeBrowsingProtocolParser parser;
int next_query_sec = 0;
- bool re_key = false;
bool reset = false;
std::vector<SBChunkDelete> deletes;
std::vector<ChunkUrl> urls;
EXPECT_TRUE(parser.ParseUpdate(redirects.data(),
- static_cast<int>(redirects.length()), "",
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
+ static_cast<int>(redirects.length()),
+ &next_query_sec, &reset, &deletes, &urls));
- EXPECT_FALSE(re_key);
EXPECT_FALSE(reset);
EXPECT_EQ(urls.size(), 4U);
EXPECT_EQ(urls[0].url,
@@ -412,63 +387,19 @@ TEST(SafeBrowsingProtocolParsingTest, TestRedirects) {
EXPECT_TRUE(deletes.empty());
}
-TEST(SafeBrowsingProtocolParsingTest, TestRedirectsWithMac) {
- std::string redirects("m:IZhFUj0bMPBMsGw7MMA-VIzrNLg=\n"
- "i:goog-phish-shavar\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,"
- "pcY6iVeT9-CBQ3fdAF0rpnKjR1Y=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8001-8160:8001-8024,"
- "8026-8045,8048-8049,8051-8134,8136-8152,8155-8160,"
- "j6XXAEWnjYk9tVVLBSdQvIEq2Wg=\n");
-
- SafeBrowsingProtocolParser parser;
- int next_query_sec = 0;
- bool re_key = false;
- bool reset = false;
- const std::string key("58Lqn5WIP961x3zuLGo5Uw==");
- std::vector<SBChunkDelete> deletes;
- std::vector<ChunkUrl> urls;
-
- ASSERT_TRUE(parser.ParseUpdate(redirects.data(),
- static_cast<int>(redirects.length()), key,
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
-
- EXPECT_FALSE(re_key);
- EXPECT_FALSE(reset);
- EXPECT_EQ(urls.size(), 2U);
- EXPECT_EQ(urls[0].url,
- "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505");
- EXPECT_EQ(urls[0].mac, "pcY6iVeT9-CBQ3fdAF0rpnKjR1Y=");
- EXPECT_EQ(urls[1].url,
- "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8001-8160:8001-8024,"
- "8026-8045,8048-8049,8051-8134,8136-8152,8155-8160");
- EXPECT_EQ(urls[1].mac, "j6XXAEWnjYk9tVVLBSdQvIEq2Wg=");
-
- std::string bad_redirects = redirects;
- bad_redirects[0] = 'z';
- EXPECT_FALSE(parser.ParseUpdate(bad_redirects.data(),
- static_cast<int>(bad_redirects.length()), key,
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
-}
-
// Test parsing various SafeBrowsing protocol headers.
TEST(SafeBrowsingProtocolParsingTest, TestNextQueryTime) {
std::string headers("n:1800\ni:goog-white-shavar\n");
SafeBrowsingProtocolParser parser;
int next_query_sec = 0;
- bool re_key = false;
bool reset = false;
std::vector<SBChunkDelete> deletes;
std::vector<ChunkUrl> urls;
EXPECT_TRUE(parser.ParseUpdate(headers.data(),
- static_cast<int>(headers.length()), "",
- &next_query_sec, &re_key,
- &reset, &deletes, &urls));
+ static_cast<int>(headers.length()),
+ &next_query_sec, &reset, &deletes, &urls));
EXPECT_EQ(next_query_sec, 1800);
- EXPECT_FALSE(re_key);
EXPECT_FALSE(reset);
EXPECT_TRUE(deletes.empty());
EXPECT_TRUE(urls.empty());
@@ -481,14 +412,11 @@ TEST(SafeBrowsingProtocolParsingTest, TestGetHash) {
"00001111222233334444555566667777"
"ffffeeeeddddccccbbbbaaaa99998888");
std::vector<SBFullHashResult> full_hashes;
- bool re_key = false;
SafeBrowsingProtocolParser parser;
EXPECT_TRUE(parser.ParseGetHash(get_hash.data(),
- static_cast<int>(get_hash.length()), "",
- &re_key,
+ static_cast<int>(get_hash.length()),
&full_hashes));
- EXPECT_FALSE(re_key);
EXPECT_EQ(full_hashes.size(), 3U);
EXPECT_EQ(memcmp(&full_hashes[0].hash,
"00112233445566778899aabbccddeeff",
@@ -510,11 +438,9 @@ TEST(SafeBrowsingProtocolParsingTest, TestGetHash) {
"cafebeefcafebeefdeaddeaddeaddead"
"zzzzyyyyxxxxwwwwvvvvuuuuttttssss");
EXPECT_TRUE(parser.ParseGetHash(get_hash2.data(),
- static_cast<int>(get_hash2.length()), "",
- &re_key,
+ static_cast<int>(get_hash2.length()),
&full_hashes));
- EXPECT_FALSE(re_key);
EXPECT_EQ(full_hashes.size(), 3U);
EXPECT_EQ(memcmp(&full_hashes[0].hash,
"00112233445566778899aabbccddeeff",
@@ -530,55 +456,15 @@ TEST(SafeBrowsingProtocolParsingTest, TestGetHash) {
EXPECT_EQ(full_hashes[2].list_name, "goog-malware-shavar");
}
-TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) {
- const unsigned char get_hash[] = {
- 0x32, 0x56, 0x74, 0x6f, 0x6b, 0x36, 0x64, 0x41,
- 0x51, 0x72, 0x65, 0x51, 0x62, 0x38, 0x51, 0x68,
- 0x59, 0x45, 0x57, 0x51, 0x57, 0x4d, 0x52, 0x65,
- 0x42, 0x63, 0x41, 0x3d, 0x0a, 0x67, 0x6f, 0x6f,
- 0x67, 0x2d, 0x70, 0x68, 0x69, 0x73, 0x68, 0x2d,
- 0x73, 0x68, 0x61, 0x76, 0x61, 0x72, 0x3a, 0x36,
- 0x31, 0x36, 0x39, 0x3a, 0x33, 0x32, 0x0a, 0x17,
- 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9, 0x0b,
- 0x1c, 0x7b, 0x9d, 0xaf, 0x7b, 0x43, 0x99, 0x10,
- 0xc1, 0xab, 0xe3, 0x1b, 0x35, 0x80, 0x38, 0x96,
- 0xf9, 0x44, 0x4f, 0x28, 0xb4, 0xeb, 0x45
- };
-
- const unsigned char hash_result[] = {
- 0x17, 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9,
- 0x0b, 0x1c, 0x7b, 0x9d, 0xaf, 0x7b, 0x43, 0x99,
- 0x10, 0xc1, 0xab, 0xe3, 0x1b, 0x35, 0x80, 0x38,
- 0x96, 0xf9, 0x44, 0x4f, 0x28, 0xb4, 0xeb, 0x45
- };
-
- const std::string key = "58Lqn5WIP961x3zuLGo5Uw==";
- std::vector<SBFullHashResult> full_hashes;
- bool re_key = false;
- SafeBrowsingProtocolParser parser;
- EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash),
- sizeof(get_hash),
- key,
- &re_key,
- &full_hashes));
- EXPECT_FALSE(re_key);
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0);
-}
-
TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) {
std::string hash_response = "goog-phish-shavar:1:32\n"
"12345678901234567890123456789012"
"googpub-phish-shavar:19:32\n"
"09876543210987654321098765432109";
- bool re_key = false;
- std::string key = "";
std::vector<SBFullHashResult> full_hashes;
SafeBrowsingProtocolParser parser;
EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
hash_response.size(),
- key,
- &re_key,
&full_hashes));
EXPECT_EQ(full_hashes.size(), 1U);
@@ -592,8 +478,6 @@ TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) {
full_hashes.clear();
EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
hash_response.size(),
- key,
- &re_key,
&full_hashes));
EXPECT_EQ(full_hashes.size(), 2U);
@@ -620,50 +504,17 @@ TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) {
EXPECT_EQ(get_hash, "4:12\n1234abcdpqrs");
}
-TEST(SafeBrowsingProtocolParsingTest, TestGetKey) {
- SafeBrowsingProtocolParser parser;
- std::string key_response("clientkey:10:0123456789\n"
- "wrappedkey:20:abcdefghijklmnopqrst\n");
-
- std::string client_key, wrapped_key;
- EXPECT_TRUE(parser.ParseNewKey(key_response.data(),
- static_cast<int>(key_response.length()),
- &client_key,
- &wrapped_key));
-
- EXPECT_EQ(client_key, "0123456789");
- EXPECT_EQ(wrapped_key, "abcdefghijklmnopqrst");
-}
-
-TEST(SafeBrowsingProtocolParsingTest, TestReKey) {
- SafeBrowsingProtocolParser parser;
- std::string update("n:1800\ni:phishy\ne:pleaserekey\n");
-
- bool re_key = false;
- bool reset = false;
- int next_update = -1;
- std::vector<SBChunkDelete> deletes;
- std::vector<ChunkUrl> urls;
- EXPECT_TRUE(parser.ParseUpdate(update.data(),
- static_cast<int>(update.size()), "",
- &next_update, &re_key,
- &reset, &deletes, &urls));
- EXPECT_TRUE(re_key);
-}
-
TEST(SafeBrowsingProtocolParsingTest, TestReset) {
SafeBrowsingProtocolParser parser;
std::string update("n:1800\ni:phishy\nr:pleasereset\n");
- bool re_key = false;
bool reset = false;
int next_update = -1;
std::vector<SBChunkDelete> deletes;
std::vector<ChunkUrl> urls;
EXPECT_TRUE(parser.ParseUpdate(update.data(),
- static_cast<int>(update.size()), "",
- &next_update, &re_key,
- &reset, &deletes, &urls));
+ static_cast<int>(update.size()),
+ &next_update, &reset, &deletes, &urls));
EXPECT_TRUE(reset);
}
@@ -673,14 +524,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestReset) {
TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeAddChunk) {
std::string add_chunk("a:1:4:0\n");
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
@@ -695,7 +545,7 @@ TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeAddChunk) {
safe_browsing_util::kMalwareList,
add_chunks.data(),
static_cast<int>(add_chunks.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
EXPECT_EQ(chunks.size(), 3U);
@@ -720,14 +570,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeAddChunk) {
TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeSubChunk) {
std::string sub_chunk("s:9:4:0\n");
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kMalwareList,
sub_chunk.data(),
static_cast<int>(sub_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 9);
@@ -744,7 +593,7 @@ TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeSubChunk) {
safe_browsing_util::kMalwareList,
sub_chunks.data(),
static_cast<int>(sub_chunks.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
EXPECT_EQ(chunks[0].chunk_number, 1);
@@ -767,121 +616,18 @@ TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeSubChunk) {
EXPECT_EQ(chunks[2].hosts[1].entry->ChunkIdAtPrefix(0), 0x35363738);
}
-TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) {
- SafeBrowsingProtocolParser parser;
-
- const std::string update_body =
- "n:1895\n"
- "i:goog-phish-shavar\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,"
- "pcY6iVeT9-CBQ3fdAF0rpnKjR1Y=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6506-6510:6506-6510,"
- "SDBrYC3rX3KEPe72LOypnP6QYac=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6511-6520:6511-6520,"
- "9UQo-e7OkcsXT2wFWTAhOuWOsUs=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6521-6560:6521-6560,"
- "qVNw6JIpR1q6PIXST7J4LJ9n3Zg=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6561-6720:6561-6720,"
- "7OiJvCbiwvpzPITW-hQohY5NHuc=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6721-6880:6721-6880,"
- "oBS3svhoi9deIa0sWZ_gnD0ujj8=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6881-7040:6881-7040,"
- "a0r8Xit4VvH39xgyQHZTPczKBIE=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_7041-7200:7041-7163,"
- "q538LChutGknBw55s6kcE2wTcvU=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8001-8160:8001-8024,"
- "8026-8045,8048-8049,8051-8134,8136-8152,8155-8160,"
- "j6XXAEWnjYk9tVVLBSdQvIEq2Wg=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8161-8320:8161-8215,"
- "8217-8222,8224-8320,YaNfiqdQOt-uLCLWVLj46AZpAjQ=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8321-8480:8321-8391,"
- "8393-8399,8402,8404-8419,8421-8425,8427,8431-8433,8435-8439,8441-8443,"
- "8445-8446,8448-8480,ALj31GQMwGiIeU3bM2ZYKITfU-U=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8481-8640:8481-8500,"
- "8502-8508,8510-8511,8513-8517,8519-8525,8527-8531,8533,8536-8539,"
- "8541-8576,8578-8638,8640,TlQYRmS_kZ5PBAUIUyNQDq0Jprs=\n"
- "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8641-8800:8641-8689,"
- "8691-8731,8733-8786,x1Qf7hdNrO8b6yym03ZzNydDS1o=\n";
-
- const std::string update = "m:XIU0LiQhAPJq6dynXwHbygjS5tw=\n" + update_body;
-
- bool re_key = false;
- bool reset = false;
- int next_update = -1;
- std::vector<SBChunkDelete> deletes;
- std::vector<ChunkUrl> urls;
- const std::string key("58Lqn5WIP961x3zuLGo5Uw==");
-
- // Should pass with correct mac.
- ASSERT_TRUE(parser.ParseUpdate(update.data(),
- static_cast<int>(update.size()), key,
- &next_update, &re_key,
- &reset, &deletes, &urls));
- EXPECT_FALSE(re_key);
- EXPECT_EQ(next_update, 1895);
-
- // Should fail if mac is not present.
- EXPECT_FALSE(parser.ParseUpdate(update_body.data(),
- static_cast<int>(update_body.size()), key,
- &next_update, &re_key,
- &reset, &deletes, &urls));
-
- std::string bad_update = update;
- bad_update[1] = 'z';
- // Should fail if mac command isn't formatted correctly.
- EXPECT_FALSE(parser.ParseUpdate(bad_update.data(),
- static_cast<int>(bad_update.size()), key,
- &next_update, &re_key,
- &reset, &deletes, &urls));
-
- bad_update = update;
- bad_update[5] ^= 1;
- // Should fail if mac is incorrect.
- EXPECT_FALSE(parser.ParseUpdate(bad_update.data(),
- static_cast<int>(bad_update.size()), key,
- &next_update, &re_key,
- &reset, &deletes, &urls));
-
-}
-
-TEST(SafeBrowsingProtocolParsingTest, TestVerifyChunkMac) {
- SafeBrowsingProtocolParser parser;
-
- const unsigned char chunk[] = {
- 0x73, 0x3a, 0x32, 0x30, 0x30, 0x32, 0x3a, 0x34,
- 0x3a, 0x32, 0x32, 0x0a, 0x2f, 0x4f, 0x89, 0x7a,
- 0x01, 0x00, 0x00, 0x0a, 0x59, 0xc8, 0x71, 0xdf,
- 0x9d, 0x29, 0x0c, 0xba, 0xd7, 0x00, 0x00, 0x00,
- 0x0a, 0x59
- };
-
- bool re_key = false;
- SBChunkList chunks;
- const std::string key("v_aDSz6jI92WeHCOoZ07QA==");
- const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk=");
-
- EXPECT_TRUE(parser.ParseChunk(
- safe_browsing_util::kMalwareList,
- reinterpret_cast<const char*>(chunk),
- sizeof(chunk), key, mac,
- &re_key, &chunks));
- EXPECT_FALSE(re_key);
-}
-
TEST(SafeBrowsingProtocolParsingTest, TestAddBinHashChunks) {
std::string add_chunk("a:1:4:16\naaaabbbbccccdddd"
"a:2:4:8\n11112222");
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kBinHashList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 2U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 1U);
@@ -911,15 +657,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddBigBinHashChunk) {
add_chunk.append(base::StringPrintf("%04d", i));
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kBinHashList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
@@ -936,15 +680,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestSubBinHashChunk) {
// Run the parser.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kBinHashList,
sub_chunk.data(),
static_cast<int>(sub_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 9);
EXPECT_EQ(chunks[0].hosts.size(), 1U);
@@ -966,15 +708,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestAddDownloadWhitelistChunk) {
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
// Run the parse.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kDownloadWhiteList,
add_chunk.data(),
static_cast<int>(add_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
EXPECT_TRUE(result);
- EXPECT_FALSE(re_key);
EXPECT_EQ(chunks.size(), 2U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 1U);
@@ -1006,15 +746,13 @@ TEST(SafeBrowsingProtocolParsingTest, TestSubDownloadWhitelistChunk) {
// Run the parser.
SafeBrowsingProtocolParser parser;
- bool re_key = false;
SBChunkList chunks;
bool result = parser.ParseChunk(
safe_browsing_util::kDownloadWhiteList,
sub_chunk.data(),
static_cast<int>(sub_chunk.length()),
- "", "", &re_key, &chunks);
+ &chunks);
ASSERT_TRUE(result);
- EXPECT_FALSE(re_key);
ASSERT_EQ(chunks.size(), 1U);
EXPECT_EQ(chunks[0].chunk_number, 1);
EXPECT_EQ(chunks[0].hosts.size(), 1U);