Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: net/http/transport_security_state_unittest.cc

Issue 2365353004: Add Content-Type header to net::ReportSender reports (Closed)
Patch Set: update some unit test subclasses Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 : public TransportSecurityState::ReportSenderInterface { 88 : public TransportSecurityState::ReportSenderInterface {
89 public: 89 public:
90 MockCertificateReportSender() {} 90 MockCertificateReportSender() {}
91 ~MockCertificateReportSender() override {} 91 ~MockCertificateReportSender() override {}
92 92
93 void Send(const GURL& report_uri, const std::string& report) override { 93 void Send(const GURL& report_uri, const std::string& report) override {
94 latest_report_uri_ = report_uri; 94 latest_report_uri_ = report_uri;
95 latest_report_ = report; 95 latest_report_ = report;
96 } 96 }
97 97
98 void SetContentTypeHeader(const std::string& content_type) override {
99 latest_content_type_ = content_type;
100 }
101
98 void SetErrorCallback( 102 void SetErrorCallback(
99 const base::Callback<void(const GURL&, int)>& error_callback) override {} 103 const base::Callback<void(const GURL&, int)>& error_callback) override {}
100 104
101 void Clear() { 105 void Clear() {
102 latest_report_uri_ = GURL(); 106 latest_report_uri_ = GURL();
103 latest_report_ = std::string(); 107 latest_report_ = std::string();
104 } 108 }
105 109
106 const GURL& latest_report_uri() { return latest_report_uri_; } 110 const GURL& latest_report_uri() { return latest_report_uri_; }
107 const std::string& latest_report() { return latest_report_; } 111 const std::string& latest_report() { return latest_report_; }
112 const std::string& latest_content_type() { return latest_content_type_; }
108 113
109 private: 114 private:
110 GURL latest_report_uri_; 115 GURL latest_report_uri_;
111 std::string latest_report_; 116 std::string latest_report_;
117 std::string latest_content_type_;
112 }; 118 };
113 119
114 // A mock ReportSenderInterface that simulates a net error on every report sent. 120 // A mock ReportSenderInterface that simulates a net error on every report sent.
115 class MockFailingCertificateReportSender 121 class MockFailingCertificateReportSender
116 : public TransportSecurityState::ReportSenderInterface { 122 : public TransportSecurityState::ReportSenderInterface {
117 public: 123 public:
118 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} 124 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {}
119 ~MockFailingCertificateReportSender() override {} 125 ~MockFailingCertificateReportSender() override {}
120 126
121 int net_error() { return net_error_; } 127 int net_error() { return net_error_; }
122 128
123 // TransportSecurityState::ReportSenderInterface: 129 // TransportSecurityState::ReportSenderInterface:
124 void Send(const GURL& report_uri, const std::string& report) override { 130 void Send(const GURL& report_uri, const std::string& report) override {
125 ASSERT_FALSE(error_callback_.is_null()); 131 ASSERT_FALSE(error_callback_.is_null());
126 error_callback_.Run(report_uri, net_error_); 132 error_callback_.Run(report_uri, net_error_);
127 } 133 }
128 134
135 void SetContentTypeHeader(const std::string& content_type) override {}
136
129 void SetErrorCallback( 137 void SetErrorCallback(
130 const base::Callback<void(const GURL&, int)>& error_callback) override { 138 const base::Callback<void(const GURL&, int)>& error_callback) override {
131 error_callback_ = error_callback; 139 error_callback_ = error_callback;
132 } 140 }
133 141
134 private: 142 private:
135 const int net_error_; 143 const int net_error_;
136 base::Callback<void(const GURL&, int)> error_callback_; 144 base::Callback<void(const GURL&, int)> error_callback_;
137 }; 145 };
138 146
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 334 }
327 335
328 // Set up |state| for ExpectStaple, call CheckExpectStaple(), and verify the 336 // Set up |state| for ExpectStaple, call CheckExpectStaple(), and verify the
329 // serialized report caught by |reporter|. 337 // serialized report caught by |reporter|.
330 void CheckExpectStapleReport(TransportSecurityState* state, 338 void CheckExpectStapleReport(TransportSecurityState* state,
331 MockCertificateReportSender* reporter, 339 MockCertificateReportSender* reporter,
332 const SSLInfo& ssl_info, 340 const SSLInfo& ssl_info,
333 const std::string& ocsp_response, 341 const std::string& ocsp_response,
334 const std::string& response_status, 342 const std::string& response_status,
335 const std::string& cert_status) { 343 const std::string& cert_status) {
344 EXPECT_EQ("application/json", reporter->latest_content_type());
336 // Expect-Staple is preload list based, so we use the baked-in test hostname 345 // Expect-Staple is preload list based, so we use the baked-in test hostname
337 // from the list ("preloaded-expect-staple.badssl.com"). 346 // from the list ("preloaded-expect-staple.badssl.com").
338 HostPortPair host_port(kExpectStapleStaticHostname, 443); 347 HostPortPair host_port(kExpectStapleStaticHostname, 443);
339 state->SetReportSender(reporter); 348 state->SetReportSender(reporter);
340 state->CheckExpectStaple(host_port, ssl_info, ocsp_response); 349 state->CheckExpectStaple(host_port, ssl_info, ocsp_response);
341 EXPECT_EQ(GURL(kExpectStapleStaticReportURI), reporter->latest_report_uri()); 350 EXPECT_EQ(GURL(kExpectStapleStaticReportURI), reporter->latest_report_uri());
342 std::string serialized_report = reporter->latest_report(); 351 std::string serialized_report = reporter->latest_report();
343 EXPECT_NO_FATAL_FAILURE(CheckSerializedExpectStapleReport( 352 EXPECT_NO_FATAL_FAILURE(CheckSerializedExpectStapleReport(
344 serialized_report, host_port, ssl_info, ocsp_response, response_status, 353 serialized_report, host_port, ssl_info, ocsp_response, response_status,
345 cert_status)); 354 cert_status));
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 EXPECT_EQ(std::string(), mock_report_sender.latest_report()); 1444 EXPECT_EQ(std::string(), mock_report_sender.latest_report());
1436 1445
1437 EXPECT_EQ(TransportSecurityState::PKPStatus::VIOLATED, 1446 EXPECT_EQ(TransportSecurityState::PKPStatus::VIOLATED,
1438 state.CheckPublicKeyPins( 1447 state.CheckPublicKeyPins(
1439 host_port_pair, true, bad_hashes, cert1.get(), cert2.get(), 1448 host_port_pair, true, bad_hashes, cert1.get(), cert2.get(),
1440 TransportSecurityState::ENABLE_PIN_REPORTS, &failure_log)); 1449 TransportSecurityState::ENABLE_PIN_REPORTS, &failure_log));
1441 1450
1442 // Now a report should have been sent. Check that it contains the 1451 // Now a report should have been sent. Check that it contains the
1443 // right information. 1452 // right information.
1444 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 1453 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
1454 EXPECT_EQ("application/json", mock_report_sender.latest_content_type());
1445 std::string report = mock_report_sender.latest_report(); 1455 std::string report = mock_report_sender.latest_report();
1446 ASSERT_FALSE(report.empty()); 1456 ASSERT_FALSE(report.empty());
1447 ASSERT_NO_FATAL_FAILURE(CheckHPKPReport(report, host_port_pair, true, kHost, 1457 ASSERT_NO_FATAL_FAILURE(CheckHPKPReport(report, host_port_pair, true, kHost,
1448 cert1.get(), cert2.get(), 1458 cert1.get(), cert2.get(),
1449 good_hashes)); 1459 good_hashes));
1450 mock_report_sender.Clear(); 1460 mock_report_sender.Clear();
1451 EXPECT_EQ(TransportSecurityState::PKPStatus::VIOLATED, 1461 EXPECT_EQ(TransportSecurityState::PKPStatus::VIOLATED,
1452 state.CheckPublicKeyPins(subdomain_host_port_pair, true, bad_hashes, 1462 state.CheckPublicKeyPins(subdomain_host_port_pair, true, bad_hashes,
1453 cert1.get(), cert2.get(), 1463 cert1.get(), cert2.get(),
1454 TransportSecurityState::ENABLE_PIN_REPORTS, 1464 TransportSecurityState::ENABLE_PIN_REPORTS,
1455 &failure_log)); 1465 &failure_log));
1456 1466
1457 // Now a report should have been sent for the subdomain. Check that it 1467 // Now a report should have been sent for the subdomain. Check that it
1458 // contains the right information. 1468 // contains the right information.
1459 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 1469 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
1470 EXPECT_EQ("application/json", mock_report_sender.latest_content_type());
1460 report = mock_report_sender.latest_report(); 1471 report = mock_report_sender.latest_report();
1461 ASSERT_FALSE(report.empty()); 1472 ASSERT_FALSE(report.empty());
1462 ASSERT_NO_FATAL_FAILURE(CheckHPKPReport(report, subdomain_host_port_pair, 1473 ASSERT_NO_FATAL_FAILURE(CheckHPKPReport(report, subdomain_host_port_pair,
1463 true, kHost, cert1.get(), cert2.get(), 1474 true, kHost, cert1.get(), cert2.get(),
1464 good_hashes)); 1475 good_hashes));
1465 } 1476 }
1466 1477
1467 // Tests that a histogram entry is recorded when TransportSecurityState 1478 // Tests that a histogram entry is recorded when TransportSecurityState
1468 // fails to send an HPKP violation report. 1479 // fails to send an HPKP violation report.
1469 TEST_F(TransportSecurityStateTest, UMAOnHPKPReportingFailure) { 1480 TEST_F(TransportSecurityStateTest, UMAOnHPKPReportingFailure) {
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", 2332 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots",
2322 "disabled"); 2333 "disabled");
2323 2334
2324 EXPECT_FALSE( 2335 EXPECT_FALSE(
2325 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); 2336 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes));
2326 EXPECT_FALSE( 2337 EXPECT_FALSE(
2327 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); 2338 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes));
2328 } 2339 }
2329 2340
2330 } // namespace net 2341 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698