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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 fetcher->set_response_code(net::HTTP_OK); | 291 fetcher->set_response_code(net::HTTP_OK); |
292 fetcher->SetResponseString(GetExpectedV4UpdateResponse(expected_lurs)); | 292 fetcher->SetResponseString(GetExpectedV4UpdateResponse(expected_lurs)); |
293 fetcher->delegate()->OnURLFetchComplete(fetcher); | 293 fetcher->delegate()->OnURLFetchComplete(fetcher); |
294 | 294 |
295 // No error, back off multiplier is unchanged. | 295 // No error, back off multiplier is unchanged. |
296 EXPECT_EQ(0ul, pm->update_error_count_); | 296 EXPECT_EQ(0ul, pm->update_error_count_); |
297 EXPECT_EQ(1ul, pm->update_back_off_mult_); | 297 EXPECT_EQ(1ul, pm->update_back_off_mult_); |
298 EXPECT_FALSE(pm->IsUpdateScheduled()); | 298 EXPECT_FALSE(pm->IsUpdateScheduled()); |
299 } | 299 } |
300 | 300 |
| 301 TEST_F(V4UpdateProtocolManagerTest, TestBase64EncodingUsesUrlEncoding) { |
| 302 // 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 |
| 304 // output. |
| 305 std::string state_minus = "z-R~3ruViQH"; |
| 306 StoreStateMap store_state_map_minus{ |
| 307 {UpdateListIdentifier(LINUX_PLATFORM, URL, MALWARE_THREAT), state_minus}}; |
| 308 std::string encoded_request_with_minus = |
| 309 V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( |
| 310 store_state_map_minus); |
| 311 EXPECT_EQ("GhMIARACGgt6LVJ-M3J1VmlRSCgB", encoded_request_with_minus); |
| 312 |
| 313 // NOTE(vakh): Same process for chosing this string. I am representing it |
| 314 // in base64 encoded form because the actual state value contains non-ASCII |
| 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("GhEIARACGglVMV8hMF_iUEwoAQ==", encoded_request_with_underscore); |
| 326 } |
| 327 |
301 } // namespace safe_browsing | 328 } // namespace safe_browsing |
OLD | NEW |