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/feature_list.h" | |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/memory/ptr_util.h" | |
14 #include "base/metrics/field_trial.h" | |
12 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/test/mock_entropy_provider.h" | |
17 #include "base/test/scoped_feature_list.h" | |
13 #include "components/certificate_reporting/cert_logger.pb.h" | 18 #include "components/certificate_reporting/cert_logger.pb.h" |
19 #include "components/variations/variations_associated_data.h" | |
14 #include "net/cert/cert_status_flags.h" | 20 #include "net/cert/cert_status_flags.h" |
15 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
16 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
17 #include "net/test/test_data_directory.h" | 23 #include "net/test/test_data_directory.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; |
(...skipping 147 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 // Set up a test feature. | |
191 const std::string kTrialName = "Trial"; | |
192 const std::string kGroupName = "group"; | |
193 base::Feature kDummyFeature{"dummy_feature", | |
194 base::FEATURE_ENABLED_BY_DEFAULT}; | |
195 std::map<std::string, std::string> params; | |
196 params["foo"] = "bar"; | |
197 params["foo2"] = "bar2"; | |
198 | |
199 variations::testing::ClearAllVariationParams(); | |
200 std::unique_ptr<base::FieldTrialList> field_trial_list; | |
201 field_trial_list.reset(); | |
meacer
2016/10/26 20:20:31
Needed?
estark
2016/10/28 00:02:34
Done.
| |
202 field_trial_list.reset( | |
203 new base::FieldTrialList(base::MakeUnique<base::MockEntropyProvider>())); | |
204 | |
205 base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial( | |
206 kTrialName, 100, kGroupName, 1971, 1, 1, | |
207 base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */); | |
208 ASSERT_TRUE( | |
209 variations::AssociateVariationParams(kTrialName, kGroupName, params)); | |
210 | |
211 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
212 feature_list->RegisterFieldTrialOverride( | |
213 kDummyFeature.name, base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial); | |
214 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list( | |
215 new base::test::ScopedFeatureList()); | |
216 scoped_feature_list->InitWithFeatureList(std::move(feature_list)); | |
217 | |
218 // Serialize a report containing information about the test feature. | |
219 SSLInfo ssl_info; | |
220 ASSERT_NO_FATAL_FAILURE( | |
221 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); | |
222 ErrorReport report(kDummyHostname, ssl_info); | |
223 report.AddFeature(kDummyFeature); | |
224 std::string serialized_report; | |
225 ASSERT_TRUE(report.Serialize(&serialized_report)); | |
226 | |
227 // Check that the report contains the test feature information. | |
228 CertLoggerRequest parsed; | |
229 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); | |
230 ASSERT_EQ(1, parsed.features_info().size()); | |
231 EXPECT_EQ(kDummyFeature.name, parsed.features_info(0).feature()); | |
232 EXPECT_TRUE(parsed.features_info(0).enabled()); | |
233 std::map<std::string, std::string> parsed_params; | |
234 for (const auto& param : parsed.features_info(0).params()) { | |
235 parsed_params[param.name()] = param.value(); | |
236 } | |
237 EXPECT_EQ(params, parsed_params); | |
238 } | |
239 | |
181 } // namespace | 240 } // namespace |
182 | 241 |
183 } // namespace certificate_reporting | 242 } // namespace certificate_reporting |
OLD | NEW |