| 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/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/net/certificate_error_reporter.h" | 16 #include "chrome/browser/net/certificate_error_reporter.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 18 #include "net/base/test_data_directory.h" | 19 #include "net/base/test_data_directory.h" |
| 19 #include "net/cert/x509_certificate.h" | 20 #include "net/cert/x509_certificate.h" |
| 20 #include "net/http/transport_security_state.h" | 21 #include "net/http/transport_security_state.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void SendReport(ReportType type, | 124 void SendReport(ReportType type, |
| 124 const std::string& hostname, | 125 const std::string& hostname, |
| 125 const net::SSLInfo& ssl_info) override { | 126 const net::SSLInfo& ssl_info) override { |
| 126 EXPECT_EQ(type, REPORT_TYPE_PINNING_VIOLATION); | 127 EXPECT_EQ(type, REPORT_TYPE_PINNING_VIOLATION); |
| 127 EXPECT_FALSE(hostname.empty()); | 128 EXPECT_FALSE(hostname.empty()); |
| 128 EXPECT_TRUE(ssl_info.is_valid()); | 129 EXPECT_TRUE(ssl_info.is_valid()); |
| 129 CertificateErrorReporter::SendReport(type, hostname, ssl_info); | 130 CertificateErrorReporter::SendReport(type, hostname, ssl_info); |
| 130 } | 131 } |
| 131 | 132 |
| 132 private: | 133 private: |
| 134 ~MockReporter() override {} |
| 133 scoped_ptr<net::URLRequest> CreateURLRequest( | 135 scoped_ptr<net::URLRequest> CreateURLRequest( |
| 134 net::URLRequestContext* context) override { | 136 net::URLRequestContext* context) override { |
| 135 return context->CreateRequest(GURL(std::string()), | 137 return context->CreateRequest(GURL(std::string()), |
| 136 net::DEFAULT_PRIORITY, | 138 net::DEFAULT_PRIORITY, |
| 137 NULL, | 139 NULL, |
| 138 NULL); | 140 NULL); |
| 139 } | 141 } |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 static void DoReportIsSent() { | 144 static void DoReportIsSent() { |
| 143 net::TestURLRequestContext context; | 145 net::TestURLRequestContext context; |
| 144 SendingTestReporter reporter(&context); | 146 SendingTestReporter reporter(&context); |
| 145 SSLInfo info = GetGoodSSLInfo(); | 147 SSLInfo info = GetGoodSSLInfo(); |
| 146 reporter.SendReport("mail.google.com", info); | 148 reporter.SendReport("mail.google.com", info); |
| 147 } | 149 } |
| 148 | 150 |
| 149 static void DoReportIsNotSent() { | 151 static void DoReportIsNotSent() { |
| 150 net::TestURLRequestContext context; | 152 net::TestURLRequestContext context; |
| 151 NotSendingTestReporter reporter(&context); | 153 NotSendingTestReporter reporter(&context); |
| 152 SSLInfo info = GetBadSSLInfo(); | 154 SSLInfo info = GetBadSSLInfo(); |
| 153 reporter.SendReport("www.example.com", info); | 155 reporter.SendReport("www.example.com", info); |
| 154 } | 156 } |
| 155 | 157 |
| 156 static void DoMockReportIsSent() { | 158 static void DoMockReportIsSent() { |
| 157 net::TestURLRequestContext context; | 159 net::TestURLRequestContext context; |
| 158 scoped_ptr<MockReporter> error_reporter(new MockReporter(&context)); | 160 scoped_refptr<MockReporter> error_reporter = new MockReporter(&context); |
| 159 ChromeFraudulentCertificateReporter reporter(error_reporter.Pass()); | 161 ChromeFraudulentCertificateReporter reporter(error_reporter); |
| 160 SSLInfo info = GetGoodSSLInfo(); | 162 SSLInfo info = GetGoodSSLInfo(); |
| 161 reporter.SendReport("mail.google.com", info); | 163 reporter.SendReport("mail.google.com", info); |
| 162 } | 164 } |
| 163 | 165 |
| 164 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { | 166 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { |
| 165 SSLInfo good = GetGoodSSLInfo(); | 167 SSLInfo good = GetGoodSSLInfo(); |
| 166 EXPECT_TRUE(IsGoodSSLInfo(good)); | 168 EXPECT_TRUE(IsGoodSSLInfo(good)); |
| 167 | 169 |
| 168 SSLInfo bad = GetBadSSLInfo(); | 170 SSLInfo bad = GetBadSSLInfo(); |
| 169 EXPECT_FALSE(IsGoodSSLInfo(bad)); | 171 EXPECT_FALSE(IsGoodSSLInfo(bad)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 184 } | 186 } |
| 185 | 187 |
| 186 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 188 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
| 187 base::MessageLoopForIO loop; | 189 base::MessageLoopForIO loop; |
| 188 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 190 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
| 189 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 191 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
| 190 loop.RunUntilIdle(); | 192 loop.RunUntilIdle(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 } // namespace chrome_browser_net | 195 } // namespace chrome_browser_net |
| OLD | NEW |