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

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc

Issue 618113005: Kill renderers that dink with Service Workers from non-secure origins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
index bdb95ea0aa912fccae56532601dccfefef04690e..da187d58b51c26b3d4c20cf97f8644a0eee3c85d 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
@@ -124,7 +124,7 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
};
-TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) {
+TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
@@ -138,7 +138,35 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) {
ServiceWorkerMsg_ServiceWorkerRegistered::ID);
}
-TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) {
+TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureTransportLocalhost) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo"));
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
+ context()->AddProviderHost(host.Pass());
+
+ Register(kProviderId,
+ GURL("http://127.0.0.3:81/bar"),
+ GURL("http://127.0.0.3:81/baz"),
+ ServiceWorkerMsg_ServiceWorkerRegistered::ID);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("http://www.example.com/foo"));
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
+ context()->AddProviderHost(host.Pass());
+
+ SendRegister(kProviderId,
+ GURL("http://www.example.com/"),
+ GURL("http://www.example.com/bar"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
@@ -170,7 +198,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) {
GURL("https://www.example.com/bar"));
EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_);
- // Script and scope have different hosts
+ // Script and scope have a different host but match each other
SendRegister(kProviderId,
GURL("https://foo.example.com/"),
GURL("https://foo.example.com/bar"));
@@ -183,20 +211,46 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) {
EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_);
}
-TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) {
+TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
- host->SetDocumentUrl(GURL("http://www.example.com/foo"));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
context()->AddProviderHost(host.Pass());
Unregister(kProviderId,
- GURL("http://www.example.com/"),
+ GURL("https://www.example.com/"),
ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
}
-TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) {
+TEST_F(ServiceWorkerDispatcherHostTest,
+ Unregister_NonSecureTransportLocalhost) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("http://localhost/foo"));
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
+ context()->AddProviderHost(host.Pass());
+
+ Unregister(kProviderId,
+ GURL("http://localhost/"),
+ ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
+ context()->AddProviderHost(host.Pass());
+
+ SendUnregister(kProviderId, GURL("https://foo.example.com/"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
@@ -204,7 +258,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) {
base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
context()->AddProviderHost(host.Pass());
- SendUnregister(kProviderId, GURL("http://foo.example.com/"));
+ SendUnregister(kProviderId, GURL("http://www.example.com/"));
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
}
@@ -264,7 +318,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) {
ServiceWorkerMsg_DidGetRegistration::ID);
}
-TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOrigin) {
+TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
@@ -276,6 +330,19 @@ TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOrigin) {
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
}
+TEST_F(ServiceWorkerDispatcherHostTest,
+ GetRegistration_NotSecureOriginShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("http://www.example.com/foo"));
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
+ context()->AddProviderHost(host.Pass());
+
+ SendGetRegistration(kProviderId, GURL("http://www.example.com/"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) {
helper_->ShutdownContext();
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698