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

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

Issue 16595: Ignore GetHash results for lists that we don't support. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Program to test the SafeBrowsing protocol parsing v2.1. 5 // Program to test the SafeBrowsing protocol parsing v2.1.
6 6
7 #include "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/safe_browsing/protocol_parser.h" 10 #include "chrome/browser/safe_browsing/protocol_parser.h"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash), 484 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash),
485 sizeof(get_hash), 485 sizeof(get_hash),
486 key, 486 key,
487 &re_key, 487 &re_key,
488 &full_hashes)); 488 &full_hashes));
489 EXPECT_FALSE(re_key); 489 EXPECT_FALSE(re_key);
490 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(1)); 490 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(1));
491 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0); 491 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0);
492 } 492 }
493 493
494 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) {
495 std::string hash_response = "goog-phish-shavar:1:32\n"
496 "12345678901234567890123456789012"
497 "googpub-phish-shavar:19:32\n"
498 "09876543210987654321098765432109";
499 bool re_key = false;
500 std::string key = "";
501 std::vector<SBFullHashResult> full_hashes;
502 SafeBrowsingProtocolParser parser;
503 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
504 hash_response.size(),
505 key,
506 &re_key,
507 &full_hashes));
508
509 EXPECT_EQ(full_hashes.size(), 1);
510 EXPECT_EQ(memcmp("12345678901234567890123456789012",
511 &full_hashes[0].hash, sizeof(SBFullHash)), 0);
512 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar");
513 EXPECT_EQ(full_hashes[0].add_chunk_id, 1);
514
515 hash_response += "goog-malware-shavar:7:32\n"
516 "abcdefghijklmnopqrstuvwxyz123457";
517 full_hashes.clear();
518 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
519 hash_response.size(),
520 key,
521 &re_key,
522 &full_hashes));
523
524 EXPECT_EQ(full_hashes.size(), 2);
525 EXPECT_EQ(memcmp("12345678901234567890123456789012",
526 &full_hashes[0].hash, sizeof(SBFullHash)), 0);
527 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar");
528 EXPECT_EQ(full_hashes[0].add_chunk_id, 1);
529 EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457",
530 &full_hashes[1].hash, sizeof(SBFullHash)), 0);
531 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar");
532 EXPECT_EQ(full_hashes[1].add_chunk_id, 7);
533 }
534
494 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { 535 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) {
495 SafeBrowsingProtocolParser parser; 536 SafeBrowsingProtocolParser parser;
496 std::vector<SBPrefix> prefixes; 537 std::vector<SBPrefix> prefixes;
497 std::string get_hash; 538 std::string get_hash;
498 539
499 prefixes.push_back(0x34333231); 540 prefixes.push_back(0x34333231);
500 prefixes.push_back(0x64636261); 541 prefixes.push_back(0x64636261);
501 prefixes.push_back(0x73727170); 542 prefixes.push_back(0x73727170);
502 543
503 parser.FormatGetHash(prefixes, &get_hash); 544 parser.FormatGetHash(prefixes, &get_hash);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 const std::string key("v_aDSz6jI92WeHCOoZ07QA=="); 743 const std::string key("v_aDSz6jI92WeHCOoZ07QA==");
703 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk="); 744 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk=");
704 745
705 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk), 746 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk),
706 sizeof(chunk), key, mac, 747 sizeof(chunk), key, mac,
707 &re_key, &chunks)); 748 &re_key, &chunks));
708 EXPECT_FALSE(re_key); 749 EXPECT_FALSE(re_key);
709 750
710 safe_browsing_util::FreeChunks(&chunks); 751 safe_browsing_util::FreeChunks(&chunks);
711 } 752 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database_bloom.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698