| OLD | NEW |
| 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 "base/win_util.h" | |
| 11 #include "chrome/browser/safe_browsing/protocol_parser.h" | 10 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 12 |
| 14 | 13 |
| 15 // Test parsing one add chunk. | 14 // Test parsing one add chunk. |
| 16 TEST(SafeBrowsingProtocolParsingTest, TestAddChunk) { | 15 TEST(SafeBrowsingProtocolParsingTest, TestAddChunk) { |
| 17 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999"); | 16 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999"); |
| 18 add_chunk[13] = '\0'; | 17 add_chunk[13] = '\0'; |
| 19 | 18 |
| 20 // Run the parse. | 19 // Run the parse. |
| 21 SafeBrowsingProtocolParser parser; | 20 SafeBrowsingProtocolParser parser; |
| 22 bool re_key = false; | 21 bool re_key = false; |
| 23 std::deque<SBChunk> chunks; | 22 std::deque<SBChunk> chunks; |
| 24 bool result = parser.ParseChunk(add_chunk.data(), | 23 bool result = parser.ParseChunk(add_chunk.data(), |
| 25 static_cast<int>(add_chunk.length()), | 24 static_cast<int>(add_chunk.length()), |
| 26 "", "", &re_key, &chunks); | 25 "", "", &re_key, &chunks); |
| 27 EXPECT_TRUE(result); | 26 EXPECT_TRUE(result); |
| 28 EXPECT_FALSE(re_key); | 27 EXPECT_FALSE(re_key); |
| 29 EXPECT_EQ(chunks.size(), 1); | 28 EXPECT_EQ(chunks.size(), static_cast<size_t>(1)); |
| 30 EXPECT_EQ(chunks[0].chunk_number, 1); | 29 EXPECT_EQ(chunks[0].chunk_number, 1); |
| 31 EXPECT_EQ(chunks[0].hosts.size(), 3); | 30 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(3)); |
| 32 | 31 |
| 33 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); | 32 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); |
| 34 SBEntry* entry = chunks[0].hosts[0].entry; | 33 SBEntry* entry = chunks[0].hosts[0].entry; |
| 35 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 34 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 36 EXPECT_EQ(entry->prefix_count(), 0); | 35 EXPECT_EQ(entry->prefix_count(), 0); |
| 37 | 36 |
| 38 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); | 37 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); |
| 39 entry = chunks[0].hosts[1].entry; | 38 entry = chunks[0].hosts[1].entry; |
| 40 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 39 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 41 EXPECT_EQ(entry->prefix_count(), 3); | 40 EXPECT_EQ(entry->prefix_count(), 3); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 69 | 68 |
| 70 // Run the parse. | 69 // Run the parse. |
| 71 SafeBrowsingProtocolParser parser; | 70 SafeBrowsingProtocolParser parser; |
| 72 bool re_key = false; | 71 bool re_key = false; |
| 73 std::deque<SBChunk> chunks; | 72 std::deque<SBChunk> chunks; |
| 74 bool result = parser.ParseChunk(add_chunk.data(), | 73 bool result = parser.ParseChunk(add_chunk.data(), |
| 75 static_cast<int>(add_chunk.length()), | 74 static_cast<int>(add_chunk.length()), |
| 76 "", "", &re_key, &chunks); | 75 "", "", &re_key, &chunks); |
| 77 EXPECT_TRUE(result); | 76 EXPECT_TRUE(result); |
| 78 EXPECT_FALSE(re_key); | 77 EXPECT_FALSE(re_key); |
| 79 EXPECT_EQ(chunks.size(), 1); | 78 EXPECT_EQ(chunks.size(), static_cast<size_t>(1)); |
| 80 EXPECT_EQ(chunks[0].chunk_number, 1); | 79 EXPECT_EQ(chunks[0].chunk_number, 1); |
| 81 EXPECT_EQ(chunks[0].hosts.size(), 1); | 80 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(1)); |
| 82 | 81 |
| 83 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); | 82 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); |
| 84 SBEntry* entry = chunks[0].hosts[0].entry; | 83 SBEntry* entry = chunks[0].hosts[0].entry; |
| 85 EXPECT_EQ(entry->type(), SBEntry::ADD_FULL_HASH); | 84 EXPECT_EQ(entry->type(), SBEntry::ADD_FULL_HASH); |
| 86 EXPECT_EQ(entry->prefix_count(), 2); | 85 EXPECT_EQ(entry->prefix_count(), 2); |
| 87 EXPECT_TRUE(entry->FullHashAt(0) == full_hash1); | 86 EXPECT_TRUE(entry->FullHashAt(0) == full_hash1); |
| 88 EXPECT_TRUE(entry->FullHashAt(1) == full_hash2); | 87 EXPECT_TRUE(entry->FullHashAt(1) == full_hash2); |
| 89 | 88 |
| 90 safe_browsing_util::FreeChunks(&chunks); | 89 safe_browsing_util::FreeChunks(&chunks); |
| 91 } | 90 } |
| 92 | 91 |
| 93 // Test parsing multiple add chunks. We'll use the same chunk as above, and add | 92 // Test parsing multiple add chunks. We'll use the same chunk as above, and add |
| 94 // one more after it. | 93 // one more after it. |
| 95 TEST(SafeBrowsingProtocolParsingTest, TestAddChunks) { | 94 TEST(SafeBrowsingProtocolParsingTest, TestAddChunks) { |
| 96 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999" | 95 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999" |
| 97 "a:2:4:13\n5555\002ppppgggg"); | 96 "a:2:4:13\n5555\002ppppgggg"); |
| 98 add_chunk[13] = '\0'; | 97 add_chunk[13] = '\0'; |
| 99 | 98 |
| 100 // Run the parse. | 99 // Run the parse. |
| 101 SafeBrowsingProtocolParser parser; | 100 SafeBrowsingProtocolParser parser; |
| 102 bool re_key = false; | 101 bool re_key = false; |
| 103 std::deque<SBChunk> chunks; | 102 std::deque<SBChunk> chunks; |
| 104 bool result = parser.ParseChunk(add_chunk.data(), | 103 bool result = parser.ParseChunk(add_chunk.data(), |
| 105 static_cast<int>(add_chunk.length()), | 104 static_cast<int>(add_chunk.length()), |
| 106 "", "", &re_key, &chunks); | 105 "", "", &re_key, &chunks); |
| 107 EXPECT_TRUE(result); | 106 EXPECT_TRUE(result); |
| 108 EXPECT_FALSE(re_key); | 107 EXPECT_FALSE(re_key); |
| 109 EXPECT_EQ(chunks.size(), 2); | 108 EXPECT_EQ(chunks.size(), static_cast<size_t>(2)); |
| 110 EXPECT_EQ(chunks[0].chunk_number, 1); | 109 EXPECT_EQ(chunks[0].chunk_number, 1); |
| 111 EXPECT_EQ(chunks[0].hosts.size(), 3); | 110 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(3)); |
| 112 | 111 |
| 113 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); | 112 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); |
| 114 SBEntry* entry = chunks[0].hosts[0].entry; | 113 SBEntry* entry = chunks[0].hosts[0].entry; |
| 115 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 114 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 116 EXPECT_EQ(entry->prefix_count(), 0); | 115 EXPECT_EQ(entry->prefix_count(), 0); |
| 117 | 116 |
| 118 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); | 117 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); |
| 119 entry = chunks[0].hosts[1].entry; | 118 entry = chunks[0].hosts[1].entry; |
| 120 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 119 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 121 EXPECT_EQ(entry->prefix_count(), 3); | 120 EXPECT_EQ(entry->prefix_count(), 3); |
| 122 EXPECT_EQ(entry->PrefixAt(0), 0x32323232); | 121 EXPECT_EQ(entry->PrefixAt(0), 0x32323232); |
| 123 EXPECT_EQ(entry->PrefixAt(1), 0x33333333); | 122 EXPECT_EQ(entry->PrefixAt(1), 0x33333333); |
| 124 EXPECT_EQ(entry->PrefixAt(2), 0x34343434); | 123 EXPECT_EQ(entry->PrefixAt(2), 0x34343434); |
| 125 | 124 |
| 126 EXPECT_EQ(chunks[0].hosts[2].host, 0x37373737); | 125 EXPECT_EQ(chunks[0].hosts[2].host, 0x37373737); |
| 127 entry = chunks[0].hosts[2].entry; | 126 entry = chunks[0].hosts[2].entry; |
| 128 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 127 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 129 EXPECT_EQ(entry->prefix_count(), 2); | 128 EXPECT_EQ(entry->prefix_count(), 2); |
| 130 EXPECT_EQ(entry->PrefixAt(0), 0x38383838); | 129 EXPECT_EQ(entry->PrefixAt(0), 0x38383838); |
| 131 EXPECT_EQ(entry->PrefixAt(1), 0x39393939); | 130 EXPECT_EQ(entry->PrefixAt(1), 0x39393939); |
| 132 | 131 |
| 133 | 132 |
| 134 EXPECT_EQ(chunks[1].chunk_number, 2); | 133 EXPECT_EQ(chunks[1].chunk_number, 2); |
| 135 EXPECT_EQ(chunks[1].hosts.size(), 1); | 134 EXPECT_EQ(chunks[1].hosts.size(), static_cast<size_t>(1)); |
| 136 | 135 |
| 137 EXPECT_EQ(chunks[1].hosts[0].host, 0x35353535); | 136 EXPECT_EQ(chunks[1].hosts[0].host, 0x35353535); |
| 138 entry = chunks[1].hosts[0].entry; | 137 entry = chunks[1].hosts[0].entry; |
| 139 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); | 138 EXPECT_EQ(entry->type(), SBEntry::ADD_PREFIX); |
| 140 EXPECT_EQ(entry->prefix_count(), 2); | 139 EXPECT_EQ(entry->prefix_count(), 2); |
| 141 EXPECT_EQ(entry->PrefixAt(0), 0x70707070); | 140 EXPECT_EQ(entry->PrefixAt(0), 0x70707070); |
| 142 EXPECT_EQ(entry->PrefixAt(1), 0x67676767); | 141 EXPECT_EQ(entry->PrefixAt(1), 0x67676767); |
| 143 | 142 |
| 144 safe_browsing_util::FreeChunks(&chunks); | 143 safe_browsing_util::FreeChunks(&chunks); |
| 145 } | 144 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 add_chunk.append(StringPrintf("001%d", i)); | 156 add_chunk.append(StringPrintf("001%d", i)); |
| 158 | 157 |
| 159 SafeBrowsingProtocolParser parser; | 158 SafeBrowsingProtocolParser parser; |
| 160 bool re_key = false; | 159 bool re_key = false; |
| 161 std::deque<SBChunk> chunks; | 160 std::deque<SBChunk> chunks; |
| 162 bool result = parser.ParseChunk(add_chunk.data(), | 161 bool result = parser.ParseChunk(add_chunk.data(), |
| 163 static_cast<int>(add_chunk.length()), | 162 static_cast<int>(add_chunk.length()), |
| 164 "", "", &re_key, &chunks); | 163 "", "", &re_key, &chunks); |
| 165 EXPECT_TRUE(result); | 164 EXPECT_TRUE(result); |
| 166 EXPECT_FALSE(re_key); | 165 EXPECT_FALSE(re_key); |
| 167 EXPECT_EQ(chunks.size(), 1); | 166 EXPECT_EQ(chunks.size(), static_cast<size_t>(1)); |
| 168 EXPECT_EQ(chunks[0].chunk_number, 1); | 167 EXPECT_EQ(chunks[0].chunk_number, 1); |
| 169 | 168 |
| 170 EXPECT_EQ(chunks[0].hosts.size(), 1); | 169 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(1)); |
| 171 | 170 |
| 172 const SBChunkHost& host = chunks[0].hosts[0]; | 171 const SBChunkHost& host = chunks[0].hosts[0]; |
| 173 EXPECT_EQ(host.host, 0x61616161); | 172 EXPECT_EQ(host.host, 0x61616161); |
| 174 EXPECT_EQ(host.entry->prefix_count(), 260); | 173 EXPECT_EQ(host.entry->prefix_count(), 260); |
| 175 | 174 |
| 176 safe_browsing_util::FreeChunks(&chunks); | 175 safe_browsing_util::FreeChunks(&chunks); |
| 177 } | 176 } |
| 178 | 177 |
| 179 // Test parsing one sub chunk. | 178 // Test parsing one sub chunk. |
| 180 TEST(SafeBrowsingProtocolParsingTest, TestSubChunk) { | 179 TEST(SafeBrowsingProtocolParsingTest, TestSubChunk) { |
| 181 std::string sub_chunk("s:9:4:59\naaaaxkkkk1111\003" | 180 std::string sub_chunk("s:9:4:59\naaaaxkkkk1111\003" |
| 182 "zzzz2222zzzz3333zzzz4444" | 181 "zzzz2222zzzz3333zzzz4444" |
| 183 "7777\002yyyy8888yyyy9999"); | 182 "7777\002yyyy8888yyyy9999"); |
| 184 sub_chunk[13] = '\0'; | 183 sub_chunk[13] = '\0'; |
| 185 | 184 |
| 186 // Run the parse. | 185 // Run the parse. |
| 187 SafeBrowsingProtocolParser parser; | 186 SafeBrowsingProtocolParser parser; |
| 188 bool re_key = false; | 187 bool re_key = false; |
| 189 std::deque<SBChunk> chunks; | 188 std::deque<SBChunk> chunks; |
| 190 bool result = parser.ParseChunk(sub_chunk.data(), | 189 bool result = parser.ParseChunk(sub_chunk.data(), |
| 191 static_cast<int>(sub_chunk.length()), | 190 static_cast<int>(sub_chunk.length()), |
| 192 "", "", &re_key, &chunks); | 191 "", "", &re_key, &chunks); |
| 193 EXPECT_TRUE(result); | 192 EXPECT_TRUE(result); |
| 194 EXPECT_FALSE(re_key); | 193 EXPECT_FALSE(re_key); |
| 195 EXPECT_EQ(chunks.size(), 1); | 194 EXPECT_EQ(chunks.size(), static_cast<size_t>(1)); |
| 196 EXPECT_EQ(chunks[0].chunk_number, 9); | 195 EXPECT_EQ(chunks[0].chunk_number, 9); |
| 197 EXPECT_EQ(chunks[0].hosts.size(), 3); | 196 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(3)); |
| 198 | 197 |
| 199 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); | 198 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); |
| 200 SBEntry* entry = chunks[0].hosts[0].entry; | 199 SBEntry* entry = chunks[0].hosts[0].entry; |
| 201 EXPECT_EQ(entry->type(), SBEntry::SUB_PREFIX); | 200 EXPECT_EQ(entry->type(), SBEntry::SUB_PREFIX); |
| 202 EXPECT_EQ(entry->chunk_id(), 0x6b6b6b6b); | 201 EXPECT_EQ(entry->chunk_id(), 0x6b6b6b6b); |
| 203 EXPECT_EQ(entry->prefix_count(), 0); | 202 EXPECT_EQ(entry->prefix_count(), 0); |
| 204 | 203 |
| 205 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); | 204 EXPECT_EQ(chunks[0].hosts[1].host, 0x31313131); |
| 206 entry = chunks[0].hosts[1].entry; | 205 entry = chunks[0].hosts[1].entry; |
| 207 EXPECT_EQ(entry->type(), SBEntry::SUB_PREFIX); | 206 EXPECT_EQ(entry->type(), SBEntry::SUB_PREFIX); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 242 |
| 244 // Run the parse. | 243 // Run the parse. |
| 245 SafeBrowsingProtocolParser parser; | 244 SafeBrowsingProtocolParser parser; |
| 246 bool re_key = false; | 245 bool re_key = false; |
| 247 std::deque<SBChunk> chunks; | 246 std::deque<SBChunk> chunks; |
| 248 bool result = parser.ParseChunk(sub_chunk.data(), | 247 bool result = parser.ParseChunk(sub_chunk.data(), |
| 249 static_cast<int>(sub_chunk.length()), | 248 static_cast<int>(sub_chunk.length()), |
| 250 "", "", &re_key, &chunks); | 249 "", "", &re_key, &chunks); |
| 251 EXPECT_TRUE(result); | 250 EXPECT_TRUE(result); |
| 252 EXPECT_FALSE(re_key); | 251 EXPECT_FALSE(re_key); |
| 253 EXPECT_EQ(chunks.size(), 1); | 252 EXPECT_EQ(chunks.size(), static_cast<size_t>(1)); |
| 254 EXPECT_EQ(chunks[0].chunk_number, 1); | 253 EXPECT_EQ(chunks[0].chunk_number, 1); |
| 255 EXPECT_EQ(chunks[0].hosts.size(), 1); | 254 EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(1)); |
| 256 | 255 |
| 257 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); | 256 EXPECT_EQ(chunks[0].hosts[0].host, 0x61616161); |
| 258 SBEntry* entry = chunks[0].hosts[0].entry; | 257 SBEntry* entry = chunks[0].hosts[0].entry; |
| 259 EXPECT_EQ(entry->type(), SBEntry::SUB_FULL_HASH); | 258 EXPECT_EQ(entry->type(), SBEntry::SUB_FULL_HASH); |
| 260 EXPECT_EQ(entry->prefix_count(), 2); | 259 EXPECT_EQ(entry->prefix_count(), 2); |
| 261 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x79797979); | 260 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x79797979); |
| 262 EXPECT_TRUE(entry->FullHashAt(0) == full_hash1); | 261 EXPECT_TRUE(entry->FullHashAt(0) == full_hash1); |
| 263 EXPECT_EQ(entry->ChunkIdAtPrefix(1), 0x7a7a7a7a); | 262 EXPECT_EQ(entry->ChunkIdAtPrefix(1), 0x7a7a7a7a); |
| 264 EXPECT_TRUE(entry->FullHashAt(1) == full_hash2); | 263 EXPECT_TRUE(entry->FullHashAt(1) == full_hash2); |
| 265 | 264 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 279 std::vector<ChunkUrl> urls; | 278 std::vector<ChunkUrl> urls; |
| 280 EXPECT_TRUE(parser.ParseUpdate(add_del.data(), | 279 EXPECT_TRUE(parser.ParseUpdate(add_del.data(), |
| 281 static_cast<int>(add_del.length()), "", | 280 static_cast<int>(add_del.length()), "", |
| 282 &next_query_sec, &re_key, | 281 &next_query_sec, &re_key, |
| 283 &reset, &deletes, &urls)); | 282 &reset, &deletes, &urls)); |
| 284 | 283 |
| 285 EXPECT_TRUE(urls.empty()); | 284 EXPECT_TRUE(urls.empty()); |
| 286 EXPECT_FALSE(re_key); | 285 EXPECT_FALSE(re_key); |
| 287 EXPECT_FALSE(reset); | 286 EXPECT_FALSE(reset); |
| 288 EXPECT_EQ(next_query_sec, 1700); | 287 EXPECT_EQ(next_query_sec, 1700); |
| 289 EXPECT_EQ(deletes.size(), 2); | 288 EXPECT_EQ(deletes.size(), static_cast<size_t>(2)); |
| 290 | 289 |
| 291 EXPECT_EQ(deletes[0].chunk_del.size(), 4); | 290 EXPECT_EQ(deletes[0].chunk_del.size(), static_cast<size_t>(4)); |
| 292 EXPECT_TRUE(deletes[0].chunk_del[0] == ChunkRange(1, 7)); | 291 EXPECT_TRUE(deletes[0].chunk_del[0] == ChunkRange(1, 7)); |
| 293 EXPECT_TRUE(deletes[0].chunk_del[1] == ChunkRange(43, 597)); | 292 EXPECT_TRUE(deletes[0].chunk_del[1] == ChunkRange(43, 597)); |
| 294 EXPECT_TRUE(deletes[0].chunk_del[2] == ChunkRange(44444)); | 293 EXPECT_TRUE(deletes[0].chunk_del[2] == ChunkRange(44444)); |
| 295 EXPECT_TRUE(deletes[0].chunk_del[3] == ChunkRange(99999)); | 294 EXPECT_TRUE(deletes[0].chunk_del[3] == ChunkRange(99999)); |
| 296 | 295 |
| 297 EXPECT_EQ(deletes[1].chunk_del.size(), 3); | 296 EXPECT_EQ(deletes[1].chunk_del.size(), static_cast<size_t>(3)); |
| 298 EXPECT_TRUE(deletes[1].chunk_del[0] == ChunkRange(21, 27)); | 297 EXPECT_TRUE(deletes[1].chunk_del[0] == ChunkRange(21, 27)); |
| 299 EXPECT_TRUE(deletes[1].chunk_del[1] == ChunkRange(42)); | 298 EXPECT_TRUE(deletes[1].chunk_del[1] == ChunkRange(42)); |
| 300 EXPECT_TRUE(deletes[1].chunk_del[2] == ChunkRange(171717)); | 299 EXPECT_TRUE(deletes[1].chunk_del[2] == ChunkRange(171717)); |
| 301 | 300 |
| 302 // An update response with missing list name. | 301 // An update response with missing list name. |
| 303 | 302 |
| 304 next_query_sec = 0; | 303 next_query_sec = 0; |
| 305 deletes.clear(); | 304 deletes.clear(); |
| 306 urls.clear(); | 305 urls.clear(); |
| 307 add_del = "n:1700\nad:1-7,43-597,44444,99999\ni:malware\nsd:4,21-27171717\n"; | 306 add_del = "n:1700\nad:1-7,43-597,44444,99999\ni:malware\nsd:4,21-27171717\n"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 326 bool reset = false; | 325 bool reset = false; |
| 327 std::vector<SBChunkDelete> deletes; | 326 std::vector<SBChunkDelete> deletes; |
| 328 std::vector<ChunkUrl> urls; | 327 std::vector<ChunkUrl> urls; |
| 329 EXPECT_TRUE(parser.ParseUpdate(redirects.data(), | 328 EXPECT_TRUE(parser.ParseUpdate(redirects.data(), |
| 330 static_cast<int>(redirects.length()), "", | 329 static_cast<int>(redirects.length()), "", |
| 331 &next_query_sec, &re_key, | 330 &next_query_sec, &re_key, |
| 332 &reset, &deletes, &urls)); | 331 &reset, &deletes, &urls)); |
| 333 | 332 |
| 334 EXPECT_FALSE(re_key); | 333 EXPECT_FALSE(re_key); |
| 335 EXPECT_FALSE(reset); | 334 EXPECT_FALSE(reset); |
| 336 EXPECT_EQ(urls.size(), 4); | 335 EXPECT_EQ(urls.size(), static_cast<size_t>(4)); |
| 337 EXPECT_EQ(urls[0].url, | 336 EXPECT_EQ(urls[0].url, |
| 338 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_1"); | 337 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_1"); |
| 339 EXPECT_EQ(urls[1].url, | 338 EXPECT_EQ(urls[1].url, |
| 340 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_2"); | 339 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_2"); |
| 341 EXPECT_EQ(urls[2].url, | 340 EXPECT_EQ(urls[2].url, |
| 342 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_3"); | 341 "cache.googlevideo.com/safebrowsing/rd/goog-malware-shavar_s_3"); |
| 343 EXPECT_EQ(urls[3].url, | 342 EXPECT_EQ(urls[3].url, |
| 344 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8641-8800:8641-8689," | 343 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8641-8800:8641-8689," |
| 345 "8691-8731,8733-8786"); | 344 "8691-8731,8733-8786"); |
| 346 EXPECT_EQ(next_query_sec, 0); | 345 EXPECT_EQ(next_query_sec, 0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 362 const std::string key("58Lqn5WIP961x3zuLGo5Uw=="); | 361 const std::string key("58Lqn5WIP961x3zuLGo5Uw=="); |
| 363 std::vector<SBChunkDelete> deletes; | 362 std::vector<SBChunkDelete> deletes; |
| 364 std::vector<ChunkUrl> urls; | 363 std::vector<ChunkUrl> urls; |
| 365 EXPECT_TRUE(parser.ParseUpdate(redirects.data(), | 364 EXPECT_TRUE(parser.ParseUpdate(redirects.data(), |
| 366 static_cast<int>(redirects.length()), key, | 365 static_cast<int>(redirects.length()), key, |
| 367 &next_query_sec, &re_key, | 366 &next_query_sec, &re_key, |
| 368 &reset, &deletes, &urls)); | 367 &reset, &deletes, &urls)); |
| 369 | 368 |
| 370 EXPECT_FALSE(re_key); | 369 EXPECT_FALSE(re_key); |
| 371 EXPECT_FALSE(reset); | 370 EXPECT_FALSE(reset); |
| 372 EXPECT_EQ(urls.size(), 2); | 371 EXPECT_EQ(urls.size(), static_cast<size_t>(2)); |
| 373 EXPECT_EQ(urls[0].url, | 372 EXPECT_EQ(urls[0].url, |
| 374 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505"); | 373 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505"); |
| 375 EXPECT_EQ(urls[0].mac, "pcY6iVeT9-CBQ3fdAF0rpnKjR1Y="); | 374 EXPECT_EQ(urls[0].mac, "pcY6iVeT9-CBQ3fdAF0rpnKjR1Y="); |
| 376 EXPECT_EQ(urls[1].url, | 375 EXPECT_EQ(urls[1].url, |
| 377 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8001-8160:8001-8024," | 376 "s.ytimg.com/safebrowsing/rd/goog-phish-shavar_a_8001-8160:8001-8024," |
| 378 "8026-8045,8048-8049,8051-8134,8136-8152,8155-8160"); | 377 "8026-8045,8048-8049,8051-8134,8136-8152,8155-8160"); |
| 379 EXPECT_EQ(urls[1].mac, "j6XXAEWnjYk9tVVLBSdQvIEq2Wg="); | 378 EXPECT_EQ(urls[1].mac, "j6XXAEWnjYk9tVVLBSdQvIEq2Wg="); |
| 380 } | 379 } |
| 381 | 380 |
| 382 // Test parsing various SafeBrowsing protocol headers. | 381 // Test parsing various SafeBrowsing protocol headers. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 408 "ffffeeeeddddccccbbbbaaaa99998888"); | 407 "ffffeeeeddddccccbbbbaaaa99998888"); |
| 409 std::vector<SBFullHashResult> full_hashes; | 408 std::vector<SBFullHashResult> full_hashes; |
| 410 bool re_key = false; | 409 bool re_key = false; |
| 411 SafeBrowsingProtocolParser parser; | 410 SafeBrowsingProtocolParser parser; |
| 412 parser.ParseGetHash(get_hash.data(), | 411 parser.ParseGetHash(get_hash.data(), |
| 413 static_cast<int>(get_hash.length()), "", | 412 static_cast<int>(get_hash.length()), "", |
| 414 &re_key, | 413 &re_key, |
| 415 &full_hashes); | 414 &full_hashes); |
| 416 | 415 |
| 417 EXPECT_FALSE(re_key); | 416 EXPECT_FALSE(re_key); |
| 418 EXPECT_EQ(full_hashes.size(), 3); | 417 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(3)); |
| 419 EXPECT_EQ(memcmp(&full_hashes[0].hash, | 418 EXPECT_EQ(memcmp(&full_hashes[0].hash, |
| 420 "00112233445566778899aabbccddeeff", | 419 "00112233445566778899aabbccddeeff", |
| 421 sizeof(SBFullHash)), 0); | 420 sizeof(SBFullHash)), 0); |
| 422 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); | 421 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); |
| 423 EXPECT_EQ(memcmp(&full_hashes[1].hash, | 422 EXPECT_EQ(memcmp(&full_hashes[1].hash, |
| 424 "00001111222233334444555566667777", | 423 "00001111222233334444555566667777", |
| 425 sizeof(SBFullHash)), 0); | 424 sizeof(SBFullHash)), 0); |
| 426 EXPECT_EQ(full_hashes[1].list_name, "goog-phish-shavar"); | 425 EXPECT_EQ(full_hashes[1].list_name, "goog-phish-shavar"); |
| 427 EXPECT_EQ(memcmp(&full_hashes[2].hash, | 426 EXPECT_EQ(memcmp(&full_hashes[2].hash, |
| 428 "ffffeeeeddddccccbbbbaaaa99998888", | 427 "ffffeeeeddddccccbbbbaaaa99998888", |
| 429 sizeof(SBFullHash)), 0); | 428 sizeof(SBFullHash)), 0); |
| 430 EXPECT_EQ(full_hashes[2].list_name, "goog-phish-shavar"); | 429 EXPECT_EQ(full_hashes[2].list_name, "goog-phish-shavar"); |
| 431 | 430 |
| 432 // Test multiple lists in the GetHash results. | 431 // Test multiple lists in the GetHash results. |
| 433 std::string get_hash2("goog-phish-shavar:19:32\n" | 432 std::string get_hash2("goog-phish-shavar:19:32\n" |
| 434 "00112233445566778899aabbccddeeff" | 433 "00112233445566778899aabbccddeeff" |
| 435 "goog-malware-shavar:19:64\n" | 434 "goog-malware-shavar:19:64\n" |
| 436 "cafebeefcafebeefdeaddeaddeaddead" | 435 "cafebeefcafebeefdeaddeaddeaddead" |
| 437 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss"); | 436 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss"); |
| 438 parser.ParseGetHash(get_hash2.data(), | 437 parser.ParseGetHash(get_hash2.data(), |
| 439 static_cast<int>(get_hash2.length()), "", | 438 static_cast<int>(get_hash2.length()), "", |
| 440 &re_key, | 439 &re_key, |
| 441 &full_hashes); | 440 &full_hashes); |
| 442 | 441 |
| 443 EXPECT_FALSE(re_key); | 442 EXPECT_FALSE(re_key); |
| 444 EXPECT_EQ(full_hashes.size(), 3); | 443 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(3)); |
| 445 EXPECT_EQ(memcmp(&full_hashes[0].hash, | 444 EXPECT_EQ(memcmp(&full_hashes[0].hash, |
| 446 "00112233445566778899aabbccddeeff", | 445 "00112233445566778899aabbccddeeff", |
| 447 sizeof(SBFullHash)), 0); | 446 sizeof(SBFullHash)), 0); |
| 448 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); | 447 EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar"); |
| 449 EXPECT_EQ(memcmp(&full_hashes[1].hash, | 448 EXPECT_EQ(memcmp(&full_hashes[1].hash, |
| 450 "cafebeefcafebeefdeaddeaddeaddead", | 449 "cafebeefcafebeefdeaddeaddeaddead", |
| 451 sizeof(SBFullHash)), 0); | 450 sizeof(SBFullHash)), 0); |
| 452 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); | 451 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); |
| 453 EXPECT_EQ(memcmp(&full_hashes[2].hash, | 452 EXPECT_EQ(memcmp(&full_hashes[2].hash, |
| 454 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", | 453 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", |
| 455 sizeof(SBFullHash)), 0); | 454 sizeof(SBFullHash)), 0); |
| 456 EXPECT_EQ(full_hashes[2].list_name, "goog-malware-shavar"); | 455 EXPECT_EQ(full_hashes[2].list_name, "goog-malware-shavar"); |
| 457 } | 456 } |
| 458 | 457 |
| 458 // TODO(port): Enable when we have ported VerifyMAC in safe_browsing_util.cc. |
| 459 #if defined(OS_WIN) |
| 459 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) { | 460 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) { |
| 460 // TODO(paulg): Bug: http://b/1084719, skip this test on Windows 2000 until | |
| 461 // this bug is fixed. | |
| 462 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 463 return; | |
| 464 | |
| 465 const unsigned char get_hash[] = { | 461 const unsigned char get_hash[] = { |
| 466 0x32, 0x56, 0x74, 0x6f, 0x6b, 0x36, 0x64, 0x41, | 462 0x32, 0x56, 0x74, 0x6f, 0x6b, 0x36, 0x64, 0x41, |
| 467 0x51, 0x72, 0x65, 0x51, 0x62, 0x38, 0x51, 0x68, | 463 0x51, 0x72, 0x65, 0x51, 0x62, 0x38, 0x51, 0x68, |
| 468 0x59, 0x45, 0x57, 0x51, 0x57, 0x4d, 0x52, 0x65, | 464 0x59, 0x45, 0x57, 0x51, 0x57, 0x4d, 0x52, 0x65, |
| 469 0x42, 0x63, 0x41, 0x3d, 0x0a, 0x67, 0x6f, 0x6f, | 465 0x42, 0x63, 0x41, 0x3d, 0x0a, 0x67, 0x6f, 0x6f, |
| 470 0x67, 0x2d, 0x70, 0x68, 0x69, 0x73, 0x68, 0x2d, | 466 0x67, 0x2d, 0x70, 0x68, 0x69, 0x73, 0x68, 0x2d, |
| 471 0x73, 0x68, 0x61, 0x76, 0x61, 0x72, 0x3a, 0x36, | 467 0x73, 0x68, 0x61, 0x76, 0x61, 0x72, 0x3a, 0x36, |
| 472 0x31, 0x36, 0x39, 0x3a, 0x33, 0x32, 0x0a, 0x17, | 468 0x31, 0x36, 0x39, 0x3a, 0x33, 0x32, 0x0a, 0x17, |
| 473 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9, 0x0b, | 469 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9, 0x0b, |
| 474 0x1c, 0x7b, 0x9d, 0xaf, 0x7b, 0x43, 0x99, 0x10, | 470 0x1c, 0x7b, 0x9d, 0xaf, 0x7b, 0x43, 0x99, 0x10, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 486 const std::string key = "58Lqn5WIP961x3zuLGo5Uw=="; | 482 const std::string key = "58Lqn5WIP961x3zuLGo5Uw=="; |
| 487 std::vector<SBFullHashResult> full_hashes; | 483 std::vector<SBFullHashResult> full_hashes; |
| 488 bool re_key = false; | 484 bool re_key = false; |
| 489 SafeBrowsingProtocolParser parser; | 485 SafeBrowsingProtocolParser parser; |
| 490 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash), | 486 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash), |
| 491 sizeof(get_hash), | 487 sizeof(get_hash), |
| 492 key, | 488 key, |
| 493 &re_key, | 489 &re_key, |
| 494 &full_hashes)); | 490 &full_hashes)); |
| 495 EXPECT_FALSE(re_key); | 491 EXPECT_FALSE(re_key); |
| 496 EXPECT_EQ(full_hashes.size(), 1); | 492 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(1)); |
| 497 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0); | 493 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0); |
| 498 } | 494 } |
| 495 #endif // defined(OS_WIN) |
| 499 | 496 |
| 500 | 497 |
| 501 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { | 498 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { |
| 502 SafeBrowsingProtocolParser parser; | 499 SafeBrowsingProtocolParser parser; |
| 503 std::vector<SBPrefix> prefixes; | 500 std::vector<SBPrefix> prefixes; |
| 504 std::string get_hash; | 501 std::string get_hash; |
| 505 | 502 |
| 506 prefixes.push_back(0x34333231); | 503 prefixes.push_back(0x34333231); |
| 507 prefixes.push_back(0x64636261); | 504 prefixes.push_back(0x64636261); |
| 508 prefixes.push_back(0x73727170); | 505 prefixes.push_back(0x73727170); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 int next_update = -1; | 548 int next_update = -1; |
| 552 std::vector<SBChunkDelete> deletes; | 549 std::vector<SBChunkDelete> deletes; |
| 553 std::vector<ChunkUrl> urls; | 550 std::vector<ChunkUrl> urls; |
| 554 EXPECT_TRUE(parser.ParseUpdate(update.data(), | 551 EXPECT_TRUE(parser.ParseUpdate(update.data(), |
| 555 static_cast<int>(update.size()), "", | 552 static_cast<int>(update.size()), "", |
| 556 &next_update, &re_key, | 553 &next_update, &re_key, |
| 557 &reset, &deletes, &urls)); | 554 &reset, &deletes, &urls)); |
| 558 EXPECT_TRUE(reset); | 555 EXPECT_TRUE(reset); |
| 559 } | 556 } |
| 560 | 557 |
| 558 // TODO(port): Enable when we have ported VerifyMAC in safe_browsing_util.cc. |
| 559 #if defined(OS_WIN) |
| 561 TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) { | 560 TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) { |
| 562 // TODO(paulg): Bug: http://b/1084719, skip this test on Windows 2000 until | |
| 563 // this bug is fixed. | |
| 564 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 565 return; | |
| 566 | |
| 567 SafeBrowsingProtocolParser parser; | 561 SafeBrowsingProtocolParser parser; |
| 568 | 562 |
| 569 const std::string update = | 563 const std::string update = |
| 570 "m:XIU0LiQhAPJq6dynXwHbygjS5tw=\n" | 564 "m:XIU0LiQhAPJq6dynXwHbygjS5tw=\n" |
| 571 "n:1895\n" | 565 "n:1895\n" |
| 572 "i:goog-phish-shavar\n" | 566 "i:goog-phish-shavar\n" |
| 573 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,pcY
6iVeT9-CBQ3fdAF0rpnKjR1Y=\n" | 567 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,pcY
6iVeT9-CBQ3fdAF0rpnKjR1Y=\n" |
| 574 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6506-6510:6506-6510,SDB
rYC3rX3KEPe72LOypnP6QYac=\n" | 568 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6506-6510:6506-6510,SDB
rYC3rX3KEPe72LOypnP6QYac=\n" |
| 575 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6511-6520:6511-6520,9UQ
o-e7OkcsXT2wFWTAhOuWOsUs=\n" | 569 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6511-6520:6511-6520,9UQ
o-e7OkcsXT2wFWTAhOuWOsUs=\n" |
| 576 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6521-6560:6521-6560,qVN
w6JIpR1q6PIXST7J4LJ9n3Zg=\n" | 570 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6521-6560:6521-6560,qVN
w6JIpR1q6PIXST7J4LJ9n3Zg=\n" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 592 const std::string key("58Lqn5WIP961x3zuLGo5Uw=="); | 586 const std::string key("58Lqn5WIP961x3zuLGo5Uw=="); |
| 593 EXPECT_TRUE(parser.ParseUpdate(update.data(), | 587 EXPECT_TRUE(parser.ParseUpdate(update.data(), |
| 594 static_cast<int>(update.size()), key, | 588 static_cast<int>(update.size()), key, |
| 595 &next_update, &re_key, | 589 &next_update, &re_key, |
| 596 &reset, &deletes, &urls)); | 590 &reset, &deletes, &urls)); |
| 597 EXPECT_FALSE(re_key); | 591 EXPECT_FALSE(re_key); |
| 598 EXPECT_EQ(next_update, 1895); | 592 EXPECT_EQ(next_update, 1895); |
| 599 } | 593 } |
| 600 | 594 |
| 601 TEST(SafeBrowsingProtocolParsingTest, TestVerifyChunkMac) { | 595 TEST(SafeBrowsingProtocolParsingTest, TestVerifyChunkMac) { |
| 602 // TODO(paulg): Bug: http://b/1084719, skip this test on Windows 2000 until | |
| 603 // this bug is fixed. | |
| 604 if (win_util::GetWinVersion() <= win_util::WINVERSION_2000) | |
| 605 return; | |
| 606 | |
| 607 SafeBrowsingProtocolParser parser; | 596 SafeBrowsingProtocolParser parser; |
| 608 | 597 |
| 609 const unsigned char chunk[] = { | 598 const unsigned char chunk[] = { |
| 610 0x73, 0x3a, 0x32, 0x30, 0x30, 0x32, 0x3a, 0x34, | 599 0x73, 0x3a, 0x32, 0x30, 0x30, 0x32, 0x3a, 0x34, |
| 611 0x3a, 0x32, 0x32, 0x0a, 0x2f, 0x4f, 0x89, 0x7a, | 600 0x3a, 0x32, 0x32, 0x0a, 0x2f, 0x4f, 0x89, 0x7a, |
| 612 0x01, 0x00, 0x00, 0x0a, 0x59, 0xc8, 0x71, 0xdf, | 601 0x01, 0x00, 0x00, 0x0a, 0x59, 0xc8, 0x71, 0xdf, |
| 613 0x9d, 0x29, 0x0c, 0xba, 0xd7, 0x00, 0x00, 0x00, | 602 0x9d, 0x29, 0x0c, 0xba, 0xd7, 0x00, 0x00, 0x00, |
| 614 0x0a, 0x59 | 603 0x0a, 0x59 |
| 615 }; | 604 }; |
| 616 | 605 |
| 617 bool re_key = false; | 606 bool re_key = false; |
| 618 std::deque<SBChunk> chunks; | 607 std::deque<SBChunk> chunks; |
| 619 const std::string key("v_aDSz6jI92WeHCOoZ07QA=="); | 608 const std::string key("v_aDSz6jI92WeHCOoZ07QA=="); |
| 620 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk="); | 609 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk="); |
| 621 | 610 |
| 622 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk), | 611 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk), |
| 623 sizeof(chunk), key, mac, | 612 sizeof(chunk), key, mac, |
| 624 &re_key, &chunks)); | 613 &re_key, &chunks)); |
| 625 EXPECT_FALSE(re_key); | 614 EXPECT_FALSE(re_key); |
| 626 | 615 |
| 627 safe_browsing_util::FreeChunks(&chunks); | 616 safe_browsing_util::FreeChunks(&chunks); |
| 628 } | 617 } |
| 618 #endif // defined(OS_WIN) |
| OLD | NEW |