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 "chrome/browser/ssl/certificate_error_report.h" | 5 #include "chrome/browser/ssl/certificate_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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 std::set<CertLoggerRequest::CertError> reported_errors; | 73 std::set<CertLoggerRequest::CertError> reported_errors; |
74 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( | 74 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( |
75 deserialized_report.cert_error().Get(0))); | 75 deserialized_report.cert_error().Get(0))); |
76 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( | 76 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( |
77 deserialized_report.cert_error().Get(1))); | 77 deserialized_report.cert_error().Get(1))); |
78 EXPECT_EQ(kNumCertErrors, reported_errors.size()); | 78 EXPECT_EQ(kNumCertErrors, reported_errors.size()); |
79 EXPECT_EQ(1u, reported_errors.count(kFirstReportedCertError)); | 79 EXPECT_EQ(1u, reported_errors.count(kFirstReportedCertError)); |
80 EXPECT_EQ(1u, reported_errors.count(kSecondReportedCertError)); | 80 EXPECT_EQ(1u, reported_errors.count(kSecondReportedCertError)); |
81 } | 81 } |
82 | 82 |
| 83 TEST(CertificateErrorReportTest, |
| 84 SerializedReportAsProtobufWithInterstitialInfo) { |
| 85 SSLInfo ssl_info = GetTestSSLInfo(); |
| 86 |
| 87 std::string serialized_report; |
| 88 CertificateErrorReport report(kDummyHostname, ssl_info); |
| 89 |
| 90 const CertificateErrorReport::InterstitialReason interstitial_reason = |
| 91 CertificateErrorReport::INTERSTITIAL_CLOCK; |
| 92 const CertificateErrorReport::ProceedDecision proceeded = |
| 93 CertificateErrorReport::USER_PROCEEDED; |
| 94 const CertificateErrorReport::Overridable overridable = |
| 95 CertificateErrorReport::INTERSTITIAL_OVERRIDABLE; |
| 96 |
| 97 report.SetInterstitialInfo(interstitial_reason, proceeded, overridable); |
| 98 |
| 99 report.Serialize(&serialized_report); |
| 100 |
| 101 CertLoggerRequest deserialized_report; |
| 102 ASSERT_TRUE(deserialized_report.ParseFromString(serialized_report)); |
| 103 EXPECT_EQ(kDummyHostname, deserialized_report.hostname()); |
| 104 EXPECT_EQ(GetPEMEncodedChain(), deserialized_report.cert_chain()); |
| 105 EXPECT_EQ(1, deserialized_report.pin().size()); |
| 106 EXPECT_EQ(kDummyFailureLog, deserialized_report.pin().Get(0)); |
| 107 |
| 108 EXPECT_EQ(CertLoggerInterstitialInfo::INTERSTITIAL_CLOCK, |
| 109 deserialized_report.interstitial_info().interstitial_reason()); |
| 110 EXPECT_EQ(true, deserialized_report.interstitial_info().user_proceeded()); |
| 111 EXPECT_EQ(true, deserialized_report.interstitial_info().overridable()); |
| 112 |
| 113 std::set<CertLoggerRequest::CertError> reported_errors; |
| 114 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( |
| 115 deserialized_report.cert_error().Get(0))); |
| 116 reported_errors.insert(static_cast<CertLoggerRequest::CertError>( |
| 117 deserialized_report.cert_error().Get(1))); |
| 118 EXPECT_EQ(kNumCertErrors, reported_errors.size()); |
| 119 EXPECT_EQ(1u, reported_errors.count(kFirstReportedCertError)); |
| 120 EXPECT_EQ(1u, reported_errors.count(kSecondReportedCertError)); |
| 121 } |
| 122 |
83 // Test that a serialized report can be parsed. | 123 // Test that a serialized report can be parsed. |
84 TEST(CertificateErrorReportTest, ParseSerializedReport) { | 124 TEST(CertificateErrorReportTest, ParseSerializedReport) { |
85 SSLInfo ssl_info = GetTestSSLInfo(); | 125 SSLInfo ssl_info = GetTestSSLInfo(); |
86 | 126 |
87 std::string serialized_report; | 127 std::string serialized_report; |
88 CertificateErrorReport report(kDummyHostname, ssl_info); | 128 CertificateErrorReport report(kDummyHostname, ssl_info); |
89 EXPECT_EQ(kDummyHostname, report.hostname()); | 129 EXPECT_EQ(kDummyHostname, report.hostname()); |
90 report.Serialize(&serialized_report); | 130 report.Serialize(&serialized_report); |
91 | 131 |
92 CertificateErrorReport parsed; | 132 CertificateErrorReport parsed; |
93 ASSERT_TRUE(parsed.InitializeFromString(serialized_report)); | 133 ASSERT_TRUE(parsed.InitializeFromString(serialized_report)); |
94 EXPECT_EQ(report.hostname(), parsed.hostname()); | 134 EXPECT_EQ(report.hostname(), parsed.hostname()); |
95 } | 135 } |
96 | 136 |
97 } // namespace | 137 } // namespace |
OLD | NEW |