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

Side by Side Diff: components/certificate_reporting/error_reporter_unittest.cc

Issue 2365353004: Add Content-Type header to net::ReportSender reports (Closed)
Patch Set: eroman comment 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
« no previous file with comments | « components/certificate_reporting/error_reporter.cc ('k') | net/http/transport_security_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/certificate_reporting/error_reporter.h" 5 #include "components/certificate_reporting/error_reporter.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 24 matching lines...) Expand all
35 const char kFailureHistogramName[] = "SSL.CertificateErrorReportFailure"; 35 const char kFailureHistogramName[] = "SSL.CertificateErrorReportFailure";
36 36
37 // A mock ReportSender that keeps track of the last report 37 // A mock ReportSender that keeps track of the last report
38 // sent. 38 // sent.
39 class MockCertificateReportSender : public net::ReportSender { 39 class MockCertificateReportSender : public net::ReportSender {
40 public: 40 public:
41 MockCertificateReportSender() 41 MockCertificateReportSender()
42 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {} 42 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
43 ~MockCertificateReportSender() override {} 43 ~MockCertificateReportSender() override {}
44 44
45 void Send(const GURL& report_uri, const std::string& report) override { 45 void Send(const GURL& report_uri,
46 base::StringPiece content_type,
47 base::StringPiece report) override {
46 latest_report_uri_ = report_uri; 48 latest_report_uri_ = report_uri;
47 latest_report_ = report; 49 report.CopyToString(&latest_report_);
50 content_type.CopyToString(&latest_content_type_);
48 } 51 }
49 52
50 const GURL& latest_report_uri() { return latest_report_uri_; } 53 const GURL& latest_report_uri() { return latest_report_uri_; }
51 54
52 const std::string& latest_report() { return latest_report_; } 55 const std::string& latest_report() { return latest_report_; }
53 56
57 const std::string& latest_content_type() { return latest_content_type_; }
58
54 private: 59 private:
55 GURL latest_report_uri_; 60 GURL latest_report_uri_;
56 std::string latest_report_; 61 std::string latest_report_;
62 std::string latest_content_type_;
57 63
58 DISALLOW_COPY_AND_ASSIGN(MockCertificateReportSender); 64 DISALLOW_COPY_AND_ASSIGN(MockCertificateReportSender);
59 }; 65 };
60 66
61 // A test network delegate that allows the user to specify a callback to 67 // A test network delegate that allows the user to specify a callback to
62 // be run whenever a net::URLRequest is destroyed. 68 // be run whenever a net::URLRequest is destroyed.
63 class TestCertificateReporterNetworkDelegate : public net::NetworkDelegateImpl { 69 class TestCertificateReporterNetworkDelegate : public net::NetworkDelegateImpl {
64 public: 70 public:
65 TestCertificateReporterNetworkDelegate() 71 TestCertificateReporterNetworkDelegate()
66 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)) {} 72 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)) {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Data should be encrypted when sent to an HTTP URL. 120 // Data should be encrypted when sent to an HTTP URL.
115 MockCertificateReportSender* http_mock_report_sender = 121 MockCertificateReportSender* http_mock_report_sender =
116 new MockCertificateReportSender(); 122 new MockCertificateReportSender();
117 GURL http_url(kDummyHttpReportUri); 123 GURL http_url(kDummyHttpReportUri);
118 ErrorReporter http_reporter(http_url, server_public_key_, 124 ErrorReporter http_reporter(http_url, server_public_key_,
119 kServerPublicKeyTestVersion, 125 kServerPublicKeyTestVersion,
120 base::WrapUnique(http_mock_report_sender)); 126 base::WrapUnique(http_mock_report_sender));
121 http_reporter.SendExtendedReportingReport(kDummyReport); 127 http_reporter.SendExtendedReportingReport(kDummyReport);
122 128
123 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url); 129 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url);
130 EXPECT_EQ("application/octet-stream",
131 http_mock_report_sender->latest_content_type());
124 132
125 std::string uploaded_report; 133 std::string uploaded_report;
126 EncryptedCertLoggerRequest encrypted_request; 134 EncryptedCertLoggerRequest encrypted_request;
127 ASSERT_TRUE(encrypted_request.ParseFromString( 135 ASSERT_TRUE(encrypted_request.ParseFromString(
128 http_mock_report_sender->latest_report())); 136 http_mock_report_sender->latest_report()));
129 EXPECT_EQ(kServerPublicKeyTestVersion, 137 EXPECT_EQ(kServerPublicKeyTestVersion,
130 encrypted_request.server_public_key_version()); 138 encrypted_request.server_public_key_version());
131 EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256, 139 EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256,
132 encrypted_request.algorithm()); 140 encrypted_request.algorithm());
133 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( 141 ASSERT_TRUE(ErrorReporter::DecryptErrorReport(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ASSERT_TRUE(encrypted_request.ParseFromString( 326 ASSERT_TRUE(encrypted_request.ParseFromString(
319 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), 327 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport),
320 sizeof(kSerializedEncryptedReport)))); 328 sizeof(kSerializedEncryptedReport))));
321 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( 329 ASSERT_TRUE(ErrorReporter::DecryptErrorReport(
322 server_private_key_, encrypted_request, &decrypted_serialized_report)); 330 server_private_key_, encrypted_request, &decrypted_serialized_report));
323 } 331 }
324 332
325 } // namespace 333 } // namespace
326 334
327 } // namespace certificate_reporting 335 } // namespace certificate_reporting
OLDNEW
« no previous file with comments | « components/certificate_reporting/error_reporter.cc ('k') | net/http/transport_security_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698