tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_hostnameIsLocalIPAddress.js (1372B)


      1 "use strict";
      2 
      3 function run_test() {
      4  let testURIs = [
      5    ["http://example.com", false],
      6    ["about:robots", false],
      7    // 0/8 prefix (RFC 1122)
      8    ["http://0.0.0.0", true],
      9    ["http://0.1.2.3", true],
     10    ["http://0.255.255.255", true],
     11    ["http://1.0.0.0", false],
     12    // 10/8 prefix (RFC 1918)
     13    ["http://9.255.255.255", false],
     14    ["http://10.0.0.0", true],
     15    ["http://10.0.23.31", true],
     16    ["http://10.255.255.255", true],
     17    ["http://11.0.0.0", false],
     18    // 169.254/16 prefix (Link Local)
     19    ["http://169.253.255.255", false],
     20    ["http://169.254.0.0", true],
     21    ["http://169.254.42.91", true],
     22    ["http://169.254.255.255", true],
     23    ["http://169.255.0.0", false],
     24    // 172.16/12 prefix (RFC 1918)
     25    ["http://172.15.255.255", false],
     26    ["http://172.16.0.0", true],
     27    ["http://172.25.110.0", true],
     28    ["http://172.31.255.255", true],
     29    ["http://172.32.0.0", false],
     30    // 192.168/16 prefix (RFC 1918)
     31    ["http://192.167.255.255", false],
     32    ["http://192.168.0.0", true],
     33    ["http://192.168.127.10", true],
     34    ["http://192.168.255.255", true],
     35    ["http://192.169.0.0", false],
     36    // IPv6 any address
     37    ["http://[::]", true],
     38    ["http://[::ffff:0:0]", true],
     39  ];
     40 
     41  for (let [uri, isLocal] of testURIs) {
     42    let nsuri = Services.io.newURI(uri);
     43    equal(isLocal, Services.io.hostnameIsLocalIPAddress(nsuri));
     44  }
     45 }