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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 // A test ReportSender that exposes the latest report URI and | 33 // A test ReportSender that exposes the latest report URI and |
34 // serialized report to be sent. | 34 // serialized report to be sent. |
35 class TestCertificateReportSender : public net::ReportSender { | 35 class TestCertificateReportSender : public net::ReportSender { |
36 public: | 36 public: |
37 TestCertificateReportSender() | 37 TestCertificateReportSender() |
38 : ReportSender(nullptr, net::ReportSender::DO_NOT_SEND_COOKIES) {} | 38 : ReportSender(nullptr, net::ReportSender::DO_NOT_SEND_COOKIES) {} |
39 ~TestCertificateReportSender() override {} | 39 ~TestCertificateReportSender() override {} |
40 | 40 |
41 void Send(const GURL& report_uri, | 41 void Send(const GURL& report_uri, |
42 const std::string& serialized_report) override { | 42 base::StringPiece content_type, |
| 43 base::StringPiece serialized_report) override { |
43 latest_report_uri_ = report_uri; | 44 latest_report_uri_ = report_uri; |
44 latest_serialized_report_ = serialized_report; | 45 serialized_report.CopyToString(&latest_serialized_report_); |
| 46 content_type.CopyToString(&latest_content_type_); |
45 } | 47 } |
46 | 48 |
47 const GURL& latest_report_uri() { return latest_report_uri_; } | 49 const GURL& latest_report_uri() { return latest_report_uri_; } |
48 | 50 |
| 51 const std::string& latest_content_type() { return latest_content_type_; } |
| 52 |
49 const std::string& latest_serialized_report() { | 53 const std::string& latest_serialized_report() { |
50 return latest_serialized_report_; | 54 return latest_serialized_report_; |
51 } | 55 } |
52 | 56 |
53 private: | 57 private: |
54 GURL latest_report_uri_; | 58 GURL latest_report_uri_; |
| 59 std::string latest_content_type_; |
55 std::string latest_serialized_report_; | 60 std::string latest_serialized_report_; |
56 }; | 61 }; |
57 | 62 |
58 // Constructs a net::SignedCertificateTimestampAndStatus with the given | 63 // Constructs a net::SignedCertificateTimestampAndStatus with the given |
59 // information and appends it to |sct_list|. | 64 // information and appends it to |sct_list|. |
60 void MakeTestSCTAndStatus( | 65 void MakeTestSCTAndStatus( |
61 net::ct::SignedCertificateTimestamp::Origin origin, | 66 net::ct::SignedCertificateTimestamp::Origin origin, |
62 const std::string& log_id, | 67 const std::string& log_id, |
63 const std::string& extensions, | 68 const std::string& extensions, |
64 const std::string& signature_data, | 69 const std::string& signature_data, |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 net::ct::SCT_STATUS_OK, | 476 net::ct::SCT_STATUS_OK, |
472 &ssl_info.signed_certificate_timestamps); | 477 &ssl_info.signed_certificate_timestamps); |
473 | 478 |
474 net::HostPortPair host_port("example.test", 443); | 479 net::HostPortPair host_port("example.test", 443); |
475 GURL report_uri("http://example-report.test"); | 480 GURL report_uri("http://example-report.test"); |
476 | 481 |
477 // Check that the report is sent and contains the correct information. | 482 // Check that the report is sent and contains the correct information. |
478 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); | 483 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); |
479 EXPECT_EQ(report_uri, sender->latest_report_uri()); | 484 EXPECT_EQ(report_uri, sender->latest_report_uri()); |
480 EXPECT_FALSE(sender->latest_serialized_report().empty()); | 485 EXPECT_FALSE(sender->latest_serialized_report().empty()); |
| 486 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); |
481 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( | 487 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( |
482 sender->latest_serialized_report(), host_port, ssl_info)); | 488 sender->latest_serialized_report(), host_port, ssl_info)); |
483 | 489 |
484 histograms.ExpectTotalCount(kFailureHistogramName, 0); | 490 histograms.ExpectTotalCount(kFailureHistogramName, 0); |
485 histograms.ExpectTotalCount(kSendHistogramName, 1); | 491 histograms.ExpectTotalCount(kSendHistogramName, 1); |
486 histograms.ExpectBucketCount(kSendHistogramName, true, 1); | 492 histograms.ExpectBucketCount(kSendHistogramName, true, 1); |
487 } | 493 } |
OLD | NEW |