Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 2 | |
michael@0 | 3 | var httpserver = new HttpServer(); |
michael@0 | 4 | var currentTestIndex = 0; |
michael@0 | 5 | |
michael@0 | 6 | XPCOMUtils.defineLazyGetter(this, "port", function() { |
michael@0 | 7 | return httpserver.identity.primaryPort; |
michael@0 | 8 | }); |
michael@0 | 9 | |
michael@0 | 10 | XPCOMUtils.defineLazyGetter(this, "tests", function() { |
michael@0 | 11 | return [ |
michael@0 | 12 | // this is valid |
michael@0 | 13 | {url: "/assoc/assoctest?valid", |
michael@0 | 14 | responseheader: ["Assoc-Req: GET http://localhost:" + port + |
michael@0 | 15 | "/assoc/assoctest?valid", |
michael@0 | 16 | "Pragma: X-Verify-Assoc-Req"], |
michael@0 | 17 | flags: 0}, |
michael@0 | 18 | |
michael@0 | 19 | // this is invalid because the method is wrong |
michael@0 | 20 | {url: "/assoc/assoctest?invalid", |
michael@0 | 21 | responseheader: ["Assoc-Req: POST http://localhost:" + port + |
michael@0 | 22 | "/assoc/assoctest?invalid", |
michael@0 | 23 | "Pragma: X-Verify-Assoc-Req"], |
michael@0 | 24 | flags: CL_EXPECT_LATE_FAILURE}, |
michael@0 | 25 | |
michael@0 | 26 | // this is invalid because the url is wrong |
michael@0 | 27 | {url: "/assoc/assoctest?notvalid", |
michael@0 | 28 | responseheader: ["Assoc-Req: GET http://localhost:" + port + |
michael@0 | 29 | "/wrongpath/assoc/assoctest?notvalid", |
michael@0 | 30 | "Pragma: X-Verify-Assoc-Req"], |
michael@0 | 31 | flags: CL_EXPECT_LATE_FAILURE}, |
michael@0 | 32 | |
michael@0 | 33 | // this is invalid because the space between method and URL is missing |
michael@0 | 34 | {url: "/assoc/assoctest?invalid2", |
michael@0 | 35 | responseheader: ["Assoc-Req: GEThttp://localhost:" + port + |
michael@0 | 36 | "/assoc/assoctest?invalid2", |
michael@0 | 37 | "Pragma: X-Verify-Assoc-Req"], |
michael@0 | 38 | flags: CL_EXPECT_LATE_FAILURE}, |
michael@0 | 39 | ]; |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | var oldPrefVal; |
michael@0 | 43 | var domBranch; |
michael@0 | 44 | |
michael@0 | 45 | function setupChannel(url) |
michael@0 | 46 | { |
michael@0 | 47 | var ios = Components.classes["@mozilla.org/network/io-service;1"]. |
michael@0 | 48 | getService(Ci.nsIIOService); |
michael@0 | 49 | var chan = ios.newChannel("http://localhost:" + port + url, "", null); |
michael@0 | 50 | return chan; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function startIter() |
michael@0 | 54 | { |
michael@0 | 55 | var channel = setupChannel(tests[currentTestIndex].url); |
michael@0 | 56 | channel.asyncOpen(new ChannelListener(completeIter, |
michael@0 | 57 | channel, tests[currentTestIndex].flags), null); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function completeIter(request, data, ctx) |
michael@0 | 61 | { |
michael@0 | 62 | if (++currentTestIndex < tests.length ) { |
michael@0 | 63 | startIter(); |
michael@0 | 64 | } else { |
michael@0 | 65 | domBranch.setBoolPref("enforce", oldPrefVal); |
michael@0 | 66 | httpserver.stop(do_test_finished); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function run_test() |
michael@0 | 71 | { |
michael@0 | 72 | var prefService = |
michael@0 | 73 | Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 74 | .getService(Components.interfaces.nsIPrefService); |
michael@0 | 75 | domBranch = prefService.getBranch("network.http.assoc-req."); |
michael@0 | 76 | oldPrefVal = domBranch.getBoolPref("enforce"); |
michael@0 | 77 | domBranch.setBoolPref("enforce", true); |
michael@0 | 78 | |
michael@0 | 79 | httpserver.registerPathHandler("/assoc/assoctest", handler); |
michael@0 | 80 | httpserver.start(-1); |
michael@0 | 81 | |
michael@0 | 82 | startIter(); |
michael@0 | 83 | do_test_pending(); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function handler(metadata, response) |
michael@0 | 87 | { |
michael@0 | 88 | var body = "thequickbrownfox"; |
michael@0 | 89 | response.setHeader("Content-Type", "text/plain", false); |
michael@0 | 90 | |
michael@0 | 91 | var header = tests[currentTestIndex].responseheader; |
michael@0 | 92 | if (header != undefined) { |
michael@0 | 93 | for (var i = 0; i < header.length; i++) { |
michael@0 | 94 | var splitHdr = header[i].split(": "); |
michael@0 | 95 | response.setHeader(splitHdr[0], splitHdr[1], false); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | response.setStatusLine(metadata.httpVersion, 200, "OK"); |
michael@0 | 100 | response.bodyOutputStream.write(body, body.length); |
michael@0 | 101 | } |