Bug 1337246 - Part 3 - Add a test for hostnameIsLocalIPAddress. r=valentin draft
authorJohann Hofmann <jhofmann@mozilla.com>
Sun, 07 May 2017 21:12:45 +0200
changeset 574344 7ccb47feae6e60f979b560d6c4f2e8c0fce4d3d6
parent 574343 db9a82f764fddbd9cbd8fd625fa8e4caf6b77577
child 627564 87efc7e9cf205cce90cc1e4624ebfc3409dd85ab
push id57674
push userbmo:jhofmann@mozilla.com
push dateMon, 08 May 2017 18:59:31 +0000
reviewersvalentin
bugs1337246
milestone55.0a1
Bug 1337246 - Part 3 - Add a test for hostnameIsLocalIPAddress. r=valentin MozReview-Commit-ID: 11nCKJFsv6i
netwerk/test/unit/test_hostnameIsLocalIPAddress.js
netwerk/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_hostnameIsLocalIPAddress.js
@@ -0,0 +1,29 @@
+var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+
+function run_test() {
+  let testURIs = [
+    ["http://example.com", false],
+    ["about:robots", false],
+    ["http://9.255.255.255", false],
+    ["http://10.0.0.0", true],
+    ["http://10.0.23.31", true],
+    ["http://10.255.255.255", true],
+    ["http://11.0.0.0", false],
+    ["http://172.15.255.255", false],
+    ["http://172.16.0.0", true],
+    ["http://172.25.110.0", true],
+    ["http://172.31.255.255", true],
+    ["http://172.32.0.0", false],
+    ["http://192.167.255.255", false],
+    ["http://192.168.0.0", true],
+    ["http://192.168.127.10", true],
+    ["http://192.168.255.255", true],
+    ["http://192.169.0.0", false],
+  ];
+
+  for (let [uri, isLocal] of testURIs) {
+    let nsuri = ioService.newURI(uri);
+    equal(isLocal, ioService.hostnameIsLocalIPAddress(nsuri));
+  }
+}
+
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -212,16 +212,17 @@ skip-if = bits != 32
 [test_filestreams.js]
 [test_freshconnection.js]
 [test_gre_resources.js]
 [test_gzipped_206.js]
 [test_head.js]
 [test_header_Accept-Language.js]
 [test_header_Accept-Language_case.js]
 [test_headers.js]
+[test_hostnameIsLocalIPAddress.js]
 [test_http_headers.js]
 [test_httpauth.js]
 [test_httpcancel.js]
 [test_httpResponseTimeout.js]
 [test_httpsuspend.js]
 [test_idnservice.js]
 [test_idn_blacklist.js]
 [test_idn_urls.js]