| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | |
| 16 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread.h" |
| 17 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 18 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
| 19 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 20 #include "net/http/transport_security_state.h" | 19 #include "net/http/transport_security_state.h" |
| 21 #include "net/ssl/ssl_info.h" | 20 #include "net/ssl/ssl_info.h" |
| 22 #include "net/test/cert_test_util.h" | 21 #include "net/test/cert_test_util.h" |
| 23 #include "net/url_request/fraudulent_certificate_reporter.h" | 22 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 24 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_test_util.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using net::SSLInfo; | 28 using net::SSLInfo; |
| 29 | 29 |
| 30 namespace chrome_browser_net { | 30 namespace chrome_browser_net { |
| 31 | 31 |
| 32 // Builds an SSLInfo from an invalid cert chain. In this case, the cert is | 32 // Builds an SSLInfo from an invalid cert chain. In this case, the cert is |
| 33 // expired; what matters is that the cert would not pass even a normal | 33 // expired; what matters is that the cert would not pass even a normal |
| 34 // sanity check. We test that we DO NOT send a fraudulent certificate report | 34 // sanity check. We test that we DO NOT send a fraudulent certificate report |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const net::SSLInfo& ssl_info, | 149 const net::SSLInfo& ssl_info, |
| 150 bool sni_available) OVERRIDE { | 150 bool sni_available) OVERRIDE { |
| 151 DCHECK(!hostname.empty()); | 151 DCHECK(!hostname.empty()); |
| 152 DCHECK(ssl_info.is_valid()); | 152 DCHECK(ssl_info.is_valid()); |
| 153 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, | 153 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, |
| 154 sni_available); | 154 sni_available); |
| 155 } | 155 } |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 static void DoReportIsSent() { | 158 static void DoReportIsSent() { |
| 159 ChromeURLRequestContext context; | 159 net::TestURLRequestContext context; |
| 160 SendingTestReporter reporter(&context); | 160 SendingTestReporter reporter(&context); |
| 161 SSLInfo info = GetGoodSSLInfo(); | 161 SSLInfo info = GetGoodSSLInfo(); |
| 162 reporter.SendReport("mail.google.com", info, true); | 162 reporter.SendReport("mail.google.com", info, true); |
| 163 } | 163 } |
| 164 | 164 |
| 165 static void DoReportIsNotSent() { | 165 static void DoReportIsNotSent() { |
| 166 ChromeURLRequestContext context; | 166 net::TestURLRequestContext context; |
| 167 NotSendingTestReporter reporter(&context); | 167 NotSendingTestReporter reporter(&context); |
| 168 SSLInfo info = GetBadSSLInfo(); | 168 SSLInfo info = GetBadSSLInfo(); |
| 169 reporter.SendReport("www.example.com", info, true); | 169 reporter.SendReport("www.example.com", info, true); |
| 170 } | 170 } |
| 171 | 171 |
| 172 static void DoMockReportIsSent() { | 172 static void DoMockReportIsSent() { |
| 173 ChromeURLRequestContext context; | 173 net::TestURLRequestContext context; |
| 174 MockReporter reporter(&context); | 174 MockReporter reporter(&context); |
| 175 SSLInfo info = GetGoodSSLInfo(); | 175 SSLInfo info = GetGoodSSLInfo(); |
| 176 reporter.SendReport("mail.google.com", info, true); | 176 reporter.SendReport("mail.google.com", info, true); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { | 179 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { |
| 180 SSLInfo good = GetGoodSSLInfo(); | 180 SSLInfo good = GetGoodSSLInfo(); |
| 181 EXPECT_TRUE(IsGoodSSLInfo(good)); | 181 EXPECT_TRUE(IsGoodSSLInfo(good)); |
| 182 | 182 |
| 183 SSLInfo bad = GetBadSSLInfo(); | 183 SSLInfo bad = GetBadSSLInfo(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 } | 199 } |
| 200 | 200 |
| 201 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 201 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
| 202 base::MessageLoopForIO loop; | 202 base::MessageLoopForIO loop; |
| 203 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 203 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
| 204 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 204 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
| 205 loop.RunUntilIdle(); | 205 loop.RunUntilIdle(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace chrome_browser_net | 208 } // namespace chrome_browser_net |
| OLD | NEW |