Bug 1878765 - Copy purpose to TRR request following CNAME r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D203137
This commit is contained in:
Valentin Gosu 2024-02-29 21:11:51 +00:00
parent de3474c44a
commit 05f6750807
2 changed files with 66 additions and 0 deletions

View File

@ -616,6 +616,7 @@ TRR::OnPush(nsIHttpChannel* associated, nsIHttpChannel* pushed) {
}
RefPtr<TRR> trr = new TRR(mHostResolver, mPB);
trr->SetPurpose(mPurpose);
return trr->ReceivePush(pushed, mRec);
}
@ -901,6 +902,7 @@ nsresult TRR::FollowCname(nsIChannel* aChannel) {
mCnameLoop));
RefPtr<TRR> trr =
new TRR(mHostResolver, mRec, mCname, mType, mCnameLoop, mPB);
trr->SetPurpose(mPurpose);
if (!TRRService::Get()) {
return NS_ERROR_FAILURE;
}

View File

@ -14,6 +14,21 @@ function setup() {
}
setup();
// Waits until a predicate returns true or re-tries the predicate calls
// |retry| times, we wait for 100ms between each calls.
async function waitUntil(predicate, retry = 20) {
let count = 0;
while (count++ < retry) {
if (await predicate()) {
return true;
}
// Wait for 100 milliseconds.
await new Promise(resolve => do_timeout(100, resolve));
}
// Timed out after trying too many times.
return false;
}
add_task(async function checkBlocklisting() {
let trrServer = new TRRServer();
registerCleanupFunction(async () => {
@ -76,3 +91,52 @@ add_task(async function checkBlocklisting() {
"We should do another TRR request because the bloclist expired"
);
});
add_task(async function test_blocklist_cname() {
let trrServer = new TRRServer();
registerCleanupFunction(async () => {
await trrServer.stop();
});
await trrServer.start();
info(`port = ${trrServer.port()}\n`);
Services.dns.clearCache(true);
Services.prefs.setCharPref(
"network.trr.uri",
`https://foo.example.com:${trrServer.port()}/dns-query`
);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
await trrServer.registerDoHAnswers(`top.test.com`, "NS", {
answers: [
{
name: "top.test.com",
ttl: 55,
type: "CNAME",
flush: false,
data: "other.foo",
},
],
});
await trrServer.registerDoHAnswers(`other.foo`, "NS", {
answers: [
{
name: "other.foo",
ttl: 55,
type: "NS",
flush: false,
data: "ns.other.foo",
},
],
});
override.addIPOverride("sub.top.test.com", "2.2.2.2");
await new TRRDNSListener("sub.top.test.com", {
expectedAnswer: "2.2.2.2",
});
await waitUntil(async () => {
return (await trrServer.requestCount("top.test.com", "NS")) == 1;
});
});