test_http3_with_third_party_roots.js (4445B)
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 "use strict"; 5 6 /* import-globals-from head_cache.js */ 7 /* import-globals-from head_cookies.js */ 8 /* import-globals-from head_channels.js */ 9 10 var { setTimeout } = ChromeUtils.importESModule( 11 "resource://gre/modules/Timer.sys.mjs" 12 ); 13 14 function makeChan(url) { 15 let chan = NetUtil.newChannel({ 16 uri: url, 17 loadUsingSystemPrincipal: true, 18 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT, 19 }).QueryInterface(Ci.nsIHttpChannel); 20 return chan; 21 } 22 23 function channelOpenPromise(chan, flags) { 24 return new Promise(resolve => { 25 function finish(req, buffer) { 26 resolve([req, buffer]); 27 } 28 chan.asyncOpen(new ChannelListener(finish, null, flags)); 29 }); 30 } 31 32 let h2Port; 33 let h3Port; 34 let trrServer; 35 36 add_setup(async function setup() { 37 await http3_setup_tests("h3", true); 38 Services.prefs.setBoolPref( 39 "network.http.http3.disable_when_third_party_roots_found", 40 true 41 ); 42 43 registerCleanupFunction(async () => { 44 http3_clear_prefs(); 45 46 Services.prefs.clearUserPref( 47 "network.http.http3.disable_when_third_party_roots_found" 48 ); 49 Services.prefs.clearUserPref( 50 "network.http.http3.has_third_party_roots_found_in_automation" 51 ); 52 Services.obs.notifyObservers(null, "network:reset_third_party_roots_check"); 53 54 if (trrServer) { 55 await trrServer.stop(); 56 } 57 }); 58 59 h2Port = Services.env.get("MOZHTTP2_PORT"); 60 Assert.notEqual(h2Port, null); 61 Assert.notEqual(h2Port, ""); 62 63 h3Port = Services.env.get("MOZHTTP3_PORT"); 64 }); 65 66 async function do_test(host, expectedVersion) { 67 Services.obs.notifyObservers(null, "net:cancel-all-connections"); 68 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 69 await new Promise(resolve => setTimeout(resolve, 3000)); 70 Services.obs.notifyObservers(null, "network:reset-http3-excluded-list"); 71 72 let chan = makeChan(`https://${host}:${h2Port}/`); 73 let [req] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL); 74 Assert.equal(req.protocolVersion, expectedVersion); 75 } 76 77 add_task(async function test_http3_with_third_party_roots() { 78 Services.prefs.setBoolPref( 79 "network.http.http3.has_third_party_roots_found_in_automation", 80 true 81 ); 82 83 await do_test("foo.example.com", "h2"); 84 }); 85 86 add_task(async function test_http3_with_no_third_party_roots() { 87 Services.prefs.setBoolPref( 88 "network.http.http3.has_third_party_roots_found_in_automation", 89 false 90 ); 91 92 await do_test("foo.example.com", "h3"); 93 }); 94 95 async function setup_trr_server() { 96 http3_clear_prefs(); 97 98 Services.prefs.setBoolPref("network.dns.port_prefixed_qname_https_rr", false); 99 trr_test_setup(); 100 101 trrServer = new TRRServer(); 102 await trrServer.start(); 103 104 Services.prefs.setIntPref("network.trr.mode", 3); 105 Services.prefs.setCharPref( 106 "network.trr.uri", 107 `https://foo.example.com:${trrServer.port()}/dns-query` 108 ); 109 110 await trrServer.registerDoHAnswers("alt1.example.com", "HTTPS", { 111 answers: [ 112 { 113 name: "alt1.example.com", 114 ttl: 55, 115 type: "HTTPS", 116 flush: false, 117 data: { 118 priority: 1, 119 name: "alt1.example.com", 120 values: [ 121 { key: "alpn", value: "h3" }, 122 { key: "port", value: h3Port }, 123 ], 124 }, 125 }, 126 ], 127 }); 128 129 await trrServer.registerDoHAnswers("alt1.example.com", "A", { 130 answers: [ 131 { 132 name: "alt1.example.com", 133 ttl: 55, 134 type: "A", 135 flush: false, 136 data: "127.0.0.1", 137 }, 138 ], 139 }); 140 141 let { inStatus } = await new TRRDNSListener("alt1.example.com", { 142 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, 143 }); 144 Assert.ok(Components.isSuccessCode(inStatus), `${inStatus} should work`); 145 } 146 147 // Similar to the previous test, but the difference is that we test this with 148 // HTTPS RR. 149 add_task(async function test_http3_with_third_party_roots_1() { 150 await setup_trr_server(); 151 152 Services.prefs.setBoolPref( 153 "network.http.http3.has_third_party_roots_found_in_automation", 154 true 155 ); 156 157 await do_test("alt1.example.com", "h2"); 158 }); 159 160 add_task(async function test_http3_with_no_third_party_roots_1() { 161 Services.prefs.setBoolPref( 162 "network.http.http3.has_third_party_roots_found_in_automation", 163 false 164 ); 165 166 await do_test("alt1.example.com", "h3"); 167 });