OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/data_reduction_proxy/browser/data_reduction_proxy_tamper_de
tection.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_tamper_de
tection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/md5.h" | 13 #include "base/md5.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
18 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers_te
st_utils.h" | |
19 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
23 #include "base/android/jni_android.h" | 22 #include "base/android/jni_android.h" |
24 #include "net/android/network_library.h" | 23 #include "net/android/network_library.h" |
25 #endif | 24 #endif |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
| 28 void HeadersToRaw(std::string* headers) { |
| 29 std::replace(headers->begin(), headers->end(), '\n', '\0'); |
| 30 if (!headers->empty()) |
| 31 *headers += '\0'; |
| 32 } |
| 33 |
29 // Calcuates MD5 hash value for a string and then base64 encode it. Testcases | 34 // Calcuates MD5 hash value for a string and then base64 encode it. Testcases |
30 // contain expected fingerprint in plain text, which needs to be encoded before | 35 // contain expected fingerprint in plain text, which needs to be encoded before |
31 // comparison. | 36 // comparison. |
32 std::string GetEncoded(const std::string& input) { | 37 std::string GetEncoded(const std::string& input) { |
33 base::MD5Digest digest; | 38 base::MD5Digest digest; |
34 base::MD5Sum(input.c_str(), input.size(), &digest); | 39 base::MD5Sum(input.c_str(), input.size(), &digest); |
35 std::string base64encoded; | 40 std::string base64encoded; |
36 base::Base64Encode(std::string((char*)digest.a, | 41 base::Base64Encode(std::string((char*)digest.a, |
37 ARRAYSIZE_UNSAFE(digest.a)), &base64encoded); | 42 ARRAYSIZE_UNSAFE(digest.a)), &base64encoded); |
38 return base64encoded; | 43 return base64encoded; |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 new net::HttpResponseHeaders(raw_headers)); | 748 new net::HttpResponseHeaders(raw_headers)); |
744 | 749 |
745 EXPECT_EQ( | 750 EXPECT_EQ( |
746 test[i].expected_tampered_with, | 751 test[i].expected_tampered_with, |
747 DataReductionProxyTamperDetection::DetectAndReport(headers.get(), true)) | 752 DataReductionProxyTamperDetection::DetectAndReport(headers.get(), true)) |
748 << test[i].label; | 753 << test[i].label; |
749 } | 754 } |
750 } | 755 } |
751 | 756 |
752 } // namespace | 757 } // namespace |
OLD | NEW |