| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 EXPECT_EQ(expected.platform_type(), actual->platform_type()); | 58 EXPECT_EQ(expected.platform_type(), actual->platform_type()); |
| 59 EXPECT_EQ(expected.response_type(), actual->response_type()); | 59 EXPECT_EQ(expected.response_type(), actual->response_type()); |
| 60 EXPECT_EQ(expected.threat_entry_type(), actual->threat_entry_type()); | 60 EXPECT_EQ(expected.threat_entry_type(), actual->threat_entry_type()); |
| 61 EXPECT_EQ(expected.threat_type(), actual->threat_type()); | 61 EXPECT_EQ(expected.threat_type(), actual->threat_type()); |
| 62 EXPECT_EQ(expected.new_client_state(), actual->new_client_state()); | 62 EXPECT_EQ(expected.new_client_state(), actual->new_client_state()); |
| 63 | 63 |
| 64 // TODO(vakh): Test more fields from the proto. | 64 // TODO(vakh): Test more fields from the proto. |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( | 68 V4ProtocolConfig GetProtocolConfig() { |
| 69 const std::vector<ListUpdateResponse>& expected_lurs) { | |
| 70 V4ProtocolConfig config; | 69 V4ProtocolConfig config; |
| 71 config.client_name = kClient; | 70 config.client_name = kClient; |
| 72 config.version = kAppVer; | 71 config.version = kAppVer; |
| 73 config.key_param = kKeyParam; | 72 config.key_param = kKeyParam; |
| 74 config.disable_auto_update = false; | 73 config.disable_auto_update = false; |
| 74 return config; |
| 75 } |
| 76 |
| 77 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( |
| 78 const std::vector<ListUpdateResponse>& expected_lurs) { |
| 75 return V4UpdateProtocolManager::Create( | 79 return V4UpdateProtocolManager::Create( |
| 76 NULL, config, | 80 NULL, GetProtocolConfig(), |
| 77 base::Bind(&V4UpdateProtocolManagerTest::ValidateGetUpdatesResults, | 81 base::Bind(&V4UpdateProtocolManagerTest::ValidateGetUpdatesResults, |
| 78 base::Unretained(this), expected_lurs)); | 82 base::Unretained(this), expected_lurs)); |
| 79 } | 83 } |
| 80 | 84 |
| 81 void SetupStoreStates() { | 85 void SetupStoreStates() { |
| 82 store_state_map_ = base::MakeUnique<StoreStateMap>(); | 86 store_state_map_ = base::MakeUnique<StoreStateMap>(); |
| 83 | 87 |
| 84 UpdateListIdentifier win_url_malware(WINDOWS_PLATFORM, URL, MALWARE_THREAT); | 88 UpdateListIdentifier win_url_malware(WINDOWS_PLATFORM, URL, MALWARE_THREAT); |
| 85 store_state_map_->insert({win_url_malware, "initial_state_1"}); | 89 store_state_map_->insert({win_url_malware, "initial_state_1"}); |
| 86 | 90 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // No error, back off multiplier is unchanged. | 299 // No error, back off multiplier is unchanged. |
| 296 EXPECT_EQ(0ul, pm->update_error_count_); | 300 EXPECT_EQ(0ul, pm->update_error_count_); |
| 297 EXPECT_EQ(1ul, pm->update_back_off_mult_); | 301 EXPECT_EQ(1ul, pm->update_back_off_mult_); |
| 298 EXPECT_FALSE(pm->IsUpdateScheduled()); | 302 EXPECT_FALSE(pm->IsUpdateScheduled()); |
| 299 } | 303 } |
| 300 | 304 |
| 301 TEST_F(V4UpdateProtocolManagerTest, TestBase64EncodingUsesUrlEncoding) { | 305 TEST_F(V4UpdateProtocolManagerTest, TestBase64EncodingUsesUrlEncoding) { |
| 302 // NOTE(vakh): I handpicked this value for state by generating random strings | 306 // NOTE(vakh): I handpicked this value for state by generating random strings |
| 303 // and picked the one that leads to a '-' in the base64 url encoded request | 307 // and picked the one that leads to a '-' in the base64 url encoded request |
| 304 // output. | 308 // output. |
| 305 std::string state_minus = "z-R~3ruViQH"; | 309 std::string state_minus = "h8xfYqY>:R"; |
| 306 StoreStateMap store_state_map_minus{ | 310 StoreStateMap store_state_map_minus{ |
| 307 {UpdateListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT), state_minus}}; | 311 {UpdateListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT), state_minus}}; |
| 308 std::string encoded_request_with_minus = | 312 std::string encoded_request_with_minus = |
| 309 V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( | 313 V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( |
| 310 store_state_map_minus); | 314 store_state_map_minus, GetProtocolConfig()); |
| 311 EXPECT_EQ("GhkIARACGgt6LVJ-M3J1VmlRSCIEIAEgAigB", encoded_request_with_minus); | 315 EXPECT_EQ("Cg8KCHVuaXR0ZXN0EgMxLjAaGAgBEAIaCmg4eGZZcVk-OlIiBCABIAIoAQ==", |
| 316 encoded_request_with_minus); |
| 312 | 317 |
| 313 // NOTE(vakh): Same process for chosing this string. I am representing it | 318 // TODO(vakh): Add a similar test for underscore for completeness, although |
| 314 // in base64 encoded form because the actual state value contains non-ASCII | 319 // the '-' case is sufficient to prove that we are using URL encoding. |
| 315 // characters. | |
| 316 std::string base64_encoded_state_underscore = "VTFfITBf4lBM"; | |
| 317 std::string state_underscore; | |
| 318 base::Base64Decode(base64_encoded_state_underscore, &state_underscore); | |
| 319 StoreStateMap store_state_map_underscore{ | |
| 320 {UpdateListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT), | |
| 321 state_underscore}}; | |
| 322 std::string encoded_request_with_underscore = | |
| 323 V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( | |
| 324 store_state_map_underscore); | |
| 325 EXPECT_EQ("GhcIARACGglVMV8hMF_iUEwiBCABIAIoAQ==", | |
| 326 encoded_request_with_underscore); | |
| 327 } | 320 } |
| 328 | 321 |
| 329 } // namespace safe_browsing | 322 } // namespace safe_browsing |
| OLD | NEW |