diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /netwerk/test/unit/test_dns_onion.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_dns_onion.js')
-rw-r--r-- | netwerk/test/unit/test_dns_onion.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_dns_onion.js b/netwerk/test/unit/test_dns_onion.js new file mode 100644 index 0000000000..b7824fed3f --- /dev/null +++ b/netwerk/test/unit/test_dns_onion.js @@ -0,0 +1,82 @@ +"use strict"; + +var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); +var threadManager = Cc["@mozilla.org/thread-manager;1"].getService( + Ci.nsIThreadManager +); +var mainThread = threadManager.currentThread; + +var onionPref; +var localdomainPref; +var prefs = Cc["@mozilla.org/preferences-service;1"].getService( + Ci.nsIPrefBranch +); + +// check that we don't lookup .onion +var listenerBlock = { + onLookupComplete(inRequest, inRecord, inStatus) { + Assert.ok(!Components.isSuccessCode(inStatus)); + do_test_dontBlock(); + }, + QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]), +}; + +// check that we do lookup .onion (via pref) +var listenerDontBlock = { + onLookupComplete(inRequest, inRecord, inStatus) { + inRecord.QueryInterface(Ci.nsIDNSAddrRecord); + var answer = inRecord.getNextAddrAsString(); + Assert.ok(answer == "127.0.0.1" || answer == "::1"); + all_done(); + }, + QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]), +}; + +const defaultOriginAttributes = {}; + +function do_test_dontBlock() { + prefs.setBoolPref("network.dns.blockDotOnion", false); + dns.asyncResolve( + "private.onion", + Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, + 0, + null, // resolverInfo + listenerDontBlock, + mainThread, + defaultOriginAttributes + ); +} + +function do_test_block() { + prefs.setBoolPref("network.dns.blockDotOnion", true); + try { + dns.asyncResolve( + "private.onion", + Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, + 0, + null, // resolverInfo + listenerBlock, + mainThread, + defaultOriginAttributes + ); + } catch (e) { + // it is ok for this negative test to fail fast + Assert.ok(true); + do_test_dontBlock(); + } +} + +function all_done() { + // reset locally modified prefs + prefs.setCharPref("network.dns.localDomains", localdomainPref); + prefs.setBoolPref("network.dns.blockDotOnion", onionPref); + do_test_finished(); +} + +function run_test() { + onionPref = prefs.getBoolPref("network.dns.blockDotOnion"); + localdomainPref = prefs.getCharPref("network.dns.localDomains"); + prefs.setCharPref("network.dns.localDomains", "private.onion"); + do_test_block(); + do_test_pending(); +} |