OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net/chrome_fraudulent_certificate_reporter.h" | 5 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 105 |
106 // Passes if invoked with a bad SSLInfo and for a hostname that is not a | 106 // Passes if invoked with a bad SSLInfo and for a hostname that is not a |
107 // Google pinned property. | 107 // Google pinned property. |
108 void SendReport(const std::string& hostname, | 108 void SendReport(const std::string& hostname, |
109 const SSLInfo& ssl_info) override { | 109 const SSLInfo& ssl_info) override { |
110 EXPECT_FALSE(IsGoodSSLInfo(ssl_info)); | 110 EXPECT_FALSE(IsGoodSSLInfo(ssl_info)); |
111 EXPECT_FALSE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); | 111 EXPECT_FALSE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); |
112 } | 112 } |
113 }; | 113 }; |
114 | 114 |
115 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 115 // A CertificateErrorReporter that uses a MockURLRequest, but is |
116 // otherwise normal: reports are constructed and sent in the usual way. | 116 // otherwise normal: reports are constructed and sent in the usual way. |
117 class MockReporter : public ChromeFraudulentCertificateReporter { | 117 class MockReporter : public CertificateErrorReporter { |
118 public: | 118 public: |
119 explicit MockReporter(net::URLRequestContext* request_context) | 119 explicit MockReporter(net::URLRequestContext* request_context) |
120 : ChromeFraudulentCertificateReporter(request_context) {} | 120 : CertificateErrorReporter(request_context, GURL("http://example.com")) {} |
121 | 121 |
122 void SendReport(ReportType type, | |
123 const std::string& hostname, | |
124 const net::SSLInfo& ssl_info) override { | |
125 EXPECT_EQ(type, REPORT_TYPE_PINNING_VIOLATION); | |
126 EXPECT_FALSE(hostname.empty()); | |
127 EXPECT_TRUE(ssl_info.is_valid()); | |
128 CertificateErrorReporter::SendReport(type, hostname, ssl_info); | |
Ryan Sleevi
2015/03/06 19:23:14
You don't actually need to forward this on, do you
estark
2015/03/06 19:52:06
To be honest I don't really understand what any of
| |
129 } | |
130 | |
131 private: | |
122 scoped_ptr<net::URLRequest> CreateURLRequest( | 132 scoped_ptr<net::URLRequest> CreateURLRequest( |
123 net::URLRequestContext* context) override { | 133 net::URLRequestContext* context) override { |
124 return context->CreateRequest(GURL(std::string()), | 134 return context->CreateRequest(GURL(std::string()), |
125 net::DEFAULT_PRIORITY, | 135 net::DEFAULT_PRIORITY, |
126 NULL, | 136 NULL, |
127 NULL); | 137 NULL); |
128 } | 138 } |
129 | |
130 void SendReport(const std::string& hostname, | |
131 const net::SSLInfo& ssl_info) override { | |
132 DCHECK(!hostname.empty()); | |
133 DCHECK(ssl_info.is_valid()); | |
134 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info); | |
135 } | |
136 }; | 139 }; |
137 | 140 |
138 static void DoReportIsSent() { | 141 static void DoReportIsSent() { |
139 net::TestURLRequestContext context; | 142 net::TestURLRequestContext context; |
140 SendingTestReporter reporter(&context); | 143 SendingTestReporter reporter(&context); |
141 SSLInfo info = GetGoodSSLInfo(); | 144 SSLInfo info = GetGoodSSLInfo(); |
142 reporter.SendReport("mail.google.com", info); | 145 reporter.SendReport("mail.google.com", info); |
143 } | 146 } |
144 | 147 |
145 static void DoReportIsNotSent() { | 148 static void DoReportIsNotSent() { |
146 net::TestURLRequestContext context; | 149 net::TestURLRequestContext context; |
147 NotSendingTestReporter reporter(&context); | 150 NotSendingTestReporter reporter(&context); |
148 SSLInfo info = GetBadSSLInfo(); | 151 SSLInfo info = GetBadSSLInfo(); |
149 reporter.SendReport("www.example.com", info); | 152 reporter.SendReport("www.example.com", info); |
150 } | 153 } |
151 | 154 |
152 static void DoMockReportIsSent() { | 155 static void DoMockReportIsSent() { |
153 net::TestURLRequestContext context; | 156 net::TestURLRequestContext context; |
154 MockReporter reporter(&context); | 157 scoped_ptr<MockReporter> error_reporter(new MockReporter(&context)); |
158 ChromeFraudulentCertificateReporter reporter(error_reporter.Pass()); | |
155 SSLInfo info = GetGoodSSLInfo(); | 159 SSLInfo info = GetGoodSSLInfo(); |
156 reporter.SendReport("mail.google.com", info); | 160 reporter.SendReport("mail.google.com", info); |
157 } | 161 } |
158 | 162 |
159 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { | 163 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { |
160 SSLInfo good = GetGoodSSLInfo(); | 164 SSLInfo good = GetGoodSSLInfo(); |
161 EXPECT_TRUE(IsGoodSSLInfo(good)); | 165 EXPECT_TRUE(IsGoodSSLInfo(good)); |
162 | 166 |
163 SSLInfo bad = GetBadSSLInfo(); | 167 SSLInfo bad = GetBadSSLInfo(); |
164 EXPECT_FALSE(IsGoodSSLInfo(bad)); | 168 EXPECT_FALSE(IsGoodSSLInfo(bad)); |
(...skipping 14 matching lines...) Expand all Loading... | |
179 } | 183 } |
180 | 184 |
181 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 185 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
182 base::MessageLoopForIO loop; | 186 base::MessageLoopForIO loop; |
183 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 187 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
184 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 188 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
185 loop.RunUntilIdle(); | 189 loop.RunUntilIdle(); |
186 } | 190 } |
187 | 191 |
188 } // namespace chrome_browser_net | 192 } // namespace chrome_browser_net |
OLD | NEW |