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_report.h" | 5 #include "components/certificate_reporting/error_report.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "base/time/default_clock.h" |
| 15 #include "base/time/default_tick_clock.h" |
13 #include "components/certificate_reporting/cert_logger.pb.h" | 16 #include "components/certificate_reporting/cert_logger.pb.h" |
| 17 #include "components/network_time/network_time_test_utils.h" |
| 18 #include "components/prefs/testing_pref_service.h" |
14 #include "net/cert/cert_status_flags.h" | 19 #include "net/cert/cert_status_flags.h" |
15 #include "net/ssl/ssl_info.h" | 20 #include "net/ssl/ssl_info.h" |
16 #include "net/test/cert_test_util.h" | 21 #include "net/test/cert_test_util.h" |
17 #include "net/test/test_data_directory.h" | 22 #include "net/test/test_data_directory.h" |
| 23 #include "net/url_request/url_request_test_util.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
20 | 26 |
21 using net::SSLInfo; | 27 using net::SSLInfo; |
22 using testing::UnorderedElementsAre; | 28 using testing::UnorderedElementsAre; |
23 using testing::UnorderedElementsAreArray; | 29 using testing::UnorderedElementsAreArray; |
24 | 30 |
25 namespace certificate_reporting { | 31 namespace certificate_reporting { |
26 | 32 |
27 namespace { | 33 namespace { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, | 177 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, |
172 net::CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED)); | 178 net::CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED)); |
173 ErrorReport report_known(kDummyHostname, ssl_info); | 179 ErrorReport report_known(kDummyHostname, ssl_info); |
174 std::vector<CertLoggerRequest::CertError> cert_errors; | 180 std::vector<CertLoggerRequest::CertError> cert_errors; |
175 cert_errors.push_back( | 181 cert_errors.push_back( |
176 CertLoggerRequest::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); | 182 CertLoggerRequest::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); |
177 ASSERT_NO_FATAL_FAILURE( | 183 ASSERT_NO_FATAL_FAILURE( |
178 VerifyErrorReportSerialization(report_known, ssl_info, cert_errors)); | 184 VerifyErrorReportSerialization(report_known, ssl_info, cert_errors)); |
179 } | 185 } |
180 | 186 |
| 187 // Tests that information about relevant features are included in the |
| 188 // report. |
| 189 TEST(ErrorReportTest, FeatureInfo) { |
| 190 base::Thread io_thread("IO thread"); |
| 191 base::Thread::Options thread_options; |
| 192 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 193 EXPECT_TRUE(io_thread.StartWithOptions(thread_options)); |
| 194 |
| 195 std::unique_ptr<network_time::FieldTrialTest> field_trial_test( |
| 196 network_time::FieldTrialTest::CreateForUnitTest()); |
| 197 field_trial_test->SetNetworkQueriesWithVariationsService( |
| 198 true, 0.0, network_time::NetworkTimeTracker::FETCHES_ON_DEMAND_ONLY); |
| 199 |
| 200 TestingPrefServiceSimple pref_service; |
| 201 network_time::NetworkTimeTracker::RegisterPrefs(pref_service.registry()); |
| 202 network_time::NetworkTimeTracker network_time_tracker( |
| 203 base::MakeUnique<base::DefaultClock>(), |
| 204 base::MakeUnique<base::DefaultTickClock>(), &pref_service, |
| 205 new net::TestURLRequestContextGetter(io_thread.task_runner())); |
| 206 |
| 207 // Serialize a report containing information about the network time querying |
| 208 // feature. |
| 209 SSLInfo ssl_info; |
| 210 ASSERT_NO_FATAL_FAILURE( |
| 211 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); |
| 212 ErrorReport report(kDummyHostname, ssl_info); |
| 213 report.AddNetworkTimeInfo(&network_time_tracker); |
| 214 std::string serialized_report; |
| 215 ASSERT_TRUE(report.Serialize(&serialized_report)); |
| 216 |
| 217 // Check that the report contains the network time querying feature |
| 218 // information. |
| 219 CertLoggerRequest parsed; |
| 220 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); |
| 221 EXPECT_TRUE(parsed.features_info() |
| 222 .network_time_querying_info() |
| 223 .network_time_queries_enabled()); |
| 224 EXPECT_EQ(CertLoggerFeaturesInfo::NetworkTimeQueryingInfo:: |
| 225 NETWORK_TIME_FETCHES_ON_DEMAND_ONLY, |
| 226 parsed.features_info() |
| 227 .network_time_querying_info() |
| 228 .network_time_query_behavior()); |
| 229 } |
| 230 |
181 } // namespace | 231 } // namespace |
182 | 232 |
183 } // namespace certificate_reporting | 233 } // namespace certificate_reporting |
OLD | NEW |