Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc

Issue 452013002: Kill renderers that register Service Workers from non-secure origins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( 101 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
102 expected_message)); 102 expected_message));
103 dispatcher_host_->ipc_sink()->ClearMessages(); 103 dispatcher_host_->ipc_sink()->ClearMessages();
104 } 104 }
105 105
106 TestBrowserThreadBundle browser_thread_bundle_; 106 TestBrowserThreadBundle browser_thread_bundle_;
107 scoped_ptr<EmbeddedWorkerTestHelper> helper_; 107 scoped_ptr<EmbeddedWorkerTestHelper> helper_;
108 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; 108 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
109 }; 109 };
110 110
111 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { 111 TEST_F(ServiceWorkerDispatcherHostTest, Register) {
112 const int64 kProviderId = 99; // Dummy value 112 const int64 kProviderId = 99; // Dummy value
113 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 113 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
114 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); 114 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
115 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 115 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
116 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); 116 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
117 context()->AddProviderHost(host.Pass()); 117 context()->AddProviderHost(host.Pass());
118 118
119 Register(kProviderId, 119 Register(kProviderId,
120 GURL("https://www.example.com/"), 120 GURL("https://www.example.com/"),
121 GURL("https://www.example.com/bar"), 121 GURL("https://www.example.com/bar"),
122 ServiceWorkerMsg_ServiceWorkerRegistered::ID); 122 ServiceWorkerMsg_ServiceWorkerRegistered::ID);
123 } 123 }
124 124
125 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) { 125 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonHttpsSecureOrigin) {
126 const int64 kProviderId = 99; // Dummy value 126 const int64 kProviderId = 99; // Dummy value
127 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 127 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
128 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); 128 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
129 host->SetDocumentUrl(GURL("http://127.0.0.1/"));
130 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
131 context()->AddProviderHost(host.Pass());
132
133 Register(kProviderId,
134 GURL("http://127.0.0.1/"),
135 GURL("http://127.0.0.1/bar"),
136 ServiceWorkerMsg_ServiceWorkerRegistered::ID);
137 }
138
139 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginKillsRenderer) {
140 const int64 kProviderId = 99; // Dummy value
141 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
142 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
129 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 143 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
130 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); 144 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
131 context()->AddProviderHost(host.Pass()); 145 context()->AddProviderHost(host.Pass());
132 146
133 // Script has a different host 147 // Script has a different host
134 SendRegister(kProviderId, 148 SendRegister(kProviderId,
135 GURL("https://www.example.com/"), 149 GURL("https://www.example.com/"),
136 GURL("https://foo.example.com/bar")); 150 GURL("https://foo.example.com/bar"));
137 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 151 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
138 152
(...skipping 21 matching lines...) Expand all
160 GURL("https://foo.example.com/bar")); 174 GURL("https://foo.example.com/bar"));
161 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); 175 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_);
162 176
163 // Script and scope URLs are invalid 177 // Script and scope URLs are invalid
164 SendRegister(kProviderId, 178 SendRegister(kProviderId,
165 GURL(), 179 GURL(),
166 GURL("h@ttps://@")); 180 GURL("h@ttps://@"));
167 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); 181 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_);
168 } 182 }
169 183
170 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) { 184 TEST_F(ServiceWorkerDispatcherHostTest, Register_NotSecureOriginKillsRenderer) {
171 const int64 kProviderId = 99; // Dummy value 185 const int64 kProviderId = 99; // Dummy value
172 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 186 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
173 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); 187 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
174 host->SetDocumentUrl(GURL("http://www.example.com/foo")); 188 host->SetDocumentUrl(GURL("http://www.example.com/foo"));
175 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); 189 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
176 context()->AddProviderHost(host.Pass()); 190 context()->AddProviderHost(host.Pass());
177 191
192 SendRegister(kProviderId,
193 GURL("http://www.example.com/"),
194 GURL("http://www.example.com/bar"));
195 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
196 }
197
198 TEST_F(ServiceWorkerDispatcherHostTest, Unregister) {
199 const int64 kProviderId = 99; // Dummy value
200 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
201 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
202 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
203 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
204 context()->AddProviderHost(host.Pass());
205
178 Unregister(kProviderId, 206 Unregister(kProviderId,
179 GURL("http://www.example.com/"), 207 GURL("https://www.example.com/"),
180 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); 208 ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
181 } 209 }
182 210
183 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) { 211 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonHttpsSecureOrigin) {
184 const int64 kProviderId = 99; // Dummy value 212 const int64 kProviderId = 99; // Dummy value
185 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 213 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
186 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); 214 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
215 host->SetDocumentUrl(GURL("http://localhost:8123/foo"));
216 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
217 context()->AddProviderHost(host.Pass());
218
219 Unregister(kProviderId,
220 GURL("http://localhost:8123/"),
221 ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
222 }
223
224 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginKillsRenderer) {
225 const int64 kProviderId = 99; // Dummy value
226 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
227 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
228 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
229 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
230 context()->AddProviderHost(host.Pass());
231
232 SendUnregister(kProviderId, GURL("https://foo.example.com/"));
233 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
234 }
235
236 TEST_F(ServiceWorkerDispatcherHostTest,
237 Unregister_NotSecureOriginKillsRenderer) {
238 const int64 kProviderId = 99; // Dummy value
239 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
240 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
187 host->SetDocumentUrl(GURL("http://www.example.com/foo")); 241 host->SetDocumentUrl(GURL("http://www.example.com/foo"));
188 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); 242 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
189 context()->AddProviderHost(host.Pass()); 243 context()->AddProviderHost(host.Pass());
190 244
191 SendUnregister(kProviderId, GURL("http://foo.example.com/")); 245 SendUnregister(kProviderId, GURL("http://www.example.com/"));
192 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 246 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
193 } 247 }
194 248
195 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { 249 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) {
196 helper_->ShutdownContext(); 250 helper_->ShutdownContext();
197 251
198 // Let the shutdown reach the simulated IO thread. 252 // Let the shutdown reach the simulated IO thread.
199 base::RunLoop().RunUntilIdle(); 253 base::RunLoop().RunUntilIdle();
200 254
201 Register(-1, 255 Register(-1,
(...skipping 27 matching lines...) Expand all
229 // process to get deleted as well. 283 // process to get deleted as well.
230 dispatcher_host_->OnMessageReceived( 284 dispatcher_host_->OnMessageReceived(
231 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); 285 ServiceWorkerHostMsg_ProviderCreated(kProviderId));
232 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); 286 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId));
233 EXPECT_TRUE(dispatcher_host_->HasOneRef()); 287 EXPECT_TRUE(dispatcher_host_->HasOneRef());
234 dispatcher_host_ = NULL; 288 dispatcher_host_ = NULL;
235 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); 289 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId));
236 } 290 }
237 291
238 } // namespace content 292 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698