Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 7 | Cu.import("resource://services-sync/resource.js"); |
michael@0 | 8 | |
michael@0 | 9 | function run_test() { |
michael@0 | 10 | initTestLogging("Trace"); |
michael@0 | 11 | run_next_test(); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | let httpServer = new HttpServer(); |
michael@0 | 15 | httpServer.registerPathHandler("/content", contentHandler); |
michael@0 | 16 | httpServer.start(-1); |
michael@0 | 17 | |
michael@0 | 18 | const HTTP_PORT = httpServer.identity.primaryPort; |
michael@0 | 19 | const TEST_URL = "http://localhost:" + HTTP_PORT + "/content"; |
michael@0 | 20 | const BODY = "response body"; |
michael@0 | 21 | |
michael@0 | 22 | // Keep headers for later inspection. |
michael@0 | 23 | let auth = null; |
michael@0 | 24 | let foo = null; |
michael@0 | 25 | function contentHandler(metadata, response) { |
michael@0 | 26 | _("Handling request."); |
michael@0 | 27 | auth = metadata.getHeader("Authorization"); |
michael@0 | 28 | foo = metadata.getHeader("X-Foo"); |
michael@0 | 29 | |
michael@0 | 30 | _("Extracted headers. " + auth + ", " + foo); |
michael@0 | 31 | |
michael@0 | 32 | response.setHeader("Content-Type", "text/plain"); |
michael@0 | 33 | response.bodyOutputStream.write(BODY, BODY.length); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // Set a proxy function to cause an internal redirect. |
michael@0 | 37 | function triggerRedirect() { |
michael@0 | 38 | const PROXY_FUNCTION = "function FindProxyForURL(url, host) {" + |
michael@0 | 39 | " return 'PROXY a_non_existent_domain_x7x6c572v:80; " + |
michael@0 | 40 | "PROXY localhost:" + HTTP_PORT + "';" + |
michael@0 | 41 | "}"; |
michael@0 | 42 | |
michael@0 | 43 | let prefsService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); |
michael@0 | 44 | let prefs = prefsService.getBranch("network.proxy."); |
michael@0 | 45 | prefs.setIntPref("type", 2); |
michael@0 | 46 | prefs.setCharPref("autoconfig_url", "data:text/plain," + PROXY_FUNCTION); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | add_test(function test_headers_copied() { |
michael@0 | 50 | triggerRedirect(); |
michael@0 | 51 | |
michael@0 | 52 | _("Issuing request."); |
michael@0 | 53 | let resource = new Resource(TEST_URL); |
michael@0 | 54 | resource.setHeader("Authorization", "Basic foobar"); |
michael@0 | 55 | resource.setHeader("X-Foo", "foofoo"); |
michael@0 | 56 | |
michael@0 | 57 | let result = resource.get(TEST_URL); |
michael@0 | 58 | _("Result: " + result); |
michael@0 | 59 | |
michael@0 | 60 | do_check_eq(result, BODY); |
michael@0 | 61 | do_check_eq(auth, "Basic foobar"); |
michael@0 | 62 | do_check_eq(foo, "foofoo"); |
michael@0 | 63 | |
michael@0 | 64 | httpServer.stop(run_next_test); |
michael@0 | 65 | }); |