OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/net/certificate_error_reporter.h" | 5 #include "chrome/browser/net/certificate_error_reporter.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/field_trial.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/test/mock_entropy_provider.h" |
18 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
19 #include "chrome/browser/net/cert_logger.pb.h" | 21 #include "chrome/browser/net/cert_logger.pb.h" |
20 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
22 #include "crypto/curve25519.h" | 24 #include "crypto/curve25519.h" |
23 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
24 #include "net/base/network_delegate_impl.h" | 26 #include "net/base/network_delegate_impl.h" |
25 #include "net/base/test_data_directory.h" | 27 #include "net/base/test_data_directory.h" |
26 #include "net/base/upload_bytes_element_reader.h" | 28 #include "net/base/upload_bytes_element_reader.h" |
27 #include "net/base/upload_data_stream.h" | 29 #include "net/base/upload_data_stream.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 377 |
376 // Test that a request that returns an error gets cleaned up. | 378 // Test that a request that returns an error gets cleaned up. |
377 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { | 379 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { |
378 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); | 380 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); |
379 CertificateErrorReporter reporter( | 381 CertificateErrorReporter reporter( |
380 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 382 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
381 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 383 SendReport(&reporter, network_delegate(), kHostname, url, 0, |
382 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); | 384 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); |
383 } | 385 } |
384 | 386 |
| 387 // Test that the Finch config correctly controls whether the reporter |
| 388 // supports HTTP uploads. |
| 389 TEST_F(CertificateErrorReporterTest, FinchConfigDisablesHttpUploads) { |
| 390 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 391 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 392 chrome_browser_net::kHttpCertificateUploadExperiment, |
| 393 "not the right group")); |
| 394 |
| 395 EXPECT_FALSE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 396 } |
| 397 |
| 398 TEST_F(CertificateErrorReporterTest, FinchConfigPossiblyEnablesHttpUploads) { |
| 399 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 400 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 401 chrome_browser_net::kHttpCertificateUploadExperiment, |
| 402 chrome_browser_net::kHttpCertificateUploadGroup)); |
| 403 |
| 404 #if defined(USE_OPENSSL) |
| 405 EXPECT_TRUE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 406 #else |
| 407 EXPECT_FALSE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 408 #endif |
| 409 } |
| 410 |
385 // Test that cookies are sent or not sent according to the error | 411 // Test that cookies are sent or not sent according to the error |
386 // reporter's cookies preference. | 412 // reporter's cookies preference. |
387 | 413 |
388 TEST_F(CertificateErrorReporterTest, SendCookiesPreference) { | 414 TEST_F(CertificateErrorReporterTest, SendCookiesPreference) { |
389 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 415 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
390 CertificateErrorReporter reporter(context(), url, | 416 CertificateErrorReporter reporter(context(), url, |
391 CertificateErrorReporter::SEND_COOKIES); | 417 CertificateErrorReporter::SEND_COOKIES); |
392 | 418 |
393 network_delegate()->set_expect_cookies(true); | 419 network_delegate()->set_expect_cookies(true); |
394 SendReport(&reporter, network_delegate(), kHostname, url, 0, | 420 SendReport(&reporter, network_delegate(), kHostname, url, 0, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 ASSERT_TRUE(encrypted_request.ParseFromString(std::string( | 588 ASSERT_TRUE(encrypted_request.ParseFromString(std::string( |
563 (char*) kSerializedEncryptedReport, sizeof(kSerializedEncryptedReport)))); | 589 (char*) kSerializedEncryptedReport, sizeof(kSerializedEncryptedReport)))); |
564 ASSERT_TRUE(chrome_browser_net::CertificateErrorReporter:: | 590 ASSERT_TRUE(chrome_browser_net::CertificateErrorReporter:: |
565 DecryptCertificateErrorReport( | 591 DecryptCertificateErrorReport( |
566 network_delegate()->server_private_key(), | 592 network_delegate()->server_private_key(), |
567 encrypted_request, &request)); | 593 encrypted_request, &request)); |
568 } | 594 } |
569 #endif | 595 #endif |
570 | 596 |
571 } // namespace | 597 } // namespace |
OLD | NEW |