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, | 86 const SSLInfo& ssl_info) OVERRIDE { |
87 bool sni_available) OVERRIDE { | |
88 EXPECT_TRUE(IsGoodSSLInfo(ssl_info)); | 87 EXPECT_TRUE(IsGoodSSLInfo(ssl_info)); |
89 EXPECT_TRUE(net::TransportSecurityState::IsGooglePinnedProperty( | 88 EXPECT_TRUE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); |
90 hostname, sni_available)); | |
91 passed_ = true; | 89 passed_ = true; |
92 } | 90 } |
93 | 91 |
94 virtual ~SendingTestReporter() { | 92 virtual ~SendingTestReporter() { |
95 // If the object is destroyed without having its SendReport method invoked, | 93 // If the object is destroyed without having its SendReport method invoked, |
96 // we failed. | 94 // we failed. |
97 EXPECT_TRUE(passed_); | 95 EXPECT_TRUE(passed_); |
98 } | 96 } |
99 | 97 |
100 bool passed_; | 98 bool passed_; |
101 }; | 99 }; |
102 | 100 |
103 class NotSendingTestReporter : public TestReporter { | 101 class NotSendingTestReporter : public TestReporter { |
104 public: | 102 public: |
105 explicit NotSendingTestReporter(net::URLRequestContext* request_context) | 103 explicit NotSendingTestReporter(net::URLRequestContext* request_context) |
106 : TestReporter(request_context) {} | 104 : TestReporter(request_context) {} |
107 | 105 |
108 // 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 |
109 // Google pinned property. | 107 // Google pinned property. |
110 virtual void SendReport(const std::string& hostname, | 108 virtual void SendReport(const std::string& hostname, |
111 const SSLInfo& ssl_info, | 109 const SSLInfo& ssl_info) OVERRIDE { |
112 bool sni_available) OVERRIDE { | |
113 EXPECT_FALSE(IsGoodSSLInfo(ssl_info)); | 110 EXPECT_FALSE(IsGoodSSLInfo(ssl_info)); |
114 EXPECT_FALSE(net::TransportSecurityState::IsGooglePinnedProperty( | 111 EXPECT_FALSE(net::TransportSecurityState::IsGooglePinnedProperty(hostname)); |
115 hostname, sni_available)); | |
116 } | 112 } |
117 }; | 113 }; |
118 | 114 |
119 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 115 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is |
120 // otherwise normal: reports are constructed and sent in the usual way. | 116 // otherwise normal: reports are constructed and sent in the usual way. |
121 class MockReporter : public ChromeFraudulentCertificateReporter { | 117 class MockReporter : public ChromeFraudulentCertificateReporter { |
122 public: | 118 public: |
123 explicit MockReporter(net::URLRequestContext* request_context) | 119 explicit MockReporter(net::URLRequestContext* request_context) |
124 : ChromeFraudulentCertificateReporter(request_context) {} | 120 : ChromeFraudulentCertificateReporter(request_context) {} |
125 | 121 |
126 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 122 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
127 net::URLRequestContext* context) OVERRIDE { | 123 net::URLRequestContext* context) OVERRIDE { |
128 return context->CreateRequest(GURL(std::string()), | 124 return context->CreateRequest(GURL(std::string()), |
129 net::DEFAULT_PRIORITY, | 125 net::DEFAULT_PRIORITY, |
130 NULL, | 126 NULL, |
131 NULL); | 127 NULL); |
132 } | 128 } |
133 | 129 |
134 virtual void SendReport( | 130 virtual void SendReport( |
135 const std::string& hostname, | 131 const std::string& hostname, |
136 const net::SSLInfo& ssl_info, | 132 const net::SSLInfo& ssl_info) OVERRIDE { |
137 bool sni_available) OVERRIDE { | |
138 DCHECK(!hostname.empty()); | 133 DCHECK(!hostname.empty()); |
139 DCHECK(ssl_info.is_valid()); | 134 DCHECK(ssl_info.is_valid()); |
140 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, | 135 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info); |
141 sni_available); | |
142 } | 136 } |
143 }; | 137 }; |
144 | 138 |
145 static void DoReportIsSent() { | 139 static void DoReportIsSent() { |
146 net::TestURLRequestContext context; | 140 net::TestURLRequestContext context; |
147 SendingTestReporter reporter(&context); | 141 SendingTestReporter reporter(&context); |
148 SSLInfo info = GetGoodSSLInfo(); | 142 SSLInfo info = GetGoodSSLInfo(); |
149 reporter.SendReport("mail.google.com", info, true); | 143 reporter.SendReport("mail.google.com", info); |
150 } | 144 } |
151 | 145 |
152 static void DoReportIsNotSent() { | 146 static void DoReportIsNotSent() { |
153 net::TestURLRequestContext context; | 147 net::TestURLRequestContext context; |
154 NotSendingTestReporter reporter(&context); | 148 NotSendingTestReporter reporter(&context); |
155 SSLInfo info = GetBadSSLInfo(); | 149 SSLInfo info = GetBadSSLInfo(); |
156 reporter.SendReport("www.example.com", info, true); | 150 reporter.SendReport("www.example.com", info); |
157 } | 151 } |
158 | 152 |
159 static void DoMockReportIsSent() { | 153 static void DoMockReportIsSent() { |
160 net::TestURLRequestContext context; | 154 net::TestURLRequestContext context; |
161 MockReporter reporter(&context); | 155 MockReporter reporter(&context); |
162 SSLInfo info = GetGoodSSLInfo(); | 156 SSLInfo info = GetGoodSSLInfo(); |
163 reporter.SendReport("mail.google.com", info, true); | 157 reporter.SendReport("mail.google.com", info); |
164 } | 158 } |
165 | 159 |
166 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { | 160 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { |
167 SSLInfo good = GetGoodSSLInfo(); | 161 SSLInfo good = GetGoodSSLInfo(); |
168 EXPECT_TRUE(IsGoodSSLInfo(good)); | 162 EXPECT_TRUE(IsGoodSSLInfo(good)); |
169 | 163 |
170 SSLInfo bad = GetBadSSLInfo(); | 164 SSLInfo bad = GetBadSSLInfo(); |
171 EXPECT_FALSE(IsGoodSSLInfo(bad)); | 165 EXPECT_FALSE(IsGoodSSLInfo(bad)); |
172 } | 166 } |
173 | 167 |
(...skipping 12 matching lines...) Expand all Loading... |
186 } | 180 } |
187 | 181 |
188 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 182 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
189 base::MessageLoopForIO loop; | 183 base::MessageLoopForIO loop; |
190 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 184 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
191 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 185 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
192 loop.RunUntilIdle(); | 186 loop.RunUntilIdle(); |
193 } | 187 } |
194 | 188 |
195 } // namespace chrome_browser_net | 189 } // namespace chrome_browser_net |
OLD | NEW |