| Index: chrome/content/tests/policy.js |
| =================================================================== |
| --- a/chrome/content/tests/policy.js |
| +++ b/chrome/content/tests/policy.js |
| @@ -3,6 +3,7 @@ |
| let server = null; |
| let frame = null; |
| let requestNotifier = null; |
| + let httpProtocol = null; |
| module("Content policy", { |
| setup: function() |
| @@ -18,6 +19,9 @@ |
| document.body.appendChild(frame); |
| requestNotifier = new RequestNotifier(window, onPolicyHit); |
| + |
| + httpProtocol = Utils.httpProtocol; |
| + Utils.httpProtocol = {userAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"}; |
| }, |
| teardown: function() |
| { |
| @@ -36,9 +40,30 @@ |
| start(); |
| }); |
| + |
| + Utils.httpProtocol = httpProtocol; |
| } |
| }); |
| + /* |
| + -----BEGIN RSA PRIVATE KEY----- |
| + MIIBOgIBAAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD |
| + 2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQJBALo/ZSYTqsl4ve7vvTwG |
| + gKq7ZihIdV1wEcDwELGoBiESo87zl//7q2q9/7VE3dB3Qp6uZMLtxVvXzF8bh074 |
| + OuECIQDzzenwgPVMtg6OjMtZBAB95oKaTzd+x/8JienKW4edEQIhAN1Y+vlB/waB |
| + miRjGMrsOQDHhUbxyL6NXaPfxYlosYETAiBg0M9qgztl+BH1x7FkqvMrC+OnNXf7 |
| + L552gj7F7ez/kQIgOBNhyaHxlNlijpNYZZhAvLTPS/DXFYdE0M5RAgW26mcCIDrR |
| + fi2xaM2NqJQCmyshtNmDxW2FCrtrQn1n0211WCEe |
| + -----END RSA PRIVATE KEY----- |
| + */ |
| + let publickey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQ"; |
|
Wladimir Palant
2014/09/10 21:55:06
There are some RSA keys in https://hg.adblockplus.
Thomas Greiner
2014/12/11 14:33:55
Done.
|
| + |
| + /** |
| + * Content: |
| + * /test\0127.0.0.1:1234\0Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 |
| + */ |
| + let sitekey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQ==_peQ1CvuHieDHAXURwy9K8VQFaPWHHU0oDGT3pnIoQ6Nm7DUvCPw6FsnqfpdoIcq+kwqtkgWIcxM95gytuphvzQ=="; |
|
Wladimir Palant
2014/09/10 21:55:06
Call this variable "signature"?
Thomas Greiner
2014/12/11 14:33:55
Technically, it's a concatentation of public key a
|
| + |
| let tests = [ |
| [ |
| "HTML image with relative URL", |
| @@ -217,7 +242,7 @@ |
| { |
| // Ignore duplicate policy calls (possible due to prefetching) |
| let [prevWnd, prevNode, prevItem] = policyHits[policyHits.length - 1]; |
| - if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain) |
| + if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain) |
| policyHits.pop(); |
| } |
| policyHits.push([wnd, node, item]); |
| @@ -233,6 +258,8 @@ |
| defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document")); |
| if (stage == 4) |
| defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document")); |
| + if (stage == 5) |
| + defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,sitekey=" + publickey)); |
| let serverHit = false; |
| server.registerPathHandler("/test", function(metadata, response) |
| @@ -241,7 +268,12 @@ |
| let contentType = "text/html"; |
| if (body.indexOf("2000/svg") >= 0) |
| + { |
| contentType = "image/svg+xml"; |
| + body = body.replace(/^<svg/, "<svg data-adblockkey='" + sitekey + "'"); |
| + } |
| + else |
| + body = "<html data-adblockkey='" + sitekey + "'>" + body + "</html>"; |
| response.setHeader("Content-Type", contentType + "; charset=utf-8"); |
| response.bodyOutputStream.write(body, body.length); |
| @@ -273,7 +305,9 @@ |
| let expectedStatus = "allowed"; |
| if (stage == 3) |
| equal(policyHits.length, 0, "Number of policy hits"); |
| - else |
| + // We cannot rely on the correctness of policy hits for sitekey filters due to blocking |
| + // filter hits being counted even if the resource doesn't end up getting blocked |
| + else if (stage != 5) |
| { |
| equal(policyHits.length, 1, "Number of policy hits"); |
| if (policyHits.length == 1) |
| @@ -312,6 +346,7 @@ |
| 2: "running with filter %S", |
| 3: "running with filter %S and site exception", |
| 4: "running with filter %S and exception not applicable to sites", |
| + 5: "running with filter %S and sitekey exception" |
| }; |
| for (let test = 0; test < tests.length; test++) |