| 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/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/test/mock_entropy_provider.h" |
| 15 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/net/encrypted_cert_logger.pb.h" | 18 #include "chrome/browser/net/encrypted_cert_logger.pb.h" |
| 17 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "crypto/curve25519.h" | 21 #include "crypto/curve25519.h" |
| 20 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 21 #include "net/base/network_delegate_impl.h" | 23 #include "net/base/network_delegate_impl.h" |
| 22 #include "net/base/upload_bytes_element_reader.h" | 24 #include "net/base/upload_bytes_element_reader.h" |
| 23 #include "net/base/upload_data_stream.h" | 25 #include "net/base/upload_data_stream.h" |
| 24 #include "net/base/upload_element_reader.h" | 26 #include "net/base/upload_element_reader.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 319 |
| 318 // Test that a request that returns an error gets cleaned up. | 320 // Test that a request that returns an error gets cleaned up. |
| 319 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { | 321 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { |
| 320 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); | 322 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); |
| 321 CertificateErrorReporter reporter( | 323 CertificateErrorReporter reporter( |
| 322 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); | 324 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); |
| 323 SendReport(&reporter, network_delegate(), kDummyReport, url, 0, | 325 SendReport(&reporter, network_delegate(), kDummyReport, url, 0, |
| 324 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); | 326 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); |
| 325 } | 327 } |
| 326 | 328 |
| 329 // Test that the Finch config correctly controls whether the reporter |
| 330 // supports HTTP uploads. |
| 331 TEST_F(CertificateErrorReporterTest, FinchConfigDisablesHttpUploads) { |
| 332 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 333 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 334 chrome_browser_net::kHttpCertificateUploadExperiment, |
| 335 "not the right group")); |
| 336 |
| 337 EXPECT_FALSE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 338 } |
| 339 |
| 340 TEST_F(CertificateErrorReporterTest, FinchConfigPossiblyEnablesHttpUploads) { |
| 341 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 342 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 343 chrome_browser_net::kHttpCertificateUploadExperiment, |
| 344 chrome_browser_net::kHttpCertificateUploadGroup)); |
| 345 |
| 346 #if defined(USE_OPENSSL) |
| 347 EXPECT_TRUE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 348 #else |
| 349 EXPECT_FALSE(CertificateErrorReporter::IsHttpUploadUrlSupported()); |
| 350 #endif |
| 351 } |
| 352 |
| 327 // Test that cookies are sent or not sent according to the error | 353 // Test that cookies are sent or not sent according to the error |
| 328 // reporter's cookies preference. | 354 // reporter's cookies preference. |
| 329 | 355 |
| 330 TEST_F(CertificateErrorReporterTest, SendCookiesPreference) { | 356 TEST_F(CertificateErrorReporterTest, SendCookiesPreference) { |
| 331 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 357 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
| 332 CertificateErrorReporter reporter(context(), url, | 358 CertificateErrorReporter reporter(context(), url, |
| 333 CertificateErrorReporter::SEND_COOKIES); | 359 CertificateErrorReporter::SEND_COOKIES); |
| 334 | 360 |
| 335 network_delegate()->set_expect_cookies(true); | 361 network_delegate()->set_expect_cookies(true); |
| 336 SendReport(&reporter, network_delegate(), kDummyReport, url, 0, | 362 SendReport(&reporter, network_delegate(), kDummyReport, url, 0, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), | 531 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), |
| 506 sizeof(kSerializedEncryptedReport)))); | 532 sizeof(kSerializedEncryptedReport)))); |
| 507 ASSERT_TRUE(chrome_browser_net::CertificateErrorReporter:: | 533 ASSERT_TRUE(chrome_browser_net::CertificateErrorReporter:: |
| 508 DecryptCertificateErrorReport( | 534 DecryptCertificateErrorReport( |
| 509 network_delegate()->server_private_key(), | 535 network_delegate()->server_private_key(), |
| 510 encrypted_request, &decrypted_serialized_report)); | 536 encrypted_request, &decrypted_serialized_report)); |
| 511 } | 537 } |
| 512 #endif | 538 #endif |
| 513 | 539 |
| 514 } // namespace | 540 } // namespace |
| OLD | NEW |