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" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, | 171 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, |
172 net::CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED)); | 172 net::CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED)); |
173 ErrorReport report_known(kDummyHostname, ssl_info); | 173 ErrorReport report_known(kDummyHostname, ssl_info); |
174 std::vector<CertLoggerRequest::CertError> cert_errors; | 174 std::vector<CertLoggerRequest::CertError> cert_errors; |
175 cert_errors.push_back( | 175 cert_errors.push_back( |
176 CertLoggerRequest::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); | 176 CertLoggerRequest::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); |
177 ASSERT_NO_FATAL_FAILURE( | 177 ASSERT_NO_FATAL_FAILURE( |
178 VerifyErrorReportSerialization(report_known, ssl_info, cert_errors)); | 178 VerifyErrorReportSerialization(report_known, ssl_info, cert_errors)); |
179 } | 179 } |
180 | 180 |
| 181 // Tests that information about relevant features are included in the |
| 182 // report. |
| 183 TEST(ErrorReportTest, FeatureInfo) { |
| 184 const std::string kFeatureName = "TestFeature"; |
| 185 std::map<std::string, std::string> params; |
| 186 params["foo"] = "bar"; |
| 187 params["foo2"] = "bar2"; |
| 188 |
| 189 // Serialize a report containing information about the test feature. |
| 190 SSLInfo ssl_info; |
| 191 ASSERT_NO_FATAL_FAILURE( |
| 192 GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus)); |
| 193 ErrorReport report(kDummyHostname, ssl_info); |
| 194 report.AddFeature(kFeatureName, true, params); |
| 195 std::string serialized_report; |
| 196 ASSERT_TRUE(report.Serialize(&serialized_report)); |
| 197 |
| 198 // Check that the report contains the test feature information. |
| 199 CertLoggerRequest parsed; |
| 200 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); |
| 201 ASSERT_EQ(1, parsed.features_info().size()); |
| 202 EXPECT_EQ(kFeatureName, parsed.features_info(0).feature()); |
| 203 EXPECT_TRUE(parsed.features_info(0).enabled()); |
| 204 std::map<std::string, std::string> parsed_params; |
| 205 for (const auto& param : parsed.features_info(0).params()) { |
| 206 parsed_params[param.name()] = param.value(); |
| 207 } |
| 208 EXPECT_EQ(params, parsed_params); |
| 209 } |
| 210 |
181 } // namespace | 211 } // namespace |
182 | 212 |
183 } // namespace certificate_reporting | 213 } // namespace certificate_reporting |
OLD | NEW |