test_https_rr_sorted_alpn.js (6026B)
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 "use strict"; 6 7 let trrServer; 8 9 const { TestUtils } = ChromeUtils.importESModule( 10 "resource://testing-common/TestUtils.sys.mjs" 11 ); 12 13 add_setup(async function setup() { 14 trr_test_setup(); 15 registerCleanupFunction(async () => { 16 trr_clear_prefs(); 17 Services.prefs.clearUserPref("network.http.http3.support_version1"); 18 Services.prefs.clearUserPref("security.tls.version.max"); 19 if (trrServer) { 20 await trrServer.stop(); 21 } 22 }); 23 24 if (mozinfo.socketprocess_networking) { 25 Services.dns; // Needed to trigger socket process. 26 await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); 27 } 28 }); 29 30 function checkResult(inRecord, noHttp2, noHttp3, result) { 31 if (!result) { 32 Assert.throws( 33 () => { 34 inRecord 35 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord) 36 .GetServiceModeRecord(noHttp2, noHttp3); 37 }, 38 /NS_ERROR_NOT_AVAILABLE/, 39 "Should get an error" 40 ); 41 return; 42 } 43 44 let record = inRecord 45 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord) 46 .GetServiceModeRecord(noHttp2, noHttp3); 47 Assert.equal(record.priority, result.expectedPriority); 48 Assert.equal(record.name, result.expectedName); 49 Assert.equal(record.selectedAlpn, result.expectedAlpn); 50 } 51 52 add_task(async function testSortedAlpnH3() { 53 Services.dns.clearCache(true); 54 55 trrServer = new TRRServer(); 56 await trrServer.start(); 57 58 Services.prefs.setIntPref("network.trr.mode", 3); 59 Services.prefs.setCharPref( 60 "network.trr.uri", 61 `https://foo.example.com:${trrServer.port()}/dns-query` 62 ); 63 Services.prefs.setBoolPref("network.http.http3.support_version1", true); 64 await trrServer.registerDoHAnswers("test.alpn.com", "HTTPS", { 65 answers: [ 66 { 67 name: "test.alpn.com", 68 ttl: 55, 69 type: "HTTPS", 70 flush: false, 71 data: { 72 priority: 1, 73 name: "test.alpn.com", 74 values: [{ key: "alpn", value: ["h2", "http/1.1", "h3"] }], 75 }, 76 }, 77 ], 78 }); 79 80 let { inRecord } = await new TRRDNSListener("test.alpn.com", { 81 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, 82 }); 83 84 checkResult(inRecord, false, false, { 85 expectedPriority: 1, 86 expectedName: "test.alpn.com", 87 expectedAlpn: "h3", 88 }); 89 checkResult(inRecord, false, true, { 90 expectedPriority: 1, 91 expectedName: "test.alpn.com", 92 expectedAlpn: "", 93 }); 94 checkResult(inRecord, true, false, { 95 expectedPriority: 1, 96 expectedName: "test.alpn.com", 97 expectedAlpn: "h3", 98 }); 99 checkResult(inRecord, true, true, { 100 expectedPriority: 1, 101 expectedName: "test.alpn.com", 102 expectedAlpn: "http/1.1", 103 }); 104 105 Services.prefs.setBoolPref("network.http.http3.support_version1", false); 106 checkResult(inRecord, false, false, { 107 expectedPriority: 1, 108 expectedName: "test.alpn.com", 109 expectedAlpn: "", 110 }); 111 checkResult(inRecord, false, true, { 112 expectedPriority: 1, 113 expectedName: "test.alpn.com", 114 expectedAlpn: "", 115 }); 116 checkResult(inRecord, true, false, { 117 expectedPriority: 1, 118 expectedName: "test.alpn.com", 119 expectedAlpn: "http/1.1", 120 }); 121 checkResult(inRecord, true, true, { 122 expectedPriority: 1, 123 expectedName: "test.alpn.com", 124 expectedAlpn: "http/1.1", 125 }); 126 Services.prefs.setBoolPref("network.http.http3.support_version1", true); 127 128 // Disable TLS1.3 129 Services.prefs.setIntPref("security.tls.version.max", 3); 130 checkResult(inRecord, false, false, { 131 expectedPriority: 1, 132 expectedName: "test.alpn.com", 133 expectedAlpn: "", 134 }); 135 checkResult(inRecord, false, true, { 136 expectedPriority: 1, 137 expectedName: "test.alpn.com", 138 expectedAlpn: "", 139 }); 140 checkResult(inRecord, true, false, { 141 expectedPriority: 1, 142 expectedName: "test.alpn.com", 143 expectedAlpn: "http/1.1", 144 }); 145 checkResult(inRecord, true, true, { 146 expectedPriority: 1, 147 expectedName: "test.alpn.com", 148 expectedAlpn: "http/1.1", 149 }); 150 151 // Enable TLS1.3 152 Services.prefs.setIntPref("security.tls.version.max", 4); 153 checkResult(inRecord, false, false, { 154 expectedPriority: 1, 155 expectedName: "test.alpn.com", 156 expectedAlpn: "h3", 157 }); 158 checkResult(inRecord, false, true, { 159 expectedPriority: 1, 160 expectedName: "test.alpn.com", 161 expectedAlpn: "", 162 }); 163 checkResult(inRecord, true, false, { 164 expectedPriority: 1, 165 expectedName: "test.alpn.com", 166 expectedAlpn: "h3", 167 }); 168 checkResult(inRecord, true, true, { 169 expectedPriority: 1, 170 expectedName: "test.alpn.com", 171 expectedAlpn: "http/1.1", 172 }); 173 }); 174 175 add_task(async function testSortedAlpnH2() { 176 Services.dns.clearCache(true); 177 178 Services.prefs.setIntPref("network.trr.mode", 3); 179 Services.prefs.setCharPref( 180 "network.trr.uri", 181 `https://foo.example.com:${trrServer.port()}/dns-query` 182 ); 183 await trrServer.registerDoHAnswers("test.alpn_2.com", "HTTPS", { 184 answers: [ 185 { 186 name: "test.alpn_2.com", 187 ttl: 55, 188 type: "HTTPS", 189 flush: false, 190 data: { 191 priority: 1, 192 name: "test.alpn_2.com", 193 values: [{ key: "alpn", value: ["http/1.1", "h2"] }], 194 }, 195 }, 196 ], 197 }); 198 199 let { inRecord } = await new TRRDNSListener("test.alpn_2.com", { 200 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, 201 }); 202 203 checkResult(inRecord, false, false, { 204 expectedPriority: 1, 205 expectedName: "test.alpn_2.com", 206 expectedAlpn: "", 207 }); 208 checkResult(inRecord, false, true, { 209 expectedPriority: 1, 210 expectedName: "test.alpn_2.com", 211 expectedAlpn: "", 212 }); 213 checkResult(inRecord, true, false, { 214 expectedPriority: 1, 215 expectedName: "test.alpn_2.com", 216 expectedAlpn: "http/1.1", 217 }); 218 checkResult(inRecord, true, true, { 219 expectedPriority: 1, 220 expectedName: "test.alpn_2.com", 221 expectedAlpn: "http/1.1", 222 }); 223 224 await trrServer.stop(); 225 trrServer = null; 226 });