/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
for (let i = 0; i < 15; i++) {
await trrServer.registerDoHAnswers(`failing-domain${i}.faily.com`, "A", {
error: 600,
});
await trrServer.registerDoHAnswers(`failing-domain${i}.faily.com`, "AAAA", {
error: 600,
});
}
});
function trigger15Failures() { // We need to clear the cache in case a previous call to this method // put the results in the DNS cache.
Services.dns.clearCache(true);
let dnsRequests = []; // There are actually two TRR requests sent for A and AAAA records, so doing // DNS query 10 times should be enough to trigger confirmation process. for (let i = 0; i < 10; i++) {
dnsRequests.push( new TRRDNSListener(`failing-domain${i}.faily.com`, {
expectedAnswer: "127.0.0.1",
})
);
}
await registerNS(500);
Services.prefs.setIntPref( "network.trr.mode",
Ci.nsIDNSService.MODE_NATIVEONLY
);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
);
await new Promise(resolve => do_timeout(100, resolve));
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Confirmation should still be pending"
);
await waitForConfirmationState(CONFIRM_OK, 3000);
});
add_task(async function confirm_timeout() {
Services.prefs.setIntPref( "network.trr.mode",
Ci.nsIDNSService.MODE_NATIVEONLY
);
equal(Services.dns.currentTrrConfirmationState, CONFIRM_OFF);
await registerNS(7000);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
);
await waitForConfirmationState(CONFIRM_FAILED, 7500); // After the confirmation fails, a timer will periodically trigger a retry // causing the state to go into CONFIRM_TRYING_FAILED.
await waitForConfirmationState(CONFIRM_TRYING_FAILED, 500);
});
await registerNS(100);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
);
await waitForConfirmationState(CONFIRM_OK, 3000);
await registerNS(4000);
let failures = trigger15Failures();
await waitForConfirmationState(CONFIRM_TRYING_OK, 3000);
await failures; // Check that failures during confirmation are ignored.
await trigger15Failures();
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
);
await waitForConfirmationState(CONFIRM_OK, 8500);
});
add_task(async function test_connectivity_change() {
Services.prefs.setCharPref( "network.trr.confirmationNS", "confirm.example.com"
);
Services.prefs.setCharPref( "network.trr.uri",
`https://foo.example.com:${trrServer.port()}/dns-query`
);
await registerNS(100);
Services.prefs.setIntPref( "network.trr.mode",
Ci.nsIDNSService.MODE_NATIVEONLY
);
let confirmationCount = await trrServer.requestCount( "confirm.example.com", "NS"
);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
);
await waitForConfirmationState(CONFIRM_OK, 3000);
equal(
await trrServer.requestCount("confirm.example.com", "NS"),
confirmationCount + 1
);
Services.obs.notifyObservers( null, "network:captive-portal-connectivity", "clear"
); // This means a CP check completed successfully. But no CP was previously // detected, so this is mostly a no-op.
equal(Services.dns.currentTrrConfirmationState, CONFIRM_OK);
Services.obs.notifyObservers( null, "network:captive-portal-connectivity", "captive"
); // This basically a successful CP login event. Wasn't captive before. // Still treating as a no-op.
equal(Services.dns.currentTrrConfirmationState, CONFIRM_OK);
// This makes the TRR service set mCaptiveIsPassed=false
Services.obs.notifyObservers( null, "captive-portal-login", "{type: 'captive-portal-login', id: 0, url: 'http://localhost/'}"
);
await registerNS(500);
let failures = trigger15Failures(); // The failure should cause us to go into CONFIRM_TRYING_OK and do an NS req
await waitForConfirmationState(CONFIRM_TRYING_OK, 3000);
await failures;
// The notification sets mCaptiveIsPassed=true then triggers an entirely new // confirmation.
Services.obs.notifyObservers( null, "network:captive-portal-connectivity", "clear"
); // The notification should cause us to send a new confirmation request
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_OK, "Should be CONFIRM_TRYING_OK"
); // This confirmation runs right after the captive-portal-login tore the // connection down, so it has to re-establish before the (delayed) NS reply.
await waitForConfirmationState(CONFIRM_OK, 3000); // two extra confirmation events should have been received by the server
equal(
await trrServer.requestCount("confirm.example.com", "NS"),
confirmationCount + 3
);
});
add_task(async function test_network_change() {
let confirmationCount = await trrServer.requestCount( "confirm.example.com", "NS"
);
equal(Services.dns.currentTrrConfirmationState, CONFIRM_OK);
let failures = trigger15Failures(); // The failure should cause us to go into CONFIRM_TRYING_OK and do an NS req
await waitForConfirmationState(CONFIRM_TRYING_OK, 3000);
await failures; // The network up event should reset the confirmation to TRYING_OK and do // another NS req
Services.obs.notifyObservers(null, "network:link-status-changed", "up");
equal(Services.dns.currentTrrConfirmationState, CONFIRM_TRYING_OK);
await waitForConfirmationState(CONFIRM_OK, 3000); // two extra confirmation events should have been received by the server
equal(
await trrServer.requestCount("confirm.example.com", "NS"),
confirmationCount + 2
);
});
add_task(async function test_autodetected_uri() { const defaultPrefBranch = Services.prefs.getDefaultBranch("");
let defaultURI = defaultPrefBranch.getCharPref( "network.trr.default_provider_uri"
);
defaultPrefBranch.setCharPref( "network.trr.default_provider_uri",
`https://foo.example.com:${trrServer.port()}/dns-query?changed`
); // For setDetectedTrrURI to work we must pretend we are using the default.
Services.prefs.clearUserPref("network.trr.uri");
await waitForConfirmationState(CONFIRM_OK, 3000);
let confirmationCount = await trrServer.requestCount( "confirm.example.com", "NS"
);
Services.dns.setDetectedTrrURI(
`https://foo.example.com:${trrServer.port()}/dns-query?changed2`
);
equal(Services.dns.currentTrrConfirmationState, CONFIRM_TRYING_OK);
await waitForConfirmationState(CONFIRM_OK, 3000);
equal(
await trrServer.requestCount("confirm.example.com", "NS"),
confirmationCount + 1
);
// reset the default URI
defaultPrefBranch.setCharPref("network.trr.default_provider_uri", defaultURI);
});
add_task(async function confirm_start_in_failed_state() { // Use a clean, reachable TRR config independent of the preceding tests.
Services.prefs.setIntPref( "network.trr.mode",
Ci.nsIDNSService.MODE_NATIVEONLY
);
Services.prefs.setCharPref( "network.trr.confirmationNS", "confirm.example.com"
);
Services.prefs.setCharPref( "network.trr.uri",
`https://foo.example.com:${trrServer.port()}/dns-query`
);
await registerNS(0);
equal(Services.dns.currentTrrConfirmationState, CONFIRM_OFF);
Services.prefs.setBoolPref( "network.trr.start-confirmation-in-failed-state", true
);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST); // With the pref set the confirmation context starts in CONFIRM_FAILED, so the // pending confirmation is CONFIRM_TRYING_FAILED instead of the optimistic // CONFIRM_TRYING_OK. While in this state TRRService::Enabled() returns false, // so lookups fall back to native DNS instead of blocking on the TRR // connection until the first confirmation succeeds.
equal(
Services.dns.currentTrrConfirmationState,
CONFIRM_TRYING_FAILED, "Should be CONFIRM_TRYING_FAILED"
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.