| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ssl/chrome_expect_ct_reporter.h" | 5 #include "chrome/browser/ssl/chrome_expect_ct_reporter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 net::TestURLRequestContext* context() { return context_.get(); } | 318 net::TestURLRequestContext* context() { return context_.get(); } |
| 319 | 319 |
| 320 protected: | 320 protected: |
| 321 void SendReport(ChromeExpectCTReporter* reporter, | 321 void SendReport(ChromeExpectCTReporter* reporter, |
| 322 const net::HostPortPair& host_port, | 322 const net::HostPortPair& host_port, |
| 323 const GURL& report_uri, | 323 const GURL& report_uri, |
| 324 const net::SSLInfo& ssl_info) { | 324 const net::SSLInfo& ssl_info) { |
| 325 base::RunLoop run_loop; | 325 base::RunLoop run_loop; |
| 326 network_delegate_.set_url_request_destroyed_callback( | 326 network_delegate_.set_url_request_destroyed_callback( |
| 327 run_loop.QuitClosure()); | 327 run_loop.QuitClosure()); |
| 328 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info); | 328 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info.cert.get(), |
| 329 ssl_info.unverified_cert.get(), |
| 330 ssl_info.signed_certificate_timestamps); |
| 329 run_loop.Run(); | 331 run_loop.Run(); |
| 330 } | 332 } |
| 331 | 333 |
| 332 private: | 334 private: |
| 333 TestExpectCTNetworkDelegate network_delegate_; | 335 TestExpectCTNetworkDelegate network_delegate_; |
| 334 std::unique_ptr<net::TestURLRequestContext> context_; | 336 std::unique_ptr<net::TestURLRequestContext> context_; |
| 335 content::TestBrowserThreadBundle thread_bundle_; | 337 content::TestBrowserThreadBundle thread_bundle_; |
| 336 | 338 |
| 337 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest); | 339 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest); |
| 338 }; | 340 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 357 | 359 |
| 358 net::SSLInfo ssl_info; | 360 net::SSLInfo ssl_info; |
| 359 ssl_info.cert = | 361 ssl_info.cert = |
| 360 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | 362 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
| 361 ssl_info.unverified_cert = net::ImportCertFromFile( | 363 ssl_info.unverified_cert = net::ImportCertFromFile( |
| 362 net::GetTestCertsDirectory(), "localhost_cert.pem"); | 364 net::GetTestCertsDirectory(), "localhost_cert.pem"); |
| 363 | 365 |
| 364 net::HostPortPair host_port("example.test", 443); | 366 net::HostPortPair host_port("example.test", 443); |
| 365 GURL report_uri("http://example-report.test"); | 367 GURL report_uri("http://example-report.test"); |
| 366 | 368 |
| 367 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); | 369 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info.cert.get(), |
| 370 ssl_info.unverified_cert.get(), |
| 371 ssl_info.signed_certificate_timestamps); |
| 368 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 372 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
| 369 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 373 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
| 370 | 374 |
| 371 histograms.ExpectTotalCount(kSendHistogramName, 0); | 375 histograms.ExpectTotalCount(kSendHistogramName, 0); |
| 372 } | 376 } |
| 373 | 377 |
| 374 // Test that no report is sent if the report URI is empty. | 378 // Test that no report is sent if the report URI is empty. |
| 375 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { | 379 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { |
| 376 base::MessageLoop message_loop; | 380 base::MessageLoop message_loop; |
| 377 base::HistogramTester histograms; | 381 base::HistogramTester histograms; |
| 378 histograms.ExpectTotalCount(kSendHistogramName, 0); | 382 histograms.ExpectTotalCount(kSendHistogramName, 0); |
| 379 | 383 |
| 380 TestCertificateReportSender* sender = new TestCertificateReportSender(); | 384 TestCertificateReportSender* sender = new TestCertificateReportSender(); |
| 381 net::TestURLRequestContext context; | 385 net::TestURLRequestContext context; |
| 382 ChromeExpectCTReporter reporter(&context); | 386 ChromeExpectCTReporter reporter(&context); |
| 383 reporter.report_sender_.reset(sender); | 387 reporter.report_sender_.reset(sender); |
| 384 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 388 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
| 385 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 389 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
| 386 | 390 |
| 387 reporter.OnExpectCTFailed(net::HostPortPair("example.test", 443), GURL(), | 391 reporter.OnExpectCTFailed(net::HostPortPair(), GURL(), nullptr, nullptr, |
| 388 net::SSLInfo()); | 392 net::SignedCertificateTimestampAndStatusList()); |
| 389 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 393 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
| 390 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 394 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
| 391 | 395 |
| 392 histograms.ExpectTotalCount(kSendHistogramName, 0); | 396 histograms.ExpectTotalCount(kSendHistogramName, 0); |
| 393 } | 397 } |
| 394 | 398 |
| 395 // Test that if a report fails to send, the UMA metric is recorded. | 399 // Test that if a report fails to send, the UMA metric is recorded. |
| 396 TEST_F(ChromeExpectCTReporterWaitTest, SendReportFailure) { | 400 TEST_F(ChromeExpectCTReporterWaitTest, SendReportFailure) { |
| 397 base::HistogramTester histograms; | 401 base::HistogramTester histograms; |
| 398 histograms.ExpectTotalCount(kFailureHistogramName, 0); | 402 histograms.ExpectTotalCount(kFailureHistogramName, 0); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 &ssl_info.signed_certificate_timestamps); | 480 &ssl_info.signed_certificate_timestamps); |
| 477 MakeTestSCTAndStatus(net::ct::SignedCertificateTimestamp::SCT_EMBEDDED, | 481 MakeTestSCTAndStatus(net::ct::SignedCertificateTimestamp::SCT_EMBEDDED, |
| 478 "valid_log_id2", "extensions2", "signature2", now, | 482 "valid_log_id2", "extensions2", "signature2", now, |
| 479 net::ct::SCT_STATUS_OK, | 483 net::ct::SCT_STATUS_OK, |
| 480 &ssl_info.signed_certificate_timestamps); | 484 &ssl_info.signed_certificate_timestamps); |
| 481 | 485 |
| 482 net::HostPortPair host_port("example.test", 443); | 486 net::HostPortPair host_port("example.test", 443); |
| 483 GURL report_uri("http://example-report.test"); | 487 GURL report_uri("http://example-report.test"); |
| 484 | 488 |
| 485 // Check that the report is sent and contains the correct information. | 489 // Check that the report is sent and contains the correct information. |
| 486 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); | 490 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info.cert.get(), |
| 491 ssl_info.unverified_cert.get(), |
| 492 ssl_info.signed_certificate_timestamps); |
| 487 EXPECT_EQ(report_uri, sender->latest_report_uri()); | 493 EXPECT_EQ(report_uri, sender->latest_report_uri()); |
| 488 EXPECT_FALSE(sender->latest_serialized_report().empty()); | 494 EXPECT_FALSE(sender->latest_serialized_report().empty()); |
| 489 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); | 495 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); |
| 490 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( | 496 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( |
| 491 sender->latest_serialized_report(), host_port, ssl_info)); | 497 sender->latest_serialized_report(), host_port, ssl_info)); |
| 492 | 498 |
| 493 histograms.ExpectTotalCount(kFailureHistogramName, 0); | 499 histograms.ExpectTotalCount(kFailureHistogramName, 0); |
| 494 histograms.ExpectTotalCount(kSendHistogramName, 1); | 500 histograms.ExpectTotalCount(kSendHistogramName, 1); |
| 495 histograms.ExpectBucketCount(kSendHistogramName, true, 1); | 501 histograms.ExpectBucketCount(kSendHistogramName, true, 1); |
| 496 } | 502 } |
| OLD | NEW |