Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 // Test that ErrorReporter::SendExtendedReportingReport sends | 113 // Test that ErrorReporter::SendExtendedReportingReport sends |
| 114 // an encrypted or plaintext extended reporting report as appropriate. | 114 // an encrypted or plaintext extended reporting report as appropriate. |
| 115 TEST_F(ErrorReporterTest, ExtendedReportingSendReport) { | 115 TEST_F(ErrorReporterTest, ExtendedReportingSendReport) { |
| 116 // Data should not be encrypted when sent to an HTTPS URL. | 116 // Data should not be encrypted when sent to an HTTPS URL. |
| 117 MockCertificateReportSender* mock_report_sender = | 117 MockCertificateReportSender* mock_report_sender = |
| 118 new MockCertificateReportSender(); | 118 new MockCertificateReportSender(); |
| 119 GURL https_url(kDummyHttpsReportUri); | 119 GURL https_url(kDummyHttpsReportUri); |
| 120 ErrorReporter https_reporter(https_url, server_public_key_, | 120 ErrorReporter https_reporter(https_url, server_public_key_, |
| 121 kServerPublicKeyTestVersion, | 121 kServerPublicKeyTestVersion, |
| 122 base::WrapUnique(mock_report_sender)); | 122 base::WrapUnique(mock_report_sender)); |
| 123 https_reporter.SendExtendedReportingReport(kDummyReport); | 123 https_reporter.SendExtendedReportingReport(kDummyReport, 0); |
| 124 EXPECT_EQ(mock_report_sender->latest_report_uri(), https_url); | 124 EXPECT_EQ(mock_report_sender->latest_report_uri(), https_url); |
| 125 EXPECT_EQ(mock_report_sender->latest_report(), kDummyReport); | 125 EXPECT_EQ(mock_report_sender->latest_report(), kDummyReport); |
| 126 | 126 |
| 127 // Data should be encrypted when sent to an HTTP URL. | 127 // Data should be encrypted when sent to an HTTP URL. |
| 128 MockCertificateReportSender* http_mock_report_sender = | 128 MockCertificateReportSender* http_mock_report_sender = |
| 129 new MockCertificateReportSender(); | 129 new MockCertificateReportSender(); |
| 130 GURL http_url(kDummyHttpReportUri); | 130 GURL http_url(kDummyHttpReportUri); |
| 131 ErrorReporter http_reporter(http_url, server_public_key_, | 131 ErrorReporter http_reporter(http_url, server_public_key_, |
| 132 kServerPublicKeyTestVersion, | 132 kServerPublicKeyTestVersion, |
| 133 base::WrapUnique(http_mock_report_sender)); | 133 base::WrapUnique(http_mock_report_sender)); |
| 134 http_reporter.SendExtendedReportingReport(kDummyReport); | 134 http_reporter.SendExtendedReportingReport(kDummyReport, 0); |
| 135 | 135 |
| 136 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url); | 136 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url); |
| 137 EXPECT_EQ("application/octet-stream", | 137 EXPECT_EQ("application/octet-stream", |
| 138 http_mock_report_sender->latest_content_type()); | 138 http_mock_report_sender->latest_content_type()); |
| 139 EXPECT_EQ(0, http_mock_report_sender->latest_report_id()); | 139 EXPECT_EQ(0, http_mock_report_sender->latest_report_id()); |
| 140 | 140 |
| 141 std::string uploaded_report; | 141 std::string uploaded_report; |
| 142 EncryptedCertLoggerRequest encrypted_request; | 142 EncryptedCertLoggerRequest encrypted_request; |
| 143 ASSERT_TRUE(encrypted_request.ParseFromString( | 143 ASSERT_TRUE(encrypted_request.ParseFromString( |
| 144 http_mock_report_sender->latest_report())); | 144 http_mock_report_sender->latest_report())); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 163 net::TestURLRequestContext context(true); | 163 net::TestURLRequestContext context(true); |
| 164 TestCertificateReporterNetworkDelegate test_delegate; | 164 TestCertificateReporterNetworkDelegate test_delegate; |
| 165 test_delegate.set_url_request_destroyed_callback(run_loop.QuitClosure()); | 165 test_delegate.set_url_request_destroyed_callback(run_loop.QuitClosure()); |
| 166 context.set_network_delegate(&test_delegate); | 166 context.set_network_delegate(&test_delegate); |
| 167 context.Init(); | 167 context.Init(); |
| 168 | 168 |
| 169 GURL report_uri( | 169 GURL report_uri( |
| 170 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_FAILED)); | 170 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_FAILED)); |
| 171 ErrorReporter reporter(&context, report_uri, | 171 ErrorReporter reporter(&context, report_uri, |
| 172 net::ReportSender::DO_NOT_SEND_COOKIES); | 172 net::ReportSender::DO_NOT_SEND_COOKIES); |
| 173 reporter.SendExtendedReportingReport(kDummyReport); | 173 reporter.SendExtendedReportingReport(kDummyReport, 0); |
| 174 run_loop.Run(); | 174 run_loop.Run(); |
| 175 | 175 |
| 176 histograms.ExpectTotalCount(kFailureHistogramName, 1); | 176 histograms.ExpectTotalCount(kFailureHistogramName, 1); |
| 177 histograms.ExpectBucketCount(kFailureHistogramName, | 177 histograms.ExpectBucketCount(kFailureHistogramName, |
| 178 -net::ERR_CONNECTION_FAILED, 1); | 178 -net::ERR_CONNECTION_FAILED, 1); |
| 179 } | 179 } |
| 180 | 180 |
|
estark
2016/11/11 01:15:49
Could you add a test that the success/error callba
meacer
2016/11/11 19:59:29
Added. I moved the UMA test to ping_manager_unitte
| |
| 181 // This test decrypts a "known gold" report. It's intentionally brittle | 181 // This test decrypts a "known gold" report. It's intentionally brittle |
| 182 // in order to catch changes in report encryption that could cause the | 182 // in order to catch changes in report encryption that could cause the |
| 183 // server to no longer be able to decrypt reports that it receives from | 183 // server to no longer be able to decrypt reports that it receives from |
| 184 // Chrome. | 184 // Chrome. |
| 185 TEST_F(ErrorReporterTest, DecryptExampleReport) { | 185 TEST_F(ErrorReporterTest, DecryptExampleReport) { |
| 186 // This data should not be changed without also changing the | 186 // This data should not be changed without also changing the |
| 187 // corresponding server-side test. | 187 // corresponding server-side test. |
| 188 const unsigned char kSerializedEncryptedReport[] = { | 188 const unsigned char kSerializedEncryptedReport[] = { |
| 189 0x0A, 0xFB, 0x0C, 0xD5, 0x44, 0x21, 0x36, 0x4D, 0xFC, 0x29, 0x56, 0xBD, | 189 0x0A, 0xFB, 0x0C, 0xD5, 0x44, 0x21, 0x36, 0x4D, 0xFC, 0x29, 0x56, 0xBD, |
| 190 0x47, 0x18, 0xB1, 0x6F, 0x97, 0xF1, 0xF0, 0x3C, 0x31, 0x31, 0x1D, 0xD7, | 190 0x47, 0x18, 0xB1, 0x6F, 0x97, 0xF1, 0xF0, 0x3C, 0x31, 0x31, 0x1D, 0xD7, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 ASSERT_TRUE(encrypted_request.ParseFromString( | 334 ASSERT_TRUE(encrypted_request.ParseFromString( |
| 335 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), | 335 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), |
| 336 sizeof(kSerializedEncryptedReport)))); | 336 sizeof(kSerializedEncryptedReport)))); |
| 337 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( | 337 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( |
| 338 server_private_key_, encrypted_request, &decrypted_serialized_report)); | 338 server_private_key_, encrypted_request, &decrypted_serialized_report)); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace | 341 } // namespace |
| 342 | 342 |
| 343 } // namespace certificate_reporting | 343 } // namespace certificate_reporting |
| OLD | NEW |