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 // Program to test the SafeBrowsing protocol parsing v2.1. | 5 // Program to test the SafeBrowsing protocol parsing v2.1. |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 std::vector<SBFullHashResult> full_hashes; | 482 std::vector<SBFullHashResult> full_hashes; |
483 SafeBrowsingProtocolParser parser; | 483 SafeBrowsingProtocolParser parser; |
484 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(), | 484 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(), |
485 hash_response.size(), | 485 hash_response.size(), |
486 &full_hashes)); | 486 &full_hashes)); |
487 | 487 |
488 EXPECT_EQ(full_hashes.size(), 1U); | 488 EXPECT_EQ(full_hashes.size(), 1U); |
489 EXPECT_EQ(memcmp("12345678901234567890123456789012", | 489 EXPECT_EQ(memcmp("12345678901234567890123456789012", |
490 &full_hashes[0].hash, sizeof(SBFullHash)), 0); | 490 &full_hashes[0].hash, sizeof(SBFullHash)), 0); |
491 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); | 491 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); |
492 EXPECT_EQ(full_hashes[0].add_chunk_id, 1); | |
493 | 492 |
494 hash_response += "goog-malware-shavar:7:32\n" | 493 hash_response += "goog-malware-shavar:7:32\n" |
495 "abcdefghijklmnopqrstuvwxyz123457"; | 494 "abcdefghijklmnopqrstuvwxyz123457"; |
496 full_hashes.clear(); | 495 full_hashes.clear(); |
497 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(), | 496 EXPECT_TRUE(parser.ParseGetHash(hash_response.data(), |
498 hash_response.size(), | 497 hash_response.size(), |
499 &full_hashes)); | 498 &full_hashes)); |
500 | 499 |
501 EXPECT_EQ(full_hashes.size(), 2U); | 500 EXPECT_EQ(full_hashes.size(), 2U); |
502 EXPECT_EQ(memcmp("12345678901234567890123456789012", | 501 EXPECT_EQ(memcmp("12345678901234567890123456789012", |
503 &full_hashes[0].hash, sizeof(SBFullHash)), 0); | 502 &full_hashes[0].hash, sizeof(SBFullHash)), 0); |
504 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); | 503 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); |
505 EXPECT_EQ(full_hashes[0].add_chunk_id, 1); | |
506 EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457", | 504 EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457", |
507 &full_hashes[1].hash, sizeof(SBFullHash)), 0); | 505 &full_hashes[1].hash, sizeof(SBFullHash)), 0); |
508 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); | 506 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); |
509 EXPECT_EQ(full_hashes[1].add_chunk_id, 7); | |
510 } | 507 } |
511 | 508 |
512 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { | 509 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { |
513 SafeBrowsingProtocolParser parser; | 510 SafeBrowsingProtocolParser parser; |
514 std::vector<SBPrefix> prefixes; | 511 std::vector<SBPrefix> prefixes; |
515 std::string get_hash; | 512 std::string get_hash; |
516 | 513 |
517 prefixes.push_back(0x34333231); | 514 prefixes.push_back(0x34333231); |
518 prefixes.push_back(0x64636261); | 515 prefixes.push_back(0x64636261); |
519 prefixes.push_back(0x73727170); | 516 prefixes.push_back(0x73727170); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 chunk_data.data(), | 877 chunk_data.data(), |
881 static_cast<int>(chunk_data.length()), | 878 static_cast<int>(chunk_data.length()), |
882 &chunks)) | 879 &chunks)) |
883 << "Unable to parse sub chunk data for listname: " | 880 << "Unable to parse sub chunk data for listname: " |
884 << listname; | 881 << listname; |
885 ASSERT_EQ(chunks.size(), 1U); | 882 ASSERT_EQ(chunks.size(), 1U); |
886 EXPECT_FALSE(chunks[0].is_add); | 883 EXPECT_FALSE(chunks[0].is_add); |
887 } | 884 } |
888 } | 885 } |
889 } | 886 } |
OLD | NEW |