Bug 1555671 - tests, r=valentin, a=test-only
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 11 Jun 2019 19:02:50 +0000
changeset 536862 9d4fbafe8fcd89685ad29790b7d69518ac0d8567
parent 536861 a82e30d46f04b70c4c6ac04ee292f6b8641d03aa
child 536863 2a684be8b912e9b109f5ebf1389d248f04d0b922
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin, test-only
bugs1555671
milestone68.0
Bug 1555671 - tests, r=valentin, a=test-only Differential Revision: https://phabricator.services.mozilla.com/D33153
netwerk/test/unit/test_altsvc.js
--- a/netwerk/test/unit/test_altsvc.js
+++ b/netwerk/test/unit/test_altsvc.js
@@ -7,16 +7,18 @@ var http2pref;
 var altsvcpref1;
 var altsvcpref2;
 
 // https://foo.example.com:(h2Port)
 // https://bar.example.com:(h2Port) <- invalid for bar, but ok for foo
 var h1Foo; // server http://foo.example.com:(h1Foo.identity.primaryPort)
 var h1Bar; // server http://bar.example.com:(h1bar.identity.primaryPort)
 
+var otherServer; // server socket listening for other connection.
+
 var h2FooRoute; // foo.example.com:H2PORT
 var h2BarRoute; // bar.example.com:H2PORT
 var h2Route;    // :H2PORT
 var httpFooOrigin; // http://foo.exmaple.com:PORT/
 var httpsFooOrigin; // https://foo.exmaple.com:PORT/
 var httpBarOrigin; // http://bar.example.com:PORT/
 var httpsBarOrigin; // https://bar.example.com:PORT/
 
@@ -108,16 +110,17 @@ function h1ServerWK(metadata, response) 
 }
 
 function resetPrefs() {
   prefs.setBoolPref("network.http.spdy.enabled", spdypref);
   prefs.setBoolPref("network.http.spdy.enabled.http2", http2pref);
   prefs.setBoolPref("network.http.altsvc.enabled", altsvcpref1);
   prefs.setBoolPref("network.http.altsvc.oe", altsvcpref2);
   prefs.clearUserPref("network.dns.localDomains");
+  prefs.clearUserPref("network.security.ports.banned");
 }
 
 function makeChan(origin) {
   return NetUtil.newChannel({
     uri: origin + "altsvc-test",
     loadUsingSystemPrincipal: true
   }).QueryInterface(Ci.nsIHttpChannel);
 }
@@ -182,16 +185,18 @@ Listener.prototype = {
   }
 };
 
 function testsDone()
 {
   dump("testDone\n");
   resetPrefs();
   do_test_pending();
+  otherServer.close();
+  do_test_pending();
   h1Foo.stop(do_test_finished);
   do_test_pending();
   h1Bar.stop(do_test_finished);
 }
 
 function doTest()
 {
   dump("execute doTest " + origin + "\n");
@@ -413,15 +418,40 @@ function doTest15()
   dump("doTest15()\n");
   origin = httpFooOrigin;
   xaltsvc = 'NA';
   originAttributes = {
     userContextId: 1,
     firstPartyDomain: "a.com",
   };
   loadWithoutClearingMappings = true;
-  nextTest = testsDone;
+  nextTest = doTest16;
   do_test_pending();
   doTest();
   // This ensures a cache hit.
   xaltsvc = h2FooRoute;
 }
 
+// Check we don't connect to blocked ports
+function doTest16()
+{
+  dump("doTest16()\n");
+  origin = httpFooOrigin;
+  nextTest = testsDone;
+  otherServer = Cc["@mozilla.org/network/server-socket;1"].createInstance(Ci.nsIServerSocket);
+  otherServer.init(-1, true, -1);
+  xaltsvc = "localhost:" + otherServer.port;
+  Services.prefs.setCharPref("network.security.ports.banned", "" + otherServer.port);
+  dump("Blocked port: " + otherServer.port);
+  waitFor = 500;
+  otherServer.asyncListen({
+    onSocketAccepted() {
+      Assert.ok(false, "Got connection to socket when we didn't expect it!");
+    },
+    onStopListening() {
+      // We get closed when the entire file is done, which guarantees we get the socket accept
+      // if we do connect to the alt-svc header
+      do_test_finished();
+    },
+  });
+  do_test_pending();
+  doTest();
+}