| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/transport_security_state.h" | 5 #include "net/http/transport_security_state.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 const char* const kBadPath[] = { | 71 const char* const kBadPath[] = { |
| 72 "sha1/111111111111111111111111111=", | 72 "sha1/111111111111111111111111111=", |
| 73 "sha1/222222222222222222222222222=", | 73 "sha1/222222222222222222222222222=", |
| 74 "sha1/333333333333333333333333333=", | 74 "sha1/333333333333333333333333333=", |
| 75 "sha256/1111111111111111111111111111111111111111111=", | 75 "sha256/1111111111111111111111111111111111111111111=", |
| 76 "sha256/2222222222222222222222222222222222222222222=", | 76 "sha256/2222222222222222222222222222222222222222222=", |
| 77 "sha256/3333333333333333333333333333333333333333333=", | 77 "sha256/3333333333333333333333333333333333333333333=", |
| 78 nullptr, | 78 nullptr, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // A mock ReportSender that just remembers the latest report | 81 // A mock ReportSenderInterface that just remembers the latest report |
| 82 // URI and report to be sent. | 82 // URI and report to be sent. |
| 83 class MockCertificateReportSender | 83 class MockCertificateReportSender |
| 84 : public TransportSecurityState::ReportSender { | 84 : public TransportSecurityState::ReportSenderInterface { |
| 85 public: | 85 public: |
| 86 MockCertificateReportSender() {} | 86 MockCertificateReportSender() {} |
| 87 ~MockCertificateReportSender() override {} | 87 ~MockCertificateReportSender() override {} |
| 88 | 88 |
| 89 void Send(const GURL& report_uri, const std::string& report) override { | 89 void Send(const GURL& report_uri, const std::string& report) override { |
| 90 latest_report_uri_ = report_uri; | 90 latest_report_uri_ = report_uri; |
| 91 latest_report_ = report; | 91 latest_report_ = report; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SetErrorCallback( | 94 void SetErrorCallback( |
| 95 const base::Callback<void(const GURL&, int)>& error_callback) override {} | 95 const base::Callback<void(const GURL&, int)>& error_callback) override {} |
| 96 | 96 |
| 97 void Clear() { | 97 void Clear() { |
| 98 latest_report_uri_ = GURL(); | 98 latest_report_uri_ = GURL(); |
| 99 latest_report_ = std::string(); | 99 latest_report_ = std::string(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 const GURL& latest_report_uri() { return latest_report_uri_; } | 102 const GURL& latest_report_uri() { return latest_report_uri_; } |
| 103 const std::string& latest_report() { return latest_report_; } | 103 const std::string& latest_report() { return latest_report_; } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 GURL latest_report_uri_; | 106 GURL latest_report_uri_; |
| 107 std::string latest_report_; | 107 std::string latest_report_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // A mock ReportSender that simulates a net error on every report sent. | 110 // A mock ReportSenderInterface that simulates a net error on every report sent. |
| 111 class MockFailingCertificateReportSender | 111 class MockFailingCertificateReportSender |
| 112 : public TransportSecurityState::ReportSender { | 112 : public TransportSecurityState::ReportSenderInterface { |
| 113 public: | 113 public: |
| 114 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} | 114 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} |
| 115 ~MockFailingCertificateReportSender() override {} | 115 ~MockFailingCertificateReportSender() override {} |
| 116 | 116 |
| 117 int net_error() { return net_error_; } | 117 int net_error() { return net_error_; } |
| 118 | 118 |
| 119 // TransportSecurityState::ReportSender: | 119 // TransportSecurityState::ReportSenderInterface: |
| 120 void Send(const GURL& report_uri, const std::string& report) override { | 120 void Send(const GURL& report_uri, const std::string& report) override { |
| 121 ASSERT_FALSE(error_callback_.is_null()); | 121 ASSERT_FALSE(error_callback_.is_null()); |
| 122 error_callback_.Run(report_uri, net_error_); | 122 error_callback_.Run(report_uri, net_error_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SetErrorCallback( | 125 void SetErrorCallback( |
| 126 const base::Callback<void(const GURL&, int)>& error_callback) override { | 126 const base::Callback<void(const GURL&, int)>& error_callback) override { |
| 127 error_callback_ = error_callback; | 127 error_callback_ = error_callback; |
| 128 } | 128 } |
| 129 | 129 |
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 EXPECT_EQ(1u, reporter.num_failures()); | 1845 EXPECT_EQ(1u, reporter.num_failures()); |
| 1846 EXPECT_TRUE(reporter.ssl_info().ct_compliance_details_available); | 1846 EXPECT_TRUE(reporter.ssl_info().ct_compliance_details_available); |
| 1847 EXPECT_EQ(ssl_info.ct_cert_policy_compliance, | 1847 EXPECT_EQ(ssl_info.ct_cert_policy_compliance, |
| 1848 reporter.ssl_info().ct_cert_policy_compliance); | 1848 reporter.ssl_info().ct_cert_policy_compliance); |
| 1849 EXPECT_EQ(host_port.host(), reporter.host_port_pair().host()); | 1849 EXPECT_EQ(host_port.host(), reporter.host_port_pair().host()); |
| 1850 EXPECT_EQ(host_port.port(), reporter.host_port_pair().port()); | 1850 EXPECT_EQ(host_port.port(), reporter.host_port_pair().port()); |
| 1851 EXPECT_EQ(GURL(kExpectCTStaticReportURI), reporter.report_uri()); | 1851 EXPECT_EQ(GURL(kExpectCTStaticReportURI), reporter.report_uri()); |
| 1852 } | 1852 } |
| 1853 | 1853 |
| 1854 } // namespace net | 1854 } // namespace net |
| OLD | NEW |