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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 334 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
335 feature_list->InitializeFromCommandLine(features::kExpectCTReporting.name, | 335 feature_list->InitializeFromCommandLine(features::kExpectCTReporting.name, |
336 ""); | 336 ""); |
337 base::FeatureList::SetInstance(std::move(feature_list)); | 337 base::FeatureList::SetInstance(std::move(feature_list)); |
338 } | 338 } |
339 | 339 |
340 } // namespace | 340 } // namespace |
341 | 341 |
342 // Test that no report is sent when the feature is not enabled. | 342 // Test that no report is sent when the feature is not enabled. |
343 TEST(ChromeExpectCTReporterTest, FeatureDisabled) { | 343 TEST(ChromeExpectCTReporterTest, FeatureDisabled) { |
| 344 content::TestBrowserThreadBundle thread_bundle; |
344 base::HistogramTester histograms; | 345 base::HistogramTester histograms; |
345 histograms.ExpectTotalCount(kSendHistogramName, 0); | 346 histograms.ExpectTotalCount(kSendHistogramName, 0); |
346 | 347 |
347 TestCertificateReportSender* sender = new TestCertificateReportSender(); | 348 TestCertificateReportSender* sender = new TestCertificateReportSender(); |
348 net::TestURLRequestContext context; | 349 net::TestURLRequestContext context; |
349 ChromeExpectCTReporter reporter(&context); | 350 ChromeExpectCTReporter reporter(&context); |
350 reporter.report_sender_.reset(sender); | 351 reporter.report_sender_.reset(sender); |
351 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 352 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
352 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 353 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
353 | 354 |
354 net::SSLInfo ssl_info; | 355 net::SSLInfo ssl_info; |
355 ssl_info.cert = | 356 ssl_info.cert = |
356 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | 357 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
357 ssl_info.unverified_cert = net::ImportCertFromFile( | 358 ssl_info.unverified_cert = net::ImportCertFromFile( |
358 net::GetTestCertsDirectory(), "localhost_cert.pem"); | 359 net::GetTestCertsDirectory(), "localhost_cert.pem"); |
359 | 360 |
360 net::HostPortPair host_port("example.test", 443); | 361 net::HostPortPair host_port("example.test", 443); |
361 GURL report_uri("http://example-report.test"); | 362 GURL report_uri("http://example-report.test"); |
362 | 363 |
363 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); | 364 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); |
364 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 365 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
365 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 366 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
366 | 367 |
367 histograms.ExpectTotalCount(kSendHistogramName, 0); | 368 histograms.ExpectTotalCount(kSendHistogramName, 0); |
368 } | 369 } |
369 | 370 |
370 // Test that no report is sent if the report URI is empty. | 371 // Test that no report is sent if the report URI is empty. |
371 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { | 372 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { |
| 373 content::TestBrowserThreadBundle thread_bundle; |
372 base::HistogramTester histograms; | 374 base::HistogramTester histograms; |
373 histograms.ExpectTotalCount(kSendHistogramName, 0); | 375 histograms.ExpectTotalCount(kSendHistogramName, 0); |
374 | 376 |
375 EnableFeature(); | 377 EnableFeature(); |
376 TestCertificateReportSender* sender = new TestCertificateReportSender(); | 378 TestCertificateReportSender* sender = new TestCertificateReportSender(); |
377 net::TestURLRequestContext context; | 379 net::TestURLRequestContext context; |
378 ChromeExpectCTReporter reporter(&context); | 380 ChromeExpectCTReporter reporter(&context); |
379 reporter.report_sender_.reset(sender); | 381 reporter.report_sender_.reset(sender); |
380 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 382 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
381 EXPECT_TRUE(sender->latest_serialized_report().empty()); | 383 EXPECT_TRUE(sender->latest_serialized_report().empty()); |
(...skipping 29 matching lines...) Expand all Loading... |
411 | 413 |
412 histograms.ExpectTotalCount(kFailureHistogramName, 1); | 414 histograms.ExpectTotalCount(kFailureHistogramName, 1); |
413 histograms.ExpectBucketCount(kFailureHistogramName, | 415 histograms.ExpectBucketCount(kFailureHistogramName, |
414 -net::ERR_CONNECTION_FAILED, 1); | 416 -net::ERR_CONNECTION_FAILED, 1); |
415 histograms.ExpectTotalCount(kSendHistogramName, 1); | 417 histograms.ExpectTotalCount(kSendHistogramName, 1); |
416 histograms.ExpectBucketCount(kSendHistogramName, true, 1); | 418 histograms.ExpectBucketCount(kSendHistogramName, true, 1); |
417 } | 419 } |
418 | 420 |
419 // Test that a sent report has the right format. | 421 // Test that a sent report has the right format. |
420 TEST(ChromeExpectCTReporterTest, SendReport) { | 422 TEST(ChromeExpectCTReporterTest, SendReport) { |
| 423 content::TestBrowserThreadBundle thread_bundle; |
421 base::HistogramTester histograms; | 424 base::HistogramTester histograms; |
422 histograms.ExpectTotalCount(kFailureHistogramName, 0); | 425 histograms.ExpectTotalCount(kFailureHistogramName, 0); |
423 histograms.ExpectTotalCount(kSendHistogramName, 0); | 426 histograms.ExpectTotalCount(kSendHistogramName, 0); |
424 | 427 |
425 EnableFeature(); | 428 EnableFeature(); |
426 TestCertificateReportSender* sender = new TestCertificateReportSender(); | 429 TestCertificateReportSender* sender = new TestCertificateReportSender(); |
427 net::TestURLRequestContext context; | 430 net::TestURLRequestContext context; |
428 ChromeExpectCTReporter reporter(&context); | 431 ChromeExpectCTReporter reporter(&context); |
429 reporter.report_sender_.reset(sender); | 432 reporter.report_sender_.reset(sender); |
430 EXPECT_TRUE(sender->latest_report_uri().is_empty()); | 433 EXPECT_TRUE(sender->latest_report_uri().is_empty()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 EXPECT_EQ(report_uri, sender->latest_report_uri()); | 487 EXPECT_EQ(report_uri, sender->latest_report_uri()); |
485 EXPECT_FALSE(sender->latest_serialized_report().empty()); | 488 EXPECT_FALSE(sender->latest_serialized_report().empty()); |
486 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); | 489 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); |
487 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( | 490 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( |
488 sender->latest_serialized_report(), host_port, ssl_info)); | 491 sender->latest_serialized_report(), host_port, ssl_info)); |
489 | 492 |
490 histograms.ExpectTotalCount(kFailureHistogramName, 0); | 493 histograms.ExpectTotalCount(kFailureHistogramName, 0); |
491 histograms.ExpectTotalCount(kSendHistogramName, 1); | 494 histograms.ExpectTotalCount(kSendHistogramName, 1); |
492 histograms.ExpectBucketCount(kSendHistogramName, true, 1); | 495 histograms.ExpectBucketCount(kSendHistogramName, true, 1); |
493 } | 496 } |
OLD | NEW |