OLD | NEW |
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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 EXPECT_EQ(memcmp(&full_hashes[1].hash, | 432 EXPECT_EQ(memcmp(&full_hashes[1].hash, |
433 "cafebeefcafebeefdeaddeaddeaddead", | 433 "cafebeefcafebeefdeaddeaddeaddead", |
434 sizeof(SBFullHash)), 0); | 434 sizeof(SBFullHash)), 0); |
435 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id); | 435 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id); |
436 EXPECT_EQ(memcmp(&full_hashes[2].hash, | 436 EXPECT_EQ(memcmp(&full_hashes[2].hash, |
437 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", | 437 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", |
438 sizeof(SBFullHash)), 0); | 438 sizeof(SBFullHash)), 0); |
439 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[2].list_id); | 439 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[2].list_id); |
440 | 440 |
441 // Test metadata parsing. | 441 // Test metadata parsing. |
442 // TODO(shess): Currently the code doesn't actually put the metadata anywhere, | |
443 // this is just testing that metadata doesn't break parsing. | |
444 const std::string get_hash3(base::StringPrintf( | 442 const std::string get_hash3(base::StringPrintf( |
445 "45\n" | 443 "45\n" |
446 "%s:32:2:m\n" | 444 "%s:32:2:m\n" |
447 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss" | 445 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss" |
448 "00112233445566778899aabbccddeeff" | 446 "00112233445566778899aabbccddeeff" |
449 "2\nab2\nxy" | 447 "2\nab2\nxy" |
450 "%s:32:1\n" | 448 "%s:32:1\n" |
451 "cafebeefcafebeefdeaddeaddeaddead", | 449 "cafebeefcafebeefdeaddeaddeaddead", |
452 kDefaultMalwareList, | 450 kDefaultMalwareList, |
453 kDefaultPhishList)); | 451 kDefaultPhishList)); |
454 EXPECT_TRUE(safe_browsing::ParseGetHash(get_hash3.data(), get_hash3.length(), | 452 EXPECT_TRUE(safe_browsing::ParseGetHash(get_hash3.data(), get_hash3.length(), |
455 &cache_lifetime, &full_hashes)); | 453 &cache_lifetime, &full_hashes)); |
456 | 454 |
457 ASSERT_EQ(3U, full_hashes.size()); | 455 ASSERT_EQ(3U, full_hashes.size()); |
458 EXPECT_EQ(memcmp(&full_hashes[0].hash, | 456 EXPECT_EQ(memcmp(&full_hashes[0].hash, |
459 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", | 457 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", |
460 sizeof(SBFullHash)), 0); | 458 sizeof(SBFullHash)), 0); |
461 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[0].list_id); | 459 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[0].list_id); |
| 460 EXPECT_EQ(std::string("ab"), full_hashes[0].metadata); |
462 EXPECT_EQ(memcmp(&full_hashes[1].hash, | 461 EXPECT_EQ(memcmp(&full_hashes[1].hash, |
463 "00112233445566778899aabbccddeeff", | 462 "00112233445566778899aabbccddeeff", |
464 sizeof(SBFullHash)), 0); | 463 sizeof(SBFullHash)), 0); |
465 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id); | 464 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[1].list_id); |
| 465 EXPECT_EQ(std::string("xy"), full_hashes[1].metadata); |
466 EXPECT_EQ(memcmp(&full_hashes[2].hash, | 466 EXPECT_EQ(memcmp(&full_hashes[2].hash, |
467 "cafebeefcafebeefdeaddeaddeaddead", | 467 "cafebeefcafebeefdeaddeaddeaddead", |
468 sizeof(SBFullHash)), 0); | 468 sizeof(SBFullHash)), 0); |
469 EXPECT_EQ(safe_browsing_util::PHISH, full_hashes[2].list_id); | 469 EXPECT_EQ(safe_browsing_util::PHISH, full_hashes[2].list_id); |
| 470 EXPECT_EQ(std::string(), full_hashes[2].metadata); |
470 } | 471 } |
471 | 472 |
472 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) { | 473 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) { |
473 std::string hash_response(base::StringPrintf( | 474 std::string hash_response(base::StringPrintf( |
474 "45\n" | 475 "45\n" |
475 "%s:32:1\n" | 476 "%s:32:1\n" |
476 "12345678901234567890123456789012" | 477 "12345678901234567890123456789012" |
477 "googpub-phish-shavar:32:1\n" | 478 "googpub-phish-shavar:32:1\n" |
478 "09876543210987654321098765432109", | 479 "09876543210987654321098765432109", |
479 kDefaultPhishList)); | 480 kDefaultPhishList)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 "%s:32:1\n" | 522 "%s:32:1\n" |
522 "0123456789hashhashhashhashhashha", | 523 "0123456789hashhashhashhashhashha", |
523 kDefaultMalwareList)); | 524 kDefaultMalwareList)); |
524 EXPECT_TRUE(safe_browsing::ParseGetHash(get_hash3.data(), get_hash3.length(), | 525 EXPECT_TRUE(safe_browsing::ParseGetHash(get_hash3.data(), get_hash3.length(), |
525 &cache_lifetime, &full_hashes)); | 526 &cache_lifetime, &full_hashes)); |
526 ASSERT_EQ(1U, full_hashes.size()); | 527 ASSERT_EQ(1U, full_hashes.size()); |
527 EXPECT_EQ(memcmp(&full_hashes[0].hash, | 528 EXPECT_EQ(memcmp(&full_hashes[0].hash, |
528 "0123456789hashhashhashhashhashha", | 529 "0123456789hashhashhashhashhashha", |
529 sizeof(SBFullHash)), 0); | 530 sizeof(SBFullHash)), 0); |
530 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[0].list_id); | 531 EXPECT_EQ(safe_browsing_util::MALWARE, full_hashes[0].list_id); |
| 532 EXPECT_EQ(std::string(), full_hashes[0].metadata); |
531 } | 533 } |
532 | 534 |
533 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { | 535 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { |
534 std::vector<SBPrefix> prefixes; | 536 std::vector<SBPrefix> prefixes; |
535 prefixes.push_back(0x34333231); | 537 prefixes.push_back(0x34333231); |
536 prefixes.push_back(0x64636261); | 538 prefixes.push_back(0x64636261); |
537 prefixes.push_back(0x73727170); | 539 prefixes.push_back(0x73727170); |
538 | 540 |
539 EXPECT_EQ("4:12\n1234abcdpqrs", safe_browsing::FormatGetHash(prefixes)); | 541 EXPECT_EQ("4:12\n1234abcdpqrs", safe_browsing::FormatGetHash(prefixes)); |
540 } | 542 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 EXPECT_FALSE(chunks[0]->IsAdd()); | 709 EXPECT_FALSE(chunks[0]->IsAdd()); |
708 EXPECT_TRUE(chunks[0]->IsSub()); | 710 EXPECT_TRUE(chunks[0]->IsSub()); |
709 EXPECT_TRUE(chunks[2]->IsPrefix()); | 711 EXPECT_TRUE(chunks[2]->IsPrefix()); |
710 EXPECT_FALSE(chunks[2]->IsFullHash()); | 712 EXPECT_FALSE(chunks[2]->IsFullHash()); |
711 ASSERT_EQ(1U, chunks[2]->PrefixCount()); | 713 ASSERT_EQ(1U, chunks[2]->PrefixCount()); |
712 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp | 714 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp |
713 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0)); | 715 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0)); |
714 } | 716 } |
715 | 717 |
716 } // namespace | 718 } // namespace |
OLD | NEW |