| 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> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 245 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 246 ReplaceWithEncodedString(&test[i].received_fingerprint); | 246 ReplaceWithEncodedString(&test[i].received_fingerprint); |
| 247 | 247 |
| 248 std::string raw_headers(test[i].raw_header); | 248 std::string raw_headers(test[i].raw_header); |
| 249 HeadersToRaw(&raw_headers); | 249 HeadersToRaw(&raw_headers); |
| 250 scoped_refptr<net::HttpResponseHeaders> headers( | 250 scoped_refptr<net::HttpResponseHeaders> headers( |
| 251 new net::HttpResponseHeaders(raw_headers)); | 251 new net::HttpResponseHeaders(raw_headers)); |
| 252 | 252 |
| 253 DataReductionProxyTamperDetection tamper_detection(headers, true, 0); | 253 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0); |
| 254 | 254 |
| 255 bool tampered = tamper_detection.ValidateChromeProxyHeader( | 255 bool tampered = tamper_detection.ValidateChromeProxyHeader( |
| 256 test[i].received_fingerprint); | 256 test[i].received_fingerprint); |
| 257 | 257 |
| 258 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; | 258 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 // Tests function ValidateViaHeader. | 262 // Tests function ValidateViaHeader. |
| 263 TEST_F(DataReductionProxyTamperDetectionTest, Via) { | 263 TEST_F(DataReductionProxyTamperDetectionTest, Via) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 false, | 367 false, |
| 368 }, | 368 }, |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 371 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 372 std::string raw_headers(test[i].raw_header); | 372 std::string raw_headers(test[i].raw_header); |
| 373 HeadersToRaw(&raw_headers); | 373 HeadersToRaw(&raw_headers); |
| 374 scoped_refptr<net::HttpResponseHeaders> headers( | 374 scoped_refptr<net::HttpResponseHeaders> headers( |
| 375 new net::HttpResponseHeaders(raw_headers)); | 375 new net::HttpResponseHeaders(raw_headers)); |
| 376 | 376 |
| 377 DataReductionProxyTamperDetection tamper_detection(headers, true, 0); | 377 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0); |
| 378 | 378 |
| 379 bool has_chrome_proxy_via_header; | 379 bool has_chrome_proxy_via_header; |
| 380 bool tampered = tamper_detection.ValidateViaHeader( | 380 bool tampered = tamper_detection.ValidateViaHeader( |
| 381 test[i].received_fingerprint, &has_chrome_proxy_via_header); | 381 test[i].received_fingerprint, &has_chrome_proxy_via_header); |
| 382 | 382 |
| 383 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; | 383 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; |
| 384 EXPECT_EQ(test[i].expected_has_chrome_proxy_via_header, | 384 EXPECT_EQ(test[i].expected_has_chrome_proxy_via_header, |
| 385 has_chrome_proxy_via_header) << test[i].label; | 385 has_chrome_proxy_via_header) << test[i].label; |
| 386 } | 386 } |
| 387 } | 387 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 }; | 500 }; |
| 501 | 501 |
| 502 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 502 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 503 ReplaceWithEncodedString(&test[i].received_fingerprint); | 503 ReplaceWithEncodedString(&test[i].received_fingerprint); |
| 504 | 504 |
| 505 std::string raw_headers(test[i].raw_header); | 505 std::string raw_headers(test[i].raw_header); |
| 506 HeadersToRaw(&raw_headers); | 506 HeadersToRaw(&raw_headers); |
| 507 scoped_refptr<net::HttpResponseHeaders> headers( | 507 scoped_refptr<net::HttpResponseHeaders> headers( |
| 508 new net::HttpResponseHeaders(raw_headers)); | 508 new net::HttpResponseHeaders(raw_headers)); |
| 509 | 509 |
| 510 DataReductionProxyTamperDetection tamper_detection(headers, true, 0); | 510 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0); |
| 511 | 511 |
| 512 bool tampered = tamper_detection.ValidateOtherHeaders( | 512 bool tampered = tamper_detection.ValidateOtherHeaders( |
| 513 test[i].received_fingerprint); | 513 test[i].received_fingerprint); |
| 514 | 514 |
| 515 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; | 515 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; |
| 516 } | 516 } |
| 517 } | 517 } |
| 518 | 518 |
| 519 // Tests function ValidateContentLengthHeader. | 519 // Tests function ValidateContentLengthHeader. |
| 520 TEST_F(DataReductionProxyTamperDetectionTest, ContentLength) { | 520 TEST_F(DataReductionProxyTamperDetectionTest, ContentLength) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 false, | 576 false, |
| 577 }, | 577 }, |
| 578 }; | 578 }; |
| 579 | 579 |
| 580 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 580 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 581 std::string raw_headers(test[i].raw_header); | 581 std::string raw_headers(test[i].raw_header); |
| 582 HeadersToRaw(&raw_headers); | 582 HeadersToRaw(&raw_headers); |
| 583 scoped_refptr<net::HttpResponseHeaders> headers( | 583 scoped_refptr<net::HttpResponseHeaders> headers( |
| 584 new net::HttpResponseHeaders(raw_headers)); | 584 new net::HttpResponseHeaders(raw_headers)); |
| 585 | 585 |
| 586 DataReductionProxyTamperDetection tamper_detection(headers, true, 0); | 586 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0); |
| 587 | 587 |
| 588 bool tampered = tamper_detection.ValidateContentLengthHeader( | 588 bool tampered = tamper_detection.ValidateContentLengthHeader( |
| 589 test[i].received_fingerprint); | 589 test[i].received_fingerprint); |
| 590 | 590 |
| 591 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; | 591 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 // Tests ValuesToSortedString function. | 595 // Tests ValuesToSortedString function. |
| 596 TEST_F(DataReductionProxyTamperDetectionTest, ValuesToSortedString) { | 596 TEST_F(DataReductionProxyTamperDetectionTest, ValuesToSortedString) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 667 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 668 std::string raw_headers(test[i].raw_header); | 668 std::string raw_headers(test[i].raw_header); |
| 669 HeadersToRaw(&raw_headers); | 669 HeadersToRaw(&raw_headers); |
| 670 scoped_refptr<net::HttpResponseHeaders> headers( | 670 scoped_refptr<net::HttpResponseHeaders> headers( |
| 671 new net::HttpResponseHeaders(raw_headers)); | 671 new net::HttpResponseHeaders(raw_headers)); |
| 672 | 672 |
| 673 std::vector<std::string> expected_output_values = | 673 std::vector<std::string> expected_output_values = |
| 674 StringsToVector(test[i].expected_output_values); | 674 StringsToVector(test[i].expected_output_values); |
| 675 | 675 |
| 676 std::vector<std::string> output_values = | 676 std::vector<std::string> output_values = |
| 677 DataReductionProxyTamperDetection::GetHeaderValues( | 677 DataReductionProxyTamperDetection::GetHeaderValues(headers.get(), |
| 678 headers, test[i].header_name); | 678 test[i].header_name); |
| 679 EXPECT_EQ(expected_output_values, output_values) << test[i].label; | 679 EXPECT_EQ(expected_output_values, output_values) << test[i].label; |
| 680 } | 680 } |
| 681 } | 681 } |
| 682 | 682 |
| 683 // Tests main function DetectAndReport. | 683 // Tests main function DetectAndReport. |
| 684 TEST_F(DataReductionProxyTamperDetectionTest, DetectAndReport) { | 684 TEST_F(DataReductionProxyTamperDetectionTest, DetectAndReport) { |
| 685 struct { | 685 struct { |
| 686 std::string label; | 686 std::string label; |
| 687 std::string raw_header; | 687 std::string raw_header; |
| 688 bool expected_tampered_with; | 688 bool expected_tampered_with; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 740 |
| 741 InitEnv(); | 741 InitEnv(); |
| 742 | 742 |
| 743 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { | 743 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 744 std::string raw_headers(test[i].raw_header); | 744 std::string raw_headers(test[i].raw_header); |
| 745 ReplaceWithEncodedString(&raw_headers); | 745 ReplaceWithEncodedString(&raw_headers); |
| 746 HeadersToRaw(&raw_headers); | 746 HeadersToRaw(&raw_headers); |
| 747 scoped_refptr<net::HttpResponseHeaders> headers( | 747 scoped_refptr<net::HttpResponseHeaders> headers( |
| 748 new net::HttpResponseHeaders(raw_headers)); | 748 new net::HttpResponseHeaders(raw_headers)); |
| 749 | 749 |
| 750 EXPECT_EQ(test[i].expected_tampered_with, | 750 EXPECT_EQ( |
| 751 DataReductionProxyTamperDetection::DetectAndReport(headers, true)) | 751 test[i].expected_tampered_with, |
| 752 DataReductionProxyTamperDetection::DetectAndReport(headers.get(), true)) |
| 752 << test[i].label; | 753 << test[i].label; |
| 753 } | 754 } |
| 754 } | 755 } |
| 755 | 756 |
| 756 } // namespace | 757 } // namespace |
| OLD | NEW |