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 14 matching lines...) Expand all Loading... |
25 #include "net/base/host_port_pair.h" | 25 #include "net/base/host_port_pair.h" |
26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
27 #include "net/base/test_completion_callback.h" | 27 #include "net/base/test_completion_callback.h" |
28 #include "net/cert/asn1_util.h" | 28 #include "net/cert/asn1_util.h" |
29 #include "net/cert/cert_verifier.h" | 29 #include "net/cert/cert_verifier.h" |
30 #include "net/cert/cert_verify_result.h" | 30 #include "net/cert/cert_verify_result.h" |
31 #include "net/cert/ct_policy_status.h" | 31 #include "net/cert/ct_policy_status.h" |
32 #include "net/cert/test_root_certs.h" | 32 #include "net/cert/test_root_certs.h" |
33 #include "net/cert/x509_cert_types.h" | 33 #include "net/cert/x509_cert_types.h" |
34 #include "net/cert/x509_certificate.h" | 34 #include "net/cert/x509_certificate.h" |
| 35 #include "net/http/http_status_code.h" |
35 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
36 #include "net/ssl/ssl_info.h" | 37 #include "net/ssl/ssl_info.h" |
37 #include "net/test/cert_test_util.h" | 38 #include "net/test/cert_test_util.h" |
38 #include "net/test/test_data_directory.h" | 39 #include "net/test/test_data_directory.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
41 | 42 |
42 namespace net { | 43 namespace net { |
43 | 44 |
44 namespace { | 45 namespace { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 }; | 94 }; |
94 | 95 |
95 // A mock ReportSenderInterface that just remembers the latest report | 96 // A mock ReportSenderInterface that just remembers the latest report |
96 // URI and report to be sent. | 97 // URI and report to be sent. |
97 class MockCertificateReportSender | 98 class MockCertificateReportSender |
98 : public TransportSecurityState::ReportSenderInterface { | 99 : public TransportSecurityState::ReportSenderInterface { |
99 public: | 100 public: |
100 MockCertificateReportSender() {} | 101 MockCertificateReportSender() {} |
101 ~MockCertificateReportSender() override {} | 102 ~MockCertificateReportSender() override {} |
102 | 103 |
103 void Send( | 104 void Send(const GURL& report_uri, |
104 const GURL& report_uri, | 105 base::StringPiece content_type, |
105 base::StringPiece content_type, | 106 base::StringPiece report, |
106 base::StringPiece report, | 107 const base::Callback<void()>& success_callback, |
107 const base::Callback<void()>& success_callback, | 108 const base::Callback<void(const GURL&, int, int)>& error_callback) |
108 const base::Callback<void(const GURL&, int)>& error_callback) override { | 109 override { |
109 latest_report_uri_ = report_uri; | 110 latest_report_uri_ = report_uri; |
110 report.CopyToString(&latest_report_); | 111 report.CopyToString(&latest_report_); |
111 content_type.CopyToString(&latest_content_type_); | 112 content_type.CopyToString(&latest_content_type_); |
112 } | 113 } |
113 | 114 |
114 void Clear() { | 115 void Clear() { |
115 latest_report_uri_ = GURL(); | 116 latest_report_uri_ = GURL(); |
116 latest_report_ = std::string(); | 117 latest_report_ = std::string(); |
117 latest_content_type_ = std::string(); | 118 latest_content_type_ = std::string(); |
118 } | 119 } |
(...skipping 11 matching lines...) Expand all Loading... |
130 // A mock ReportSenderInterface that simulates a net error on every report sent. | 131 // A mock ReportSenderInterface that simulates a net error on every report sent. |
131 class MockFailingCertificateReportSender | 132 class MockFailingCertificateReportSender |
132 : public TransportSecurityState::ReportSenderInterface { | 133 : public TransportSecurityState::ReportSenderInterface { |
133 public: | 134 public: |
134 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} | 135 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} |
135 ~MockFailingCertificateReportSender() override {} | 136 ~MockFailingCertificateReportSender() override {} |
136 | 137 |
137 int net_error() { return net_error_; } | 138 int net_error() { return net_error_; } |
138 | 139 |
139 // TransportSecurityState::ReportSenderInterface: | 140 // TransportSecurityState::ReportSenderInterface: |
140 void Send( | 141 void Send(const GURL& report_uri, |
141 const GURL& report_uri, | 142 base::StringPiece content_type, |
142 base::StringPiece content_type, | 143 base::StringPiece report, |
143 base::StringPiece report, | 144 const base::Callback<void()>& success_callback, |
144 const base::Callback<void()>& success_callback, | 145 const base::Callback<void(const GURL&, int, int)>& error_callback) |
145 const base::Callback<void(const GURL&, int)>& error_callback) override { | 146 override { |
146 ASSERT_FALSE(error_callback.is_null()); | 147 ASSERT_FALSE(error_callback.is_null()); |
147 error_callback.Run(report_uri, net_error_); | 148 error_callback.Run(report_uri, net_error_, 0); |
148 } | 149 } |
149 | 150 |
150 private: | 151 private: |
151 const int net_error_; | 152 const int net_error_; |
152 }; | 153 }; |
153 | 154 |
154 // A mock ExpectCTReporter that remembers the latest violation that was | 155 // A mock ExpectCTReporter that remembers the latest violation that was |
155 // reported and the number of violations reported. | 156 // reported and the number of violations reported. |
156 class MockExpectCTReporter : public TransportSecurityState::ExpectCTReporter { | 157 class MockExpectCTReporter : public TransportSecurityState::ExpectCTReporter { |
157 public: | 158 public: |
(...skipping 2528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2686 TransportSecurityState state; | 2687 TransportSecurityState state; |
2687 TransportSecurityState::ExpectCTState expect_ct_state; | 2688 TransportSecurityState::ExpectCTState expect_ct_state; |
2688 const base::Time current_time = base::Time::Now(); | 2689 const base::Time current_time = base::Time::Now(); |
2689 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 2690 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
2690 | 2691 |
2691 state.AddExpectCT(host, expiry, true, GURL()); | 2692 state.AddExpectCT(host, expiry, true, GURL()); |
2692 EXPECT_FALSE(state.GetDynamicExpectCTState(host, &expect_ct_state)); | 2693 EXPECT_FALSE(state.GetDynamicExpectCTState(host, &expect_ct_state)); |
2693 } | 2694 } |
2694 | 2695 |
2695 } // namespace net | 2696 } // namespace net |
OLD | NEW |