| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class SendingTestReporter : public TestReporter { | 78 class SendingTestReporter : public TestReporter { |
| 79 public: | 79 public: |
| 80 explicit SendingTestReporter(net::URLRequestContext* request_context) | 80 explicit SendingTestReporter(net::URLRequestContext* request_context) |
| 81 : TestReporter(request_context), passed_(false) {} | 81 : TestReporter(request_context), passed_(false) {} |
| 82 | 82 |
| 83 // Passes if invoked with a good SSLInfo and for a hostname that is a Google | 83 // Passes if invoked with a good SSLInfo and for a hostname that is a Google |
| 84 // pinned property. | 84 // pinned property. |
| 85 virtual void SendReport(const std::string& hostname, | 85 virtual void SendReport(const std::string& hostname, |
| 86 const SSLInfo& ssl_info) OVERRIDE { | 86 const SSLInfo& ssl_info) override { |
| 87 EXPECT_TRUE(IsGoodSSLInfo(ssl_info)); | 87 EXPECT_TRUE(IsGoodSSLInfo(ssl_info)); |
| 88 EXPECT_TRUE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); | 88 EXPECT_TRUE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); |
| 89 passed_ = true; | 89 passed_ = true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual ~SendingTestReporter() { | 92 virtual ~SendingTestReporter() { |
| 93 // If the object is destroyed without having its SendReport method invoked, | 93 // If the object is destroyed without having its SendReport method invoked, |
| 94 // we failed. | 94 // we failed. |
| 95 EXPECT_TRUE(passed_); | 95 EXPECT_TRUE(passed_); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool passed_; | 98 bool passed_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 class NotSendingTestReporter : public TestReporter { | 101 class NotSendingTestReporter : public TestReporter { |
| 102 public: | 102 public: |
| 103 explicit NotSendingTestReporter(net::URLRequestContext* request_context) | 103 explicit NotSendingTestReporter(net::URLRequestContext* request_context) |
| 104 : TestReporter(request_context) {} | 104 : TestReporter(request_context) {} |
| 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 virtual void SendReport(const std::string& hostname, | 108 virtual 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 ChromeFraudulentCertificateReporter 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 ChromeFraudulentCertificateReporter { |
| 118 public: | 118 public: |
| 119 explicit MockReporter(net::URLRequestContext* request_context) | 119 explicit MockReporter(net::URLRequestContext* request_context) |
| 120 : ChromeFraudulentCertificateReporter(request_context) {} | 120 : ChromeFraudulentCertificateReporter(request_context) {} |
| 121 | 121 |
| 122 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 122 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
| 123 net::URLRequestContext* context) OVERRIDE { | 123 net::URLRequestContext* context) override { |
| 124 return context->CreateRequest(GURL(std::string()), | 124 return context->CreateRequest(GURL(std::string()), |
| 125 net::DEFAULT_PRIORITY, | 125 net::DEFAULT_PRIORITY, |
| 126 NULL, | 126 NULL, |
| 127 NULL); | 127 NULL); |
| 128 } | 128 } |
| 129 | 129 |
| 130 virtual void SendReport( | 130 virtual void SendReport( |
| 131 const std::string& hostname, | 131 const std::string& hostname, |
| 132 const net::SSLInfo& ssl_info) OVERRIDE { | 132 const net::SSLInfo& ssl_info) override { |
| 133 DCHECK(!hostname.empty()); | 133 DCHECK(!hostname.empty()); |
| 134 DCHECK(ssl_info.is_valid()); | 134 DCHECK(ssl_info.is_valid()); |
| 135 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info); | 135 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info); |
| 136 } | 136 } |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 static void DoReportIsSent() { | 139 static void DoReportIsSent() { |
| 140 net::TestURLRequestContext context; | 140 net::TestURLRequestContext context; |
| 141 SendingTestReporter reporter(&context); | 141 SendingTestReporter reporter(&context); |
| 142 SSLInfo info = GetGoodSSLInfo(); | 142 SSLInfo info = GetGoodSSLInfo(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 182 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
| 183 base::MessageLoopForIO loop; | 183 base::MessageLoopForIO loop; |
| 184 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 184 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
| 185 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 185 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
| 186 loop.RunUntilIdle(); | 186 loop.RunUntilIdle(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace chrome_browser_net | 189 } // namespace chrome_browser_net |
| OLD | NEW |