OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/safe_browsing_db/v4_update_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_update_protocol_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 EXPECT_EQ(expected.platform_type(), actual->platform_type()); | 51 EXPECT_EQ(expected.platform_type(), actual->platform_type()); |
52 EXPECT_EQ(expected.response_type(), actual->response_type()); | 52 EXPECT_EQ(expected.response_type(), actual->response_type()); |
53 EXPECT_EQ(expected.threat_entry_type(), actual->threat_entry_type()); | 53 EXPECT_EQ(expected.threat_entry_type(), actual->threat_entry_type()); |
54 EXPECT_EQ(expected.threat_type(), actual->threat_type()); | 54 EXPECT_EQ(expected.threat_type(), actual->threat_type()); |
55 EXPECT_EQ(expected.new_client_state(), actual->new_client_state()); | 55 EXPECT_EQ(expected.new_client_state(), actual->new_client_state()); |
56 | 56 |
57 // TODO(vakh): Test more fields from the proto. | 57 // TODO(vakh): Test more fields from the proto. |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
| 61 ExtendedReportingLevel GetExtendedReportingLevel(ExtendedReportingLevel erl) { |
| 62 return erl; |
| 63 } |
| 64 |
61 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( | 65 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( |
62 const std::vector<ListUpdateResponse>& expected_lurs, | 66 const std::vector<ListUpdateResponse>& expected_lurs, |
63 bool disable_auto_update = false) { | 67 bool disable_auto_update = false, |
| 68 ExtendedReportingLevel erl = SBER_LEVEL_OFF) { |
64 return V4UpdateProtocolManager::Create( | 69 return V4UpdateProtocolManager::Create( |
65 NULL, GetTestV4ProtocolConfig(disable_auto_update), | 70 NULL, GetTestV4ProtocolConfig(disable_auto_update), |
66 base::Bind(&V4UpdateProtocolManagerTest::ValidateGetUpdatesResults, | 71 base::Bind(&V4UpdateProtocolManagerTest::ValidateGetUpdatesResults, |
67 base::Unretained(this), expected_lurs)); | 72 base::Unretained(this), expected_lurs), |
| 73 base::Bind(&V4UpdateProtocolManagerTest::GetExtendedReportingLevel, |
| 74 base::Unretained(this), erl)); |
68 } | 75 } |
69 | 76 |
70 void SetupStoreStates() { | 77 void SetupStoreStates() { |
71 store_state_map_ = base::MakeUnique<StoreStateMap>(); | 78 store_state_map_ = base::MakeUnique<StoreStateMap>(); |
72 | 79 |
73 ListIdentifier win_url_malware(WINDOWS_PLATFORM, URL, MALWARE_THREAT); | 80 ListIdentifier win_url_malware(WINDOWS_PLATFORM, URL, MALWARE_THREAT); |
74 store_state_map_->insert({win_url_malware, "initial_state_1"}); | 81 store_state_map_->insert({win_url_malware, "initial_state_1"}); |
75 | 82 |
76 ListIdentifier win_url_uws(WINDOWS_PLATFORM, URL, UNWANTED_SOFTWARE); | 83 ListIdentifier win_url_uws(WINDOWS_PLATFORM, URL, UNWANTED_SOFTWARE); |
77 store_state_map_->insert({win_url_uws, "initial_state_2"}); | 84 store_state_map_->insert({win_url_uws, "initial_state_2"}); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // output. | 291 // output. |
285 store_state_map_->clear(); | 292 store_state_map_->clear(); |
286 (*store_state_map_)[ListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT)] = | 293 (*store_state_map_)[ListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT)] = |
287 "h8xfYqY>:R"; | 294 "h8xfYqY>:R"; |
288 std::unique_ptr<V4UpdateProtocolManager> pm( | 295 std::unique_ptr<V4UpdateProtocolManager> pm( |
289 CreateProtocolManager(std::vector<ListUpdateResponse>({}))); | 296 CreateProtocolManager(std::vector<ListUpdateResponse>({}))); |
290 pm->store_state_map_ = std::move(store_state_map_); | 297 pm->store_state_map_ = std::move(store_state_map_); |
291 | 298 |
292 std::string encoded_request_with_minus = | 299 std::string encoded_request_with_minus = |
293 pm->GetBase64SerializedUpdateRequestProto(); | 300 pm->GetBase64SerializedUpdateRequestProto(); |
294 EXPECT_EQ("Cg8KCHVuaXR0ZXN0EgMxLjAaGAgBEAIaCmg4eGZZcVk-OlIiBCABIAIoAQ==", | 301 EXPECT_EQ("Cg8KCHVuaXR0ZXN0EgMxLjAaGAgBEAIaCmg4eGZZcVk-OlIiBCABIAIoASICCAE=", |
295 encoded_request_with_minus); | 302 encoded_request_with_minus); |
296 | 303 |
297 // TODO(vakh): Add a similar test for underscore for completeness, although | 304 // TODO(vakh): Add a similar test for underscore for completeness, although |
298 // the '-' case is sufficient to prove that we are using URL encoding. | 305 // the '-' case is sufficient to prove that we are using URL encoding. |
299 } | 306 } |
300 | 307 |
301 TEST_F(V4UpdateProtocolManagerTest, TestDisableAutoUpdates) { | 308 TEST_F(V4UpdateProtocolManagerTest, TestDisableAutoUpdates) { |
302 scoped_refptr<base::TestSimpleTaskRunner> runner( | 309 scoped_refptr<base::TestSimpleTaskRunner> runner( |
303 new base::TestSimpleTaskRunner()); | 310 new base::TestSimpleTaskRunner()); |
304 base::ThreadTaskRunnerHandle runner_handler(runner); | 311 base::ThreadTaskRunnerHandle runner_handler(runner); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 fetcher->set_status(net::URLRequestStatus()); | 358 fetcher->set_status(net::URLRequestStatus()); |
352 fetcher->set_response_code(net::HTTP_OK); | 359 fetcher->set_response_code(net::HTTP_OK); |
353 fetcher->SetResponseString(GetExpectedV4UpdateResponse(expected_lurs)); | 360 fetcher->SetResponseString(GetExpectedV4UpdateResponse(expected_lurs)); |
354 fetcher->delegate()->OnURLFetchComplete(fetcher); | 361 fetcher->delegate()->OnURLFetchComplete(fetcher); |
355 | 362 |
356 // No error, back off multiplier is unchanged. | 363 // No error, back off multiplier is unchanged. |
357 EXPECT_EQ(0ul, pm->update_error_count_); | 364 EXPECT_EQ(0ul, pm->update_error_count_); |
358 EXPECT_EQ(1ul, pm->update_back_off_mult_); | 365 EXPECT_EQ(1ul, pm->update_back_off_mult_); |
359 } | 366 } |
360 | 367 |
| 368 TEST_F(V4UpdateProtocolManagerTest, TestExtendedReportingLevelIncluded) { |
| 369 store_state_map_->clear(); |
| 370 (*store_state_map_)[ListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT)] = |
| 371 "state"; |
| 372 std::string base = "Cg8KCHVuaXR0ZXN0EgMxLjAaEwgBEAIaBXN0YXRlIgQgASACKAEiAgg"; |
| 373 |
| 374 std::unique_ptr<V4UpdateProtocolManager> pm_with_off(CreateProtocolManager( |
| 375 std::vector<ListUpdateResponse>({}), false, SBER_LEVEL_OFF)); |
| 376 pm_with_off->store_state_map_ = std::move(store_state_map_); |
| 377 EXPECT_EQ(base + "B", pm_with_off->GetBase64SerializedUpdateRequestProto()); |
| 378 |
| 379 std::unique_ptr<V4UpdateProtocolManager> pm_with_legacy(CreateProtocolManager( |
| 380 std::vector<ListUpdateResponse>({}), false, SBER_LEVEL_LEGACY)); |
| 381 pm_with_legacy->store_state_map_ = std::move(pm_with_off->store_state_map_); |
| 382 EXPECT_EQ(base + "C", |
| 383 pm_with_legacy->GetBase64SerializedUpdateRequestProto()); |
| 384 |
| 385 std::unique_ptr<V4UpdateProtocolManager> pm_with_scout(CreateProtocolManager( |
| 386 std::vector<ListUpdateResponse>({}), false, SBER_LEVEL_SCOUT)); |
| 387 pm_with_scout->store_state_map_ = std::move(pm_with_legacy->store_state_map_); |
| 388 EXPECT_EQ(base + "D", pm_with_scout->GetBase64SerializedUpdateRequestProto()); |
| 389 } |
| 390 |
361 } // namespace safe_browsing | 391 } // namespace safe_browsing |
OLD | NEW |