tor-browser

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

test_large_port.js (1591B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Ensure that non-16-bit URIs are rejected
      6 
      7 "use strict";
      8 
      9 function run_test() {
     10  let mutator = Cc[
     11    "@mozilla.org/network/standard-url-mutator;1"
     12  ].createInstance(Ci.nsIURIMutator);
     13  Assert.ok(mutator, "Mutator constructor works");
     14 
     15  let url = Cc["@mozilla.org/network/standard-url-mutator;1"]
     16    .createInstance(Ci.nsIStandardURLMutator)
     17    .init(
     18      Ci.nsIStandardURL.URLTYPE_AUTHORITY,
     19      65535,
     20      "http://localhost",
     21      "UTF-8",
     22      null
     23    )
     24    .finalize();
     25 
     26  // Bug 1301621 makes invalid ports throw
     27  Assert.throws(
     28    () => {
     29      url = Cc["@mozilla.org/network/standard-url-mutator;1"]
     30        .createInstance(Ci.nsIStandardURLMutator)
     31        .init(
     32          Ci.nsIStandardURL.URLTYPE_AUTHORITY,
     33          65536,
     34          "http://localhost",
     35          "UTF-8",
     36          null
     37        )
     38        .finalize();
     39    },
     40    /NS_ERROR_MALFORMED_URI/,
     41    "invalid port during creation"
     42  );
     43 
     44  Assert.throws(
     45    () => {
     46      url = url
     47        .mutate()
     48        .QueryInterface(Ci.nsIStandardURLMutator)
     49        .setDefaultPort(65536)
     50        .finalize();
     51    },
     52    /NS_ERROR_MALFORMED_URI/,
     53    "invalid port in setDefaultPort"
     54  );
     55  Assert.throws(
     56    () => {
     57      url = url.mutate().setPort(65536).finalize();
     58    },
     59    /NS_ERROR_MALFORMED_URI/,
     60    "invalid port in port setter"
     61  );
     62 
     63  Assert.equal(url.port, -1);
     64  do_test_finished();
     65 }