Skip to content

Commit

Permalink
Bug 1878765 - Copy purpose to TRR request following CNAME r=necko-rev…
Browse files Browse the repository at this point in the history
…iewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D203137
  • Loading branch information
valenting committed Feb 29, 2024
1 parent de3474c commit 05f6750
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions netwerk/dns/TRR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down
64 changes: 64 additions & 0 deletions netwerk/test/unit/test_trr_blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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;
});
});

0 comments on commit 05f6750

Please sign in to comment.