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