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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp

Issue 2480303002: CSP3: Implement 'worker-src'. (Closed)
Patch Set: feedback Created 4 years, 1 month 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
Index: third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp b/third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp
index de8284a448854ce4752017c0c94d2a82dc07ae30..2fcde837e88b691ee4073c580e1ce9c8423735d5 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPDirectiveListTest.cpp
@@ -391,4 +391,48 @@ TEST_F(CSPDirectiveListTest, allowRequestWithoutIntegrity) {
}
}
+TEST_F(CSPDirectiveListTest, workerSrc) {
+ struct TestCase {
+ const char* list;
+ bool allowed;
+ } cases[] = {
+ {"worker-src 'none'", false},
+ {"worker-src http://not.example.test", false},
+ {"worker-src https://example.test", true},
+ {"default-src *; worker-src 'none'", false},
+ {"default-src *; worker-src http://not.example.test", false},
+ {"default-src *; worker-src https://example.test", true},
+ {"child-src *; worker-src 'none'", false},
+ {"child-src *; worker-src http://not.example.test", false},
+ {"child-src *; worker-src https://example.test", true},
+ {"default-src *; child-src *; worker-src 'none'", false},
+ {"default-src *; child-src *; worker-src http://not.example.test", false},
+ {"default-src *; child-src *; worker-src https://example.test", true},
+
+ // Fallback to child-src.
+ {"child-src 'none'", false},
+ {"child-src http://not.example.test", false},
+ {"child-src https://example.test", true},
+ {"default-src *; child-src 'none'", false},
+ {"default-src *; child-src http://not.example.test", false},
+ {"default-src *; child-src https://example.test", true},
+
+ // Fallback to default-src.
+ {"default-src 'none'", false},
+ {"default-src http://not.example.test", false},
+ {"default-src https://example.test", true},
+ };
+
+ for (const auto& test : cases) {
+ SCOPED_TRACE(test.list);
+ KURL resource = KURL(KURL(), "https://example.test/worker.js");
+ Member<CSPDirectiveList> directiveList =
+ createList(test.list, ContentSecurityPolicyHeaderTypeEnforce);
+ EXPECT_EQ(test.allowed,
+ directiveList->allowWorkerFromSource(
+ resource, ResourceRequest::RedirectStatus::NoRedirect,
+ ContentSecurityPolicy::SuppressReport));
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698