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 "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "chrome/browser/safe_browsing/protocol_parser.h" | 8 #include "chrome/browser/safe_browsing/protocol_parser.h" |
9 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 // For safe_browsing_util::kBinUrlList. | 217 // For safe_browsing_util::kBinUrlList. |
218 result = parser.ParseChunk(safe_browsing_util::kBinUrlList, | 218 result = parser.ParseChunk(safe_browsing_util::kBinUrlList, |
219 add_chunk, | 219 add_chunk, |
220 static_cast<int>(sizeof(add_chunk)), | 220 static_cast<int>(sizeof(add_chunk)), |
221 &chunks); | 221 &chunks); |
222 EXPECT_FALSE(result); | 222 EXPECT_FALSE(result); |
223 EXPECT_EQ(chunks.size(), 0U); | 223 EXPECT_EQ(chunks.size(), 0U); |
224 } | 224 } |
225 | 225 |
| 226 // Test to verify handling of a truncated chunk header. |
| 227 TEST(SafeBrowsingProtocolParsingTest, TestTruncatedHeader) { |
| 228 std::string truncated_chunks("a:1:4:0\na:"); |
| 229 |
| 230 // Run the parser. |
| 231 SafeBrowsingProtocolParser parser; |
| 232 SBChunkList chunks; |
| 233 bool result = parser.ParseChunk( |
| 234 safe_browsing_util::kMalwareList, |
| 235 truncated_chunks.data(), |
| 236 static_cast<int>(truncated_chunks.length()), |
| 237 &chunks); |
| 238 EXPECT_FALSE(result); |
| 239 } |
| 240 |
226 // Test parsing one sub chunk. | 241 // Test parsing one sub chunk. |
227 TEST(SafeBrowsingProtocolParsingTest, TestSubChunk) { | 242 TEST(SafeBrowsingProtocolParsingTest, TestSubChunk) { |
228 std::string sub_chunk("s:9:4:59\naaaaxkkkk1111\003" | 243 std::string sub_chunk("s:9:4:59\naaaaxkkkk1111\003" |
229 "zzzz2222zzzz3333zzzz4444" | 244 "zzzz2222zzzz3333zzzz4444" |
230 "7777\002yyyy8888yyyy9999"); | 245 "7777\002yyyy8888yyyy9999"); |
231 sub_chunk[13] = '\0'; | 246 sub_chunk[13] = '\0'; |
232 | 247 |
233 // Run the parse. | 248 // Run the parse. |
234 SafeBrowsingProtocolParser parser; | 249 SafeBrowsingProtocolParser parser; |
235 SBChunkList chunks; | 250 SBChunkList chunks; |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 EXPECT_EQ(chunks[0].hosts[0].host, 0); | 775 EXPECT_EQ(chunks[0].hosts[0].host, 0); |
761 SBEntry* entry = chunks[0].hosts[0].entry; | 776 SBEntry* entry = chunks[0].hosts[0].entry; |
762 EXPECT_TRUE(entry->IsSub()); | 777 EXPECT_TRUE(entry->IsSub()); |
763 ASSERT_FALSE(entry->IsPrefix()); | 778 ASSERT_FALSE(entry->IsPrefix()); |
764 ASSERT_EQ(entry->prefix_count(), 1); | 779 ASSERT_EQ(entry->prefix_count(), 1); |
765 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x31313131); | 780 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x31313131); |
766 SBFullHash full; | 781 SBFullHash full; |
767 memcpy(full.full_hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 32); | 782 memcpy(full.full_hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 32); |
768 EXPECT_TRUE(entry->FullHashAt(0) == full); | 783 EXPECT_TRUE(entry->FullHashAt(0) == full); |
769 } | 784 } |
OLD | NEW |