From d9284623076d23e1506ba8cf287123d7d907c75d Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Fri, 17 Jul 2020 12:28:48 +0000 Subject: [PATCH] Bug 1649813 test dns api failure when forwarding dns to socks proxy r=mayhemer,necko-reviewers Differential Revision: https://phabricator.services.mozilla.com/D83006 --- netwerk/dns/nsDNSService2.cpp | 5 +- .../extensions/test/xpcshell/test_ext_dns.js | 59 ++++++++++++++++++- .../test/xpcshell/xpcshell-common.ini | 1 + 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/netwerk/dns/nsDNSService2.cpp b/netwerk/dns/nsDNSService2.cpp index a9e6ee2e5079..44867dc7510a 100644 --- a/netwerk/dns/nsDNSService2.cpp +++ b/netwerk/dns/nsDNSService2.cpp @@ -684,9 +684,8 @@ nsresult nsDNSService::ReadPrefs(const char* name) { } } if (!name || !strcmp(name, kPrefNetworkProxySOCKS)) { - if (NS_SUCCEEDED(Preferences::GetUint(kPrefNetworkProxySOCKS, &tmpint))) { - nsAutoCString socks; - Preferences::GetCString(kPrefNetworkProxySOCKS, socks); + nsAutoCString socks; + if (NS_SUCCEEDED(Preferences::GetCString(kPrefNetworkProxySOCKS, socks))) { mHasSocksProxy = !socks.IsEmpty(); } } diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_dns.js b/toolkit/components/extensions/test/xpcshell/test_ext_dns.js index 4daf2dc535d0..d7f9d6efe98c 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_dns.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_dns.js @@ -4,14 +4,29 @@ // off to get consistent test results. Services.prefs.setBoolPref("network.dns.disableIPv6", true); +AddonTestUtils.init(this); +AddonTestUtils.overrideCertDB(); + +AddonTestUtils.createAppInfo( + "xpcshell@tests.mozilla.org", + "XPCShell", + "1", + "42" +); + function getExtension(background = undefined) { let manifest = { - permissions: ["dns"], + permissions: ["dns", "proxy"], }; return ExtensionTestUtils.loadExtension({ manifest, background() { browser.test.onMessage.addListener(async (msg, data) => { + if (msg == "proxy") { + await browser.proxy.settings.set({ value: data }); + browser.test.sendMessage("proxied"); + return; + } browser.test.log(`=== dns resolve test ${JSON.stringify(data)}`); browser.dns .resolve(data.hostname, data.flags) @@ -28,6 +43,8 @@ function getExtension(background = undefined) { }); browser.test.sendMessage("ready"); }, + incognitoOverride: "spanning", + useAddonManager: "temporary", }); } @@ -79,6 +96,10 @@ const tests = [ }, ]; +add_task(async function startup() { + await AddonTestUtils.promiseStartupManager(); +}); + add_task(async function test_dns_resolve() { let extension = getExtension(); await extension.startup(); @@ -117,3 +138,39 @@ add_task(async function test_dns_resolve() { await extension.unload(); }); + +add_task(async function test_dns_resolve_socks() { + let extension = getExtension(); + await extension.startup(); + await extension.awaitMessage("ready"); + extension.sendMessage("proxy", { + proxyType: "manual", + socks: "127.0.0.1", + socksVersion: 5, + proxyDNS: true, + }); + await extension.awaitMessage("proxied"); + equal( + Services.prefs.getIntPref("network.proxy.type"), + 1 /* PROXYCONFIG_MANUAL */, + "manual proxy" + ); + equal( + Services.prefs.getStringPref("network.proxy.socks"), + "127.0.0.1", + "socks proxy" + ); + ok( + Services.prefs.getBoolPref("network.proxy.socks_remote_dns"), + "socks remote dns" + ); + extension.sendMessage("resolve", { + hostname: "mozilla.org", + }); + let result = await extension.awaitMessage("resolved"); + ok( + /NS_ERROR_UNKNOWN_PROXY_HOST/.test(result.message), + `expected error ${result.message}` + ); + await extension.unload(); +}); diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini index 61bbeda44288..568b9f6ac1e2 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini @@ -63,6 +63,7 @@ skip-if = os == 'android' && debug # The generated script takes too long to load skip-if = appname == "thunderbird" || os == "android" # Containers are not exposed to android. [test_ext_debugging_utils.js] [test_ext_dns.js] +skip-if = socketprocess_networking [test_ext_downloads.js] [test_ext_downloads_download.js] skip-if = appname == "thunderbird" || os == "android" || tsan # tsan: bug 1612707