Bug 808292 - CSP: Implement path-level host-source matching, parser tests (r=grobinson,sstamm)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Tue, 12 Aug 2014 13:07:34 -0700
changeset 230480 7fc03063d0c02a41265e7566459479414b25f7c4
parent 230479 b6cc542d38ffe8e2225c678739b8df9151d27935
child 230481 0b54f2bba06cb85b1cf57d8f3a5ad67ab5ff807e
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgrobinson, sstamm
bugs808292
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808292 - CSP: Implement path-level host-source matching, parser tests (r=grobinson,sstamm)
content/base/test/TestCSPParser.cpp
--- a/content/base/test/TestCSPParser.cpp
+++ b/content/base/test/TestCSPParser.cpp
@@ -282,62 +282,80 @@ nsresult TestIgnoreUpperLowerCasePolicie
 
 nsresult TestIgnorePaths() {
 
   static const PolicyTest policies[] =
   {
     { "script-src http://www.example.com",
       "script-src http://www.example.com" },
     { "script-src http://www.example.com/",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/" },
     { "script-src http://www.example.com/path-1",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1" },
     { "script-src http://www.example.com/path-1/",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/" },
     { "script-src http://www.example.com/path-1/path_2",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2" },
     { "script-src http://www.example.com/path-1/path_2/",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2/" },
     { "script-src http://www.example.com/path-1/path_2/file.js",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2/file.js" },
     { "script-src http://www.example.com/path-1/path_2/file_1.js",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2/file_1.js" },
     { "script-src http://www.example.com/path-1/path_2/file-2.js",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2/file-2.js" },
     { "script-src http://www.example.com/path-1/path_2/f.js",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1/path_2/f.js" },
     { "script-src http://www.example.com:88",
       "script-src http://www.example.com:88" },
     { "script-src http://www.example.com:88/",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/" },
     { "script-src http://www.example.com:88/path-1",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/path-1" },
     { "script-src http://www.example.com:88/path-1/",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/path-1/" },
     { "script-src http://www.example.com:88/path-1/path_2",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/path-1/path_2" },
     { "script-src http://www.example.com:88/path-1/path_2/",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/path-1/path_2/" },
     { "script-src http://www.example.com:88/path-1/path_2/file.js",
-      "script-src http://www.example.com:88" },
+      "script-src http://www.example.com:88/path-1/path_2/file.js" },
     { "script-src http://www.example.com:*",
       "script-src http://www.example.com:*" },
     { "script-src http://www.example.com:*/",
-      "script-src http://www.example.com:*" },
+      "script-src http://www.example.com:*/" },
     { "script-src http://www.example.com:*/path-1",
-      "script-src http://www.example.com:*" },
+      "script-src http://www.example.com:*/path-1" },
     { "script-src http://www.example.com:*/path-1/",
-      "script-src http://www.example.com:*" },
+      "script-src http://www.example.com:*/path-1/" },
     { "script-src http://www.example.com:*/path-1/path_2",
-      "script-src http://www.example.com:*" },
+      "script-src http://www.example.com:*/path-1/path_2" },
     { "script-src http://www.example.com:*/path-1/path_2/",
-      "script-src http://www.example.com:*" },
+      "script-src http://www.example.com:*/path-1/path_2/" },
     { "script-src http://www.example.com:*/path-1/path_2/file.js",
-      "script-src http://www.example.com:*" },
-    { "report-uri http://www.example.com",
+      "script-src http://www.example.com:*/path-1/path_2/file.js" },
+    { "script-src http://www.example.com#foo",
+      "script-src http://www.example.com" },
+    { "script-src http://www.example.com?foo=bar",
+      "script-src http://www.example.com" },
+    { "script-src http://www.example.com:8888#foo",
+      "script-src http://www.example.com:8888" },
+    { "script-src http://www.example.com:8888?foo",
+      "script-src http://www.example.com:8888" },
+    { "script-src http://www.example.com/#foo",
+      "script-src http://www.example.com/" },
+    { "script-src http://www.example.com/?foo",
+      "script-src http://www.example.com/" },
+    { "script-src http://www.example.com/path-1/file.js#foo",
+      "script-src http://www.example.com/path-1/file.js" },
+    { "script-src http://www.example.com/path-1/file.js?foo",
+      "script-src http://www.example.com/path-1/file.js" },
+    { "script-src http://www.example.com/path-1/file.js?foo#bar",
+      "script-src http://www.example.com/path-1/file.js" },
+    { "report-uri http://www.example.com/",
       "report-uri http://www.example.com/" },
     { "report-uri http://www.example.com:8888/asdf",
       "report-uri http://www.example.com:8888/asdf" },
     { "report-uri http://www.example.com:8888/path_1/path_2",
       "report-uri http://www.example.com:8888/path_1/path_2" },
     { "report-uri http://www.example.com:8888/path_1/path_2/report.sjs&301",
       "report-uri http://www.example.com:8888/path_1/path_2/report.sjs&301" },
     { "report-uri /examplepath",
@@ -396,19 +414,19 @@ nsresult TestSimplePolicies() {
       "default-src app://{app-host-is-uid}" },
     { "   ;   default-src abc",
       "default-src http://abc" },
     { " ; ; ; ;     default-src            abc    ; ; ; ;",
       "default-src http://abc" },
     { "script-src 'none' 'none' 'none';",
       "script-src 'none'" },
     { "script-src http://www.example.com/path-1//",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1//" },
     { "script-src http://www.example.com/path-1//path_2",
-      "script-src http://www.example.com" },
+      "script-src http://www.example.com/path-1//path_2" },
     { "default-src 127.0.0.1",
       "default-src http://127.0.0.1" },
     { "default-src 127.0.0.1:*",
       "default-src http://127.0.0.1:*" },
     { "default-src -; ",
       "default-src http://-" },
     { "script-src 1",
       "script-src http://1" }
@@ -614,31 +632,31 @@ nsresult TestGoodGeneratedPolicies() {
       "media-src https://self:34" },
     { "frame-src https://bar",
       "frame-src https://bar" },
     { "font-src http://three:81",
       "font-src http://three:81" },
     { "connect-src https://three:81",
       "connect-src https://three:81" },
     { "script-src http://self.com:80/foo",
-      "script-src http://self.com:80" },
+      "script-src http://self.com:80/foo" },
     { "object-src http://self.com/foo",
-      "object-src http://self.com" },
+      "object-src http://self.com/foo" },
     { "report-uri /report.py",
       "report-uri http://www.selfuri.com/report.py"},
     { "img-src http://foo.org:34/report.py",
-      "img-src http://foo.org:34" },
+      "img-src http://foo.org:34/report.py" },
     { "media-src foo/bar/report.py",
-      "media-src http://foo" },
+      "media-src http://foo/bar/report.py" },
     { "report-uri /",
       "report-uri http://www.selfuri.com/"},
     { "font-src https://self.com/report.py",
-      "font-src https://self.com" },
+      "font-src https://self.com/report.py" },
     { "connect-src https://foo.com/report.py",
-      "connect-src https://foo.com" },
+      "connect-src https://foo.com/report.py" },
     { "default-src *; report-uri  http://www.reporturi.com/",
       "default-src *; report-uri http://www.reporturi.com/" },
     { "default-src http://first.com",
       "default-src http://first.com" },
     { "script-src http://second.com",
       "script-src http://second.com" },
     { "object-src http://third.com",
       "object-src http://third.com" },
@@ -646,25 +664,25 @@ nsresult TestGoodGeneratedPolicies() {
       "style-src https://foobar.com:4443" },
     { "img-src http://foobar.com:4443",
       "img-src http://foobar.com:4443" },
     { "media-src bar.com",
       "media-src http://bar.com" },
     { "frame-src http://bar.com",
       "frame-src http://bar.com" },
     { "font-src http://self.com/",
-      "font-src http://self.com" },
+      "font-src http://self.com/" },
     { "script-src 'self'",
       "script-src http://www.selfuri.com" },
     { "default-src http://self.com/foo.png",
-      "default-src http://self.com" },
+      "default-src http://self.com/foo.png" },
     { "script-src http://self.com/foo.js",
-      "script-src http://self.com" },
+      "script-src http://self.com/foo.js" },
     { "object-src http://bar.com/foo.js",
-      "object-src http://bar.com" },
+      "object-src http://bar.com/foo.js" },
     { "style-src http://FOO.COM",
       "style-src http://foo.com" },
     { "img-src HTTP",
       "img-src http://http" },
     { "media-src http",
       "media-src http://http" },
     { "frame-src 'SELF'",
       "frame-src http://www.selfuri.com" },
@@ -692,21 +710,21 @@ nsresult TestGoodGeneratedPolicies() {
       "frame-ancestors http://a.b.c.d.e.f.g.h.i.j.k.l.x.com" },
     { "frame-ancestors https://self.com:34",
       "frame-ancestors https://self.com:34" },
     { "default-src 'none'; frame-ancestors 'self'",
       "default-src 'none'; frame-ancestors http://www.selfuri.com" },
     { "frame-ancestors http://self:80",
       "frame-ancestors http://self:80" },
     { "frame-ancestors http://self.com/bar",
-      "frame-ancestors http://self.com" },
+      "frame-ancestors http://self.com/bar" },
     { "default-src 'self'; frame-ancestors 'self'",
       "default-src http://www.selfuri.com; frame-ancestors http://www.selfuri.com" },
     { "frame-ancestors http://bar.com/foo.png",
-      "frame-ancestors http://bar.com" },
+      "frame-ancestors http://bar.com/foo.png" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
   return runTestSuite(policies, policyCount, 1);
 }
 
 // ============================= TestBadGeneratedPolicies ========================
 
@@ -742,121 +760,121 @@ nsresult TestGoodGeneratedPoliciesForPat
   // Once bug 808292 (Implement path-level host-source matching to CSP)
   // lands we have to update the expected output to include the parsed path
 
   static const PolicyTest policies[] =
   {
     { "img-src http://test1.example.com",
       "img-src http://test1.example.com" },
     { "img-src http://test1.example.com/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/" },
     { "img-src http://test1.example.com/path-1",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1" },
     { "img-src http://test1.example.com/path-1/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/" },
     { "img-src http://test1.example.com/path-1/path_2/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/" },
     { "img-src http://test1.example.com/path-1/path_2/file.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file.js" },
     { "img-src http://test1.example.com/path-1/path_2/file_1.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file_1.js" },
     { "img-src http://test1.example.com/path-1/path_2/file-2.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file-2.js" },
     { "img-src http://test1.example.com/path-1/path_2/f.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/f.js" },
     { "img-src http://test1.example.com/path-1/path_2/f.oo.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/f.oo.js" },
     { "img-src test1.example.com",
       "img-src http://test1.example.com" },
     { "img-src test1.example.com/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/" },
     { "img-src test1.example.com/path-1",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1" },
     { "img-src test1.example.com/path-1/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/" },
     { "img-src test1.example.com/path-1/path_2/",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/" },
     { "img-src test1.example.com/path-1/path_2/file.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file.js" },
     { "img-src test1.example.com/path-1/path_2/file_1.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file_1.js" },
     { "img-src test1.example.com/path-1/path_2/file-2.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/file-2.js" },
     { "img-src test1.example.com/path-1/path_2/f.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/f.js" },
     { "img-src test1.example.com/path-1/path_2/f.oo.js",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/path-1/path_2/f.oo.js" },
     { "img-src *.example.com",
       "img-src http://*.example.com" },
     { "img-src *.example.com/",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/" },
     { "img-src *.example.com/path-1",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1" },
     { "img-src *.example.com/path-1/",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/" },
     { "img-src *.example.com/path-1/path_2/",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/" },
     { "img-src *.example.com/path-1/path_2/file.js",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/file.js" },
     { "img-src *.example.com/path-1/path_2/file_1.js",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/file_1.js" },
     { "img-src *.example.com/path-1/path_2/file-2.js",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/file-2.js" },
     { "img-src *.example.com/path-1/path_2/f.js",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/f.js" },
     { "img-src *.example.com/path-1/path_2/f.oo.js",
-      "img-src http://*.example.com" },
+      "img-src http://*.example.com/path-1/path_2/f.oo.js" },
     { "img-src test1.example.com:80",
       "img-src http://test1.example.com:80" },
     { "img-src test1.example.com:80/",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/" },
     { "img-src test1.example.com:80/path-1",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1" },
     { "img-src test1.example.com:80/path-1/",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1/" },
     { "img-src test1.example.com:80/path-1/path_2",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1/path_2" },
     { "img-src test1.example.com:80/path-1/path_2/",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1/path_2/" },
     { "img-src test1.example.com:80/path-1/path_2/file.js",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1/path_2/file.js" },
     { "img-src test1.example.com:80/path-1/path_2/f.ile.js",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/path-1/path_2/f.ile.js" },
     { "img-src test1.example.com:*",
       "img-src http://test1.example.com:*" },
     { "img-src test1.example.com:*/",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/" },
     { "img-src test1.example.com:*/path-1",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1" },
     { "img-src test1.example.com:*/path-1/",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1/" },
     { "img-src test1.example.com:*/path-1/path_2",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1/path_2" },
     { "img-src test1.example.com:*/path-1/path_2/",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1/path_2/" },
     { "img-src test1.example.com:*/path-1/path_2/file.js",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1/path_2/file.js" },
     { "img-src test1.example.com:*/path-1/path_2/f.ile.js",
-      "img-src http://test1.example.com:*" },
+      "img-src http://test1.example.com:*/path-1/path_2/f.ile.js" },
     { "img-src http://test1.example.com/abc//",
-      "img-src http://test1.example.com" },
+      "img-src http://test1.example.com/abc//" },
     { "img-src https://test1.example.com/abc/def//",
-      "img-src https://test1.example.com" },
+      "img-src https://test1.example.com/abc/def//" },
     { "img-src https://test1.example.com/abc/def/ghi//",
-      "img-src https://test1.example.com" },
+      "img-src https://test1.example.com/abc/def/ghi//" },
     { "img-src http://test1.example.com:80/abc//",
-      "img-src http://test1.example.com:80" },
+      "img-src http://test1.example.com:80/abc//" },
     { "img-src https://test1.example.com:80/abc/def//",
-      "img-src https://test1.example.com:80" },
+      "img-src https://test1.example.com:80/abc/def//" },
     { "img-src https://test1.example.com:80/abc/def/ghi//",
-      "img-src https://test1.example.com:80" },
+      "img-src https://test1.example.com:80/abc/def/ghi//" },
     { "img-src https://test1.example.com/abc////////////def/",
-      "img-src https://test1.example.com" },
+      "img-src https://test1.example.com/abc////////////def/" },
     { "img-src https://test1.example.com/abc////////////",
-      "img-src https://test1.example.com" },
+      "img-src https://test1.example.com/abc////////////" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
   return runTestSuite(policies, policyCount, 1);
 }
 
 // ============ TestBadGeneratedPoliciesForPathHandling ============