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

Side by Side Diff: chrome/browser/safe_browsing/protocol_parser_unittest.cc

Issue 582143002: Safebrowsing: Fix failure parsing a gethash result with bad listname and metadata. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add todo Created 6 years, 3 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
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/safe_browsing/protocol_parser.h" 9 #include "chrome/browser/safe_browsing/protocol_parser.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 10 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 EXPECT_EQ(2U, full_hashes.size()); 502 EXPECT_EQ(2U, full_hashes.size());
503 EXPECT_EQ(memcmp("12345678901234567890123456789012", 503 EXPECT_EQ(memcmp("12345678901234567890123456789012",
504 &full_hashes[0].hash, sizeof(SBFullHash)), 0); 504 &full_hashes[0].hash, sizeof(SBFullHash)), 0);
505 EXPECT_EQ(safe_browsing_util::PHISH, full_hashes[0].list_id); 505 EXPECT_EQ(safe_browsing_util::PHISH, full_hashes[0].list_id);
506 EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457", 506 EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457",
507 &full_hashes[1].hash, sizeof(SBFullHash)), 0); 507 &full_hashes[1].hash, sizeof(SBFullHash)), 0);
508 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id); 508 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id);
509 } 509 }
510 510
511 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownListAndMetadata) {
512 std::vector<SBFullHashResult> full_hashes;
513 base::TimeDelta cache_lifetime;
514 // Test skipping over a hashentry with an unrecognized listname that also has
515 // metadata.
516 const std::string get_hash3(base::StringPrintf(
517 "600\n"
518 "BADLISTNAME:32:1:m\n"
519 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
520 "8\nMETADATA"
521 "%s:32:1\n"
522 "0123456789hashhashhashhashhashha",
523 kDefaultMalwareList));
524 EXPECT_TRUE(safe_browsing::ParseGetHash(get_hash3.data(), get_hash3.length(),
525 &cache_lifetime, &full_hashes));
526 ASSERT_EQ(1U, full_hashes.size());
527 EXPECT_EQ(memcmp(&full_hashes[0].hash,
528 "0123456789hashhashhashhashhashha",
529 sizeof(SBFullHash)), 0);
530 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[0].list_id);
531 }
532
511 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { 533 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) {
512 std::vector<SBPrefix> prefixes; 534 std::vector<SBPrefix> prefixes;
513 prefixes.push_back(0x34333231); 535 prefixes.push_back(0x34333231);
514 prefixes.push_back(0x64636261); 536 prefixes.push_back(0x64636261);
515 prefixes.push_back(0x73727170); 537 prefixes.push_back(0x73727170);
516 538
517 EXPECT_EQ("4:12\n1234abcdpqrs", safe_browsing::FormatGetHash(prefixes)); 539 EXPECT_EQ("4:12\n1234abcdpqrs", safe_browsing::FormatGetHash(prefixes));
518 } 540 }
519 541
520 TEST(SafeBrowsingProtocolParsingTest, TestReset) { 542 TEST(SafeBrowsingProtocolParsingTest, TestReset) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 EXPECT_FALSE(chunks[0]->IsAdd()); 707 EXPECT_FALSE(chunks[0]->IsAdd());
686 EXPECT_TRUE(chunks[0]->IsSub()); 708 EXPECT_TRUE(chunks[0]->IsSub());
687 EXPECT_TRUE(chunks[2]->IsPrefix()); 709 EXPECT_TRUE(chunks[2]->IsPrefix());
688 EXPECT_FALSE(chunks[2]->IsFullHash()); 710 EXPECT_FALSE(chunks[2]->IsFullHash());
689 ASSERT_EQ(1U, chunks[2]->PrefixCount()); 711 ASSERT_EQ(1U, chunks[2]->PrefixCount());
690 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp 712 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp
691 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0)); 713 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0));
692 } 714 }
693 715
694 } // namespace 716 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698