test_proxy.js (3769B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 add_task(async function test_proxy_modes_and_autoconfig() { 6 // Directly test the proxy Mode and AutoconfigURL parameters through 7 // the API instead of the policy engine, because the test harness 8 // uses these prefs, and changing them interfere with the harness. 9 10 // Checks that every Mode value translates correctly to the expected pref value 11 let { ProxyPolicies, PROXY_TYPES_MAP } = ChromeUtils.importESModule( 12 "resource:///modules/policies/ProxyPolicies.sys.mjs" 13 ); 14 15 for (let [mode, expectedValue] of PROXY_TYPES_MAP) { 16 ProxyPolicies.configureProxySettings({ Mode: mode }, (_, value) => { 17 equal(value, expectedValue, "Correct proxy mode"); 18 }); 19 } 20 21 let autoconfigURL = new URL("data:text/plain,test"); 22 ProxyPolicies.configureProxySettings( 23 { AutoConfigURL: autoconfigURL }, 24 (_, value) => { 25 equal(value, autoconfigURL.href, "AutoconfigURL correctly set"); 26 } 27 ); 28 }); 29 30 add_task(async function test_proxy_boolean_settings() { 31 // Tests that both false and true values are correctly set and locked 32 await setupPolicyEngineWithJson({ 33 policies: { 34 Proxy: { 35 UseProxyForDNS: false, 36 AutoLogin: false, 37 }, 38 }, 39 }); 40 41 checkUnlockedPref("network.proxy.socks5_remote_dns", false); 42 checkUnlockedPref("signon.autologin.proxy", false); 43 44 await setupPolicyEngineWithJson({ 45 policies: { 46 Proxy: { 47 UseProxyForDNS: true, 48 AutoLogin: true, 49 }, 50 }, 51 }); 52 53 checkUnlockedPref("network.proxy.socks5_remote_dns", true); 54 checkUnlockedPref("signon.autologin.proxy", true); 55 }); 56 57 add_task(async function test_proxy_socks_and_passthrough() { 58 await setupPolicyEngineWithJson({ 59 policies: { 60 Proxy: { 61 SOCKSVersion: 4, 62 Passthrough: "a, b, c", 63 }, 64 }, 65 }); 66 67 checkUnlockedPref("network.proxy.socks_version", 4); 68 checkUnlockedPref("network.proxy.no_proxies_on", "a, b, c"); 69 }); 70 71 add_task(async function test_proxy_addresses() { 72 function checkProxyPref(proxytype, address, port) { 73 checkUnlockedPref(`network.proxy.${proxytype}`, address); 74 checkUnlockedPref(`network.proxy.${proxytype}_port`, port); 75 } 76 77 await setupPolicyEngineWithJson({ 78 policies: { 79 Proxy: { 80 HTTPProxy: "http.proxy.example.com:10", 81 SSLProxy: "ssl.proxy.example.com:30", 82 SOCKSProxy: "socks.proxy.example.com:40", 83 }, 84 }, 85 }); 86 87 checkProxyPref("http", "http.proxy.example.com", 10); 88 checkProxyPref("ssl", "ssl.proxy.example.com", 30); 89 checkProxyPref("socks", "socks.proxy.example.com", 40); 90 91 // Do the same, but now use the UseHTTPProxyForAllProtocols option 92 // and check that it takes effect. 93 await setupPolicyEngineWithJson({ 94 policies: { 95 Proxy: { 96 HTTPProxy: "http.proxy.example.com:10", 97 // FTP support was removed in bug 1574475 98 // Setting an FTPProxy should result in a warning but should not fail 99 FTPProxy: "ftp.proxy.example.com:20", 100 SSLProxy: "ssl.proxy.example.com:30", 101 SOCKSProxy: "socks.proxy.example.com:40", 102 UseHTTPProxyForAllProtocols: true, 103 }, 104 }, 105 }); 106 107 checkProxyPref("http", "http.proxy.example.com", 10); 108 checkProxyPref("ssl", "http.proxy.example.com", 10); 109 // SOCKS proxy should NOT be overwritten with UseHTTPProxyForAllProtocols 110 checkProxyPref("socks", "socks.proxy.example.com", 40); 111 112 // Make sure the FTPProxy setting did nothing 113 Assert.equal( 114 Preferences.has("network.proxy.ftp"), 115 false, 116 "network.proxy.ftp should not be set" 117 ); 118 Assert.equal( 119 Preferences.has("network.proxy.ftp_port"), 120 false, 121 "network.proxy.ftp_port should not be set" 122 ); 123 });