Backed out 7 changesets (bug 1566998) for causing build bustages at Logging.h.

Backed out changeset 1d0f667507f4 (bug 1566998)
Backed out changeset dc39d8837aae (bug 1566998)
Backed out changeset 24f76460c44b (bug 1566998)
Backed out changeset b674d5f15f60 (bug 1566998)
Backed out changeset f392ebf40d2a (bug 1566998)
Backed out changeset ecbfa0721168 (bug 1566998)
Backed out changeset d948fe16b8b0 (bug 1566998)
This commit is contained in:
Butkovits Atila 2021-11-09 20:24:03 +02:00
Родитель b58b48555a
Коммит 4059928c5d
24 изменённых файлов: 398 добавлений и 649 удалений

Просмотреть файл

@ -50,150 +50,140 @@ void TRRQuery::Cancel(nsresult aStatus) {
}
}
void TRRQuery::MarkSendingTRR(TRR* trr, enum TrrType rectype, MutexAutoLock&) {
if (rectype == TRRTYPE_A) {
MOZ_ASSERT(!mTrrA);
mTrrA = trr;
mTrrAUsed = STARTED;
} else if (rectype == TRRTYPE_AAAA) {
MOZ_ASSERT(!mTrrAAAA);
mTrrAAAA = trr;
mTrrAAAAUsed = STARTED;
} else {
LOG(("TrrLookup called with bad type set: %d\n", rectype));
MOZ_ASSERT(0);
}
}
void TRRQuery::PrepareQuery(bool aUseODoH, enum TrrType aRecType,
nsTArray<RefPtr<TRR>>& aRequestsToSend) {
LOG(("TRR Resolve %s type %d\n", mRecord->host.get(), (int)aRecType));
RefPtr<TRR> trr;
if (aUseODoH) {
trr = new ODoH(this, mRecord, aRecType);
} else {
trr = new TRR(this, mRecord, aRecType);
}
{
MutexAutoLock trrlock(mTrrLock);
MarkSendingTRR(trr, aRecType, trrlock);
aRequestsToSend.AppendElement(trr);
}
}
bool TRRQuery::SendQueries(nsTArray<RefPtr<TRR>>& aRequestsToSend) {
bool madeQuery = false;
mTRRRequestCounter = aRequestsToSend.Length();
for (const auto& request : aRequestsToSend) {
if (NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(request))) {
madeQuery = true;
} else {
mTRRRequestCounter--;
MutexAutoLock trrlock(mTrrLock);
if (request == mTrrA) {
mTrrA = nullptr;
mTrrAUsed = INIT;
}
if (request == mTrrAAAA) {
mTrrAAAA = nullptr;
mTrrAAAAUsed = INIT;
}
}
}
aRequestsToSend.Clear();
return madeQuery;
}
nsresult TRRQuery::DispatchLookup(TRR* pushedTRR, bool aUseODoH) {
if (aUseODoH && pushedTRR) {
MOZ_ASSERT(false, "ODoH should not support push");
return NS_ERROR_UNKNOWN_HOST;
}
if (!mRecord->IsAddrRecord()) {
return DispatchByTypeLookup(pushedTRR, aUseODoH);
}
mTrrStart = TimeStamp::Now();
RefPtr<AddrHostRecord> addrRec = do_QueryObject(mRecord);
MOZ_ASSERT(addrRec);
if (!addrRec) {
return NS_ERROR_UNEXPECTED;
RefPtr<AddrHostRecord> addrRec;
RefPtr<TypeHostRecord> typeRec;
if (mRecord->IsAddrRecord()) {
addrRec = do_QueryObject(mRecord);
MOZ_ASSERT(addrRec);
} else {
typeRec = do_QueryObject(mRecord);
MOZ_ASSERT(typeRec);
}
mTrrStart = TimeStamp::Now();
bool madeQuery = false;
mTrrAUsed = INIT;
mTrrAAAAUsed = INIT;
if (addrRec) {
mTrrAUsed = INIT;
mTrrAAAAUsed = INIT;
// Always issue both A and AAAA.
// When both are complete we filter out the unneeded results.
enum TrrType rectype = (mRecord->af == AF_INET6) ? TRRTYPE_AAAA : TRRTYPE_A;
// If asking for AF_UNSPEC, issue both A and AAAA.
// If asking for AF_INET6 or AF_INET, do only that single type
enum TrrType rectype = (mRecord->af == AF_INET6) ? TRRTYPE_AAAA : TRRTYPE_A;
if (pushedTRR) {
MutexAutoLock trrlock(mTrrLock);
rectype = pushedTRR->Type();
MarkSendingTRR(pushedTRR, rectype, trrlock);
return NS_OK;
}
if (pushedTRR) {
rectype = pushedTRR->Type();
}
bool sendAgain;
// Need to dispatch TRR requests after |mTrrA| and |mTrrAAAA| are set
// properly so as to avoid the race when CompleteLookup() is called at the
// same time.
nsTArray<RefPtr<TRR>> requestsToSend;
do {
sendAgain = false;
if ((TRRTYPE_AAAA == rectype) && TRRService::Get() &&
(TRRService::Get()->DisableIPv6() ||
(StaticPrefs::network_trr_skip_AAAA_when_not_supported() &&
mHostResolver->GetNCS() &&
mHostResolver->GetNCS()->GetIPv6() ==
nsINetworkConnectivityService::NOT_AVAILABLE))) {
break;
}
LOG(("TRR Resolve %s type %d\n", addrRec->host.get(), (int)rectype));
RefPtr<TRR> trr;
if (aUseODoH) {
trr = new ODoH(this, mRecord, rectype);
} else {
trr = pushedTRR ? pushedTRR : new TRR(this, mRecord, rectype);
}
// Need to dispatch TRR requests after |mTrrA| and |mTrrAAAA| are set
// properly so as to avoid the race when CompleteLookup() is called at the
// same time.
nsTArray<RefPtr<TRR>> requestsToSend;
if ((mRecord->af == AF_UNSPEC || mRecord->af == AF_INET6)) {
PrepareQuery(aUseODoH, TRRTYPE_AAAA, requestsToSend);
}
if (mRecord->af == AF_UNSPEC || mRecord->af == AF_INET) {
PrepareQuery(aUseODoH, TRRTYPE_A, requestsToSend);
}
{
MutexAutoLock trrlock(mTrrLock);
if (rectype == TRRTYPE_A) {
MOZ_ASSERT(!mTrrA);
mTrrA = trr;
mTrrAUsed = STARTED;
} else if (rectype == TRRTYPE_AAAA) {
MOZ_ASSERT(!mTrrAAAA);
mTrrAAAA = trr;
mTrrAAAAUsed = STARTED;
} else {
LOG(("TrrLookup called with bad type set: %d\n", rectype));
MOZ_ASSERT(0);
}
if (SendQueries(requestsToSend)) {
mUsingODoH = aUseODoH;
return NS_OK;
}
if (!pushedTRR) {
requestsToSend.AppendElement(trr);
if ((mRecord->af == AF_UNSPEC) && (rectype == TRRTYPE_A)) {
rectype = TRRTYPE_AAAA;
sendAgain = true;
}
} else {
madeQuery = true;
}
}
} while (sendAgain);
return NS_ERROR_UNKNOWN_HOST;
}
nsresult TRRQuery::DispatchByTypeLookup(TRR* pushedTRR, bool aUseODoH) {
RefPtr<TypeHostRecord> typeRec = do_QueryObject(mRecord);
MOZ_ASSERT(typeRec);
if (!typeRec) {
return NS_ERROR_UNEXPECTED;
}
typeRec->mStart = TimeStamp::Now();
enum TrrType rectype;
// XXX this could use a more extensible approach.
if (mRecord->type == nsIDNSService::RESOLVE_TYPE_TXT) {
rectype = TRRTYPE_TXT;
} else if (mRecord->type == nsIDNSService::RESOLVE_TYPE_HTTPSSVC) {
rectype = TRRTYPE_HTTPSSVC;
} else if (pushedTRR) {
rectype = pushedTRR->Type();
mTRRRequestCounter = requestsToSend.Length();
for (const auto& request : requestsToSend) {
if (NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(request))) {
madeQuery = true;
} else {
mTRRRequestCounter--;
MutexAutoLock trrlock(mTrrLock);
if (request == mTrrA) {
mTrrA = nullptr;
mTrrAUsed = INIT;
}
if (request == mTrrAAAA) {
mTrrAAAA = nullptr;
mTrrAAAAUsed = INIT;
}
}
}
requestsToSend.Clear();
} else {
MOZ_ASSERT(false, "Not an expected request type");
return NS_ERROR_UNKNOWN_HOST;
typeRec->mStart = TimeStamp::Now();
enum TrrType rectype;
// XXX this could use a more extensible approach.
if (mRecord->type == nsIDNSService::RESOLVE_TYPE_TXT) {
rectype = TRRTYPE_TXT;
} else if (mRecord->type == nsIDNSService::RESOLVE_TYPE_HTTPSSVC) {
rectype = TRRTYPE_HTTPSSVC;
} else if (pushedTRR) {
rectype = pushedTRR->Type();
} else {
MOZ_ASSERT(false, "Not an expected request type");
return NS_ERROR_UNKNOWN_HOST;
}
LOG(("TRR Resolve %s type %d\n", typeRec->host.get(), (int)rectype));
RefPtr<TRR> trr;
if (aUseODoH) {
trr = new ODoH(this, mRecord, rectype);
} else {
trr = pushedTRR ? pushedTRR : new TRR(this, mRecord, rectype);
}
if (pushedTRR || NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(trr))) {
MutexAutoLock trrlock(mTrrLock);
MOZ_ASSERT(!mTrrByType);
mTrrByType = trr;
madeQuery = true;
}
}
LOG(("TRR Resolve %s type %d\n", typeRec->host.get(), (int)rectype));
RefPtr<TRR> trr;
if (aUseODoH) {
trr = new ODoH(this, mRecord, rectype);
} else {
trr = pushedTRR ? pushedTRR : new TRR(this, mRecord, rectype);
}
if (pushedTRR || NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(trr))) {
MutexAutoLock trrlock(mTrrLock);
MOZ_ASSERT(!mTrrByType);
mTrrByType = trr;
return NS_OK;
}
return NS_ERROR_UNKNOWN_HOST;
return madeQuery ? NS_OK : NS_ERROR_UNKNOWN_HOST;
}
AHostResolver::LookupStatus TRRQuery::CompleteLookup(
@ -201,13 +191,10 @@ AHostResolver::LookupStatus TRRQuery::CompleteLookup(
const nsACString& aOriginsuffix, nsHostRecord::TRRSkippedReason aReason,
TRR* aTRRRequest) {
if (rec != mRecord) {
LOG(("TRRQuery::CompleteLookup - Pushed record. Go to resolver"));
return mHostResolver->CompleteLookup(rec, status, aNewRRSet, pb,
aOriginsuffix, aReason, aTRRRequest);
}
LOG(("TRRQuery::CompleteLookup > host: %s", rec->host.get()));
RefPtr<AddrInfo> newRRSet(aNewRRSet);
DNSResolverType resolverType = newRRSet->ResolverType();
{
@ -217,19 +204,11 @@ AHostResolver::LookupStatus TRRQuery::CompleteLookup(
mTRRAFailReason = aReason;
mTrrA = nullptr;
mTrrAUsed = NS_SUCCEEDED(status) ? OK : FAILED;
MOZ_ASSERT(!mAddrInfoA);
mAddrInfoA = newRRSet;
mAResult = status;
LOG(("A query status: %x", status));
} else if (newRRSet->TRRType() == TRRTYPE_AAAA) {
MOZ_ASSERT(mTrrAAAA);
mTRRAAAAFailReason = aReason;
mTrrAAAA = nullptr;
mTrrAAAAUsed = NS_SUCCEEDED(status) ? OK : FAILED;
MOZ_ASSERT(!mAddrInfoAAAA);
mAddrInfoAAAA = newRRSet;
mAAAAResult = status;
LOG(("AAAA query status: %x", status));
} else {
MOZ_ASSERT(0);
}
@ -253,87 +232,40 @@ AHostResolver::LookupStatus TRRQuery::CompleteLookup(
MOZ_DIAGNOSTIC_ASSERT(false, "Request counter is messed up");
}
if (pendingRequest) { // There are other outstanding requests
mFirstTRRresult = status;
if (NS_FAILED(status)) {
return LOOKUP_OK; // wait for outstanding
}
// There's another TRR complete pending. Wait for it and keep
// this RRset around until then.
MOZ_ASSERT(!mFirstTRR && newRRSet);
mFirstTRR.swap(newRRSet); // autoPtr.swap()
MOZ_ASSERT(mFirstTRR && !newRRSet);
LOG(("CompleteLookup: waiting for all responses!\n"));
return LOOKUP_OK;
}
if (mRecord->af == AF_UNSPEC) {
// merge successful records
if (mTrrAUsed == OK) {
LOG(("Have A response"));
newRRSet = mAddrInfoA;
status = mAResult;
if (mTrrAAAAUsed == OK) {
LOG(("Merging A and AAAA responses"));
newRRSet = merge_rrset(newRRSet, mAddrInfoAAAA);
}
// no more outstanding TRRs
// If mFirstTRR is set, merge those addresses into current set!
if (mFirstTRR) {
if (NS_SUCCEEDED(status)) {
LOG(("Merging responses"));
newRRSet = merge_rrset(newRRSet, mFirstTRR);
} else {
newRRSet = mAddrInfoAAAA;
status = mAAAAResult;
LOG(("Will use previous response"));
newRRSet.swap(mFirstTRR); // transfers
// We must use the status of the first response, otherwise we'll
// pass an error result to the consumers.
status = mFirstTRRresult;
}
if (NS_FAILED(status) && (mAAAAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST ||
mAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) {
mFirstTRR = nullptr;
} else {
if (NS_FAILED(status) && status != NS_ERROR_DEFINITIVE_UNKNOWN_HOST &&
mFirstTRRresult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST) {
status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST;
}
} else {
// If this is a failed AAAA request, but the server only has a A record,
// then we should not fallback to Do53. Instead we also send a A request
// and return NS_ERROR_DEFINITIVE_UNKNOWN_HOST if that succeeds.
if (NS_FAILED(status) && status != NS_ERROR_DEFINITIVE_UNKNOWN_HOST &&
(mTrrAUsed == INIT || mTrrAAAAUsed == INIT)) {
if (newRRSet->TRRType() == TRRTYPE_A) {
LOG(("A lookup failed. Checking if AAAA record exists"));
nsTArray<RefPtr<TRR>> requestsToSend;
PrepareQuery(mUsingODoH, TRRTYPE_AAAA, requestsToSend);
if (SendQueries(requestsToSend)) {
LOG(("Sent AAAA request"));
return LOOKUP_OK;
}
} else if (newRRSet->TRRType() == TRRTYPE_AAAA) {
LOG(("AAAA lookup failed. Checking if A record exists"));
nsTArray<RefPtr<TRR>> requestsToSend;
PrepareQuery(mUsingODoH, TRRTYPE_A, requestsToSend);
if (SendQueries(requestsToSend)) {
LOG(("Sent A request"));
return LOOKUP_OK;
}
} else {
MOZ_ASSERT(false, "Unexpected family");
}
}
bool otherSucceeded =
mRecord->af == AF_INET6 ? mTrrAUsed == OK : mTrrAAAAUsed == OK;
LOG(("TRRQuery::CompleteLookup other request succeeded"));
if (mRecord->af == AF_INET) {
// return only A record
newRRSet = mAddrInfoA;
status = mAResult;
if (NS_FAILED(status) &&
(otherSucceeded || mAAAAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) {
LOG(("status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"));
status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST;
}
} else if (mRecord->af == AF_INET6) {
// return only AAAA record
newRRSet = mAddrInfoAAAA;
status = mAAAAResult;
if (NS_FAILED(status) &&
(otherSucceeded || mAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) {
LOG(("status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"));
status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST;
}
} else {
MOZ_ASSERT(false, "Unexpected AF");
return LOOKUP_OK;
}
// If this record failed, but there is a record for the other AF
// we prevent fallback to the native resolver.
}
if (mTRRSuccess && mHostResolver->GetNCS() &&
@ -365,12 +297,6 @@ AHostResolver::LookupStatus TRRQuery::CompleteLookup(
}
}
mAddrInfoAAAA = nullptr;
mAddrInfoA = nullptr;
MOZ_DIAGNOSTIC_ASSERT(!mCalledCompleteLookup,
"must not call CompleteLookup more than once");
mCalledCompleteLookup = true;
return mHostResolver->CompleteLookup(rec, status, newRRSet, pb, aOriginsuffix,
aReason, aTRRRequest);
}
@ -378,19 +304,10 @@ AHostResolver::LookupStatus TRRQuery::CompleteLookup(
AHostResolver::LookupStatus TRRQuery::CompleteLookupByType(
nsHostRecord* rec, nsresult status,
mozilla::net::TypeRecordResultType& aResult, uint32_t aTtl, bool pb) {
if (rec != mRecord) {
LOG(("TRRQuery::CompleteLookup - Pushed record. Go to resolver"));
return mHostResolver->CompleteLookupByType(rec, status, aResult, aTtl, pb);
}
{
if (rec == mRecord) {
MutexAutoLock trrlock(mTrrLock);
mTrrByType = nullptr;
}
MOZ_DIAGNOSTIC_ASSERT(!mCalledCompleteLookup,
"must not call CompleteLookup more than once");
mCalledCompleteLookup = true;
return mHostResolver->CompleteLookupByType(rec, status, aResult, aTtl, pb);
}

Просмотреть файл

@ -8,7 +8,6 @@
#define mozilla_net_TRRQuery_h
#include "nsHostResolver.h"
#include "DNSPacket.h"
namespace mozilla {
namespace net {
@ -68,18 +67,8 @@ class TRRQuery : public AHostResolver {
mozilla::TimeDuration Duration() { return mTrrDuration; }
private:
nsresult DispatchByTypeLookup(TRR* pushedTRR = nullptr,
bool aUseODoHProxy = false);
private:
~TRRQuery() = default;
void MarkSendingTRR(TRR* trr, TrrType rectype, MutexAutoLock&);
void PrepareQuery(bool aUseODoH, TrrType aRecType,
nsTArray<RefPtr<TRR>>& aRequestsToSend);
bool SendQueries(nsTArray<RefPtr<TRR>>& aRequestsToSend);
RefPtr<nsHostResolver> mHostResolver;
RefPtr<nsHostRecord> mRecord;
@ -95,16 +84,12 @@ class TRRQuery : public AHostResolver {
Atomic<uint32_t> mTRRRequestCounter{0};
uint8_t mTRRSuccess = 0; // number of successful TRR responses
bool mUsingODoH = false;
bool mCalledCompleteLookup = false;
mozilla::TimeDuration mTrrDuration;
mozilla::TimeStamp mTrrStart;
RefPtr<mozilla::net::AddrInfo> mAddrInfoA;
RefPtr<mozilla::net::AddrInfo> mAddrInfoAAAA;
nsresult mAResult = NS_OK;
nsresult mAAAAResult = NS_OK;
RefPtr<mozilla::net::AddrInfo> mFirstTRR; // partial TRR storage
nsresult mFirstTRRresult = NS_OK;
};
} // namespace net

Просмотреть файл

@ -44,6 +44,8 @@ function trr_test_setup() {
Services.prefs.setBoolPref("network.dns.native-is-localhost", true);
Services.prefs.setBoolPref("network.trr.wait-for-portal", false);
// By default wait for all responses before notifying the listeners.
Services.prefs.setBoolPref("network.trr.wait-for-A-and-AAAA", true);
// don't confirm that TRR is working, just go!
Services.prefs.setCharPref("network.trr.confirmationNS", "skip");
// some tests rely on the cache not being cleared on pref change.
@ -78,6 +80,8 @@ function trr_clear_prefs() {
Services.prefs.clearUserPref("network.trr.request_timeout_mode_trronly_ms");
Services.prefs.clearUserPref("network.trr.disable-ECS");
Services.prefs.clearUserPref("network.trr.early-AAAA");
Services.prefs.clearUserPref("network.trr.skip-AAAA-when-not-supported");
Services.prefs.clearUserPref("network.trr.wait-for-A-and-AAAA");
Services.prefs.clearUserPref("network.trr.excluded-domains");
Services.prefs.clearUserPref("network.trr.builtin-excluded-domains");
Services.prefs.clearUserPref("network.trr.clear-cache-on-pref-change");
@ -149,7 +153,7 @@ class TRRDNSListener {
Assert.ok(!this.options.expectEarlyFail);
} catch (e) {
Assert.ok(this.options.expectEarlyFail);
this.resolve({ error: e });
this.resolve([e]);
}
}
@ -162,14 +166,14 @@ class TRRDNSListener {
// If we don't expect success here, just resolve and the caller will
// decide what to do with the results.
if (!this.expectedSuccess) {
this.resolve({ inRequest, inRecord, inStatus });
this.resolve([inRequest, inRecord, inStatus]);
return;
}
Assert.equal(inStatus, Cr.NS_OK, "Checking status");
if (this.type != Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT) {
this.resolve({ inRequest, inRecord, inStatus });
this.resolve([inRequest, inRecord, inStatus]);
return;
}
@ -211,7 +215,7 @@ class TRRDNSListener {
}
}
this.resolve({ inRequest, inRecord, inStatus });
this.resolve([inRequest, inRecord, inStatus]);
}
QueryInterface(aIID) {

Просмотреть файл

@ -39,7 +39,7 @@ add_task(async function testTXTResolve() {
"https://foo.example.com:" + h2Port + "/doh"
);
let { inRecord } = await new TRRDNSListener("_esni.example.com", {
let [, inRecord] = await new TRRDNSListener("_esni.example.com", {
type: dns.RESOLVE_TYPE_TXT,
});
@ -55,7 +55,7 @@ add_task(async function testTXTRecordPushPart1() {
"network.trr.uri",
"https://foo.example.com:" + h2Port + "/txt-dns-push"
);
let { inRecord } = await new TRRDNSListener("_esni_push.example.com", {
let [, inRecord] = await new TRRDNSListener("_esni_push.example.com", {
type: dns.RESOLVE_TYPE_DEFAULT,
expectedAnswer: "127.0.0.1",
});
@ -73,7 +73,7 @@ add_task(async function testTXTRecordPushPart2() {
"network.trr.uri",
"https://foo.example.com:" + h2Port + "/404"
);
let { inRecord } = await new TRRDNSListener("_esni_push.example.com", {
let [, inRecord] = await new TRRDNSListener("_esni_push.example.com", {
type: dns.RESOLVE_TYPE_TXT,
});

Просмотреть файл

@ -6,21 +6,38 @@
"use strict";
var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService(
Ci.nsINativeDNSResolverOverride
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService
);
var listener = {
onLookupComplete(inRequest, inRecord, inStatus) {
if (inStatus != Cr.NS_OK) {
Assert.equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
do_test_finished();
return;
}
while (true) {
try {
inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
var answer = inRecord.getNextAddrAsString();
// If there is an answer it should be an IPv6 address
dump(answer);
Assert.ok(answer.includes(":"));
} catch (e) {
break;
}
}
do_test_finished();
},
};
const defaultOriginAttributes = {};
add_task(async function test_none() {
let [, inRecord] = await new Promise(resolve => {
let listener = {
onLookupComplete(inRequest, inRecord, inStatus) {
resolve([inRequest, inRecord, inStatus]);
},
QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
};
function run_test() {
do_test_pending();
try {
dns.asyncResolve(
"example.org",
Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
@ -30,40 +47,9 @@ add_task(async function test_none() {
null,
defaultOriginAttributes
);
});
if (inRecord && inRecord.QueryInterface(Ci.nsIDNSAddrRecord)) {
while (inRecord.hasMore()) {
let nextIP = inRecord.getNextAddrAsString();
ok(nextIP.includes(":"), `${nextIP} should be IPv6`);
}
} catch (e) {
dump(e);
Assert.ok(false);
do_test_finished();
}
});
add_task(async function test_some() {
dns.clearCache(true);
gOverride.addIPOverride("example.com", "1.1.1.1");
gOverride.addIPOverride("example.org", "::1:2:3");
let [, inRecord] = await new Promise(resolve => {
let listener = {
onLookupComplete(inRequest, inRecord, inStatus) {
resolve([inRequest, inRecord, inStatus]);
},
QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
};
dns.asyncResolve(
"example.org",
Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
null, // resolverInfo
listener,
null,
defaultOriginAttributes
);
});
ok(inRecord.QueryInterface(Ci.nsIDNSAddrRecord));
equal(inRecord.getNextAddrAsString(), "::1:2:3");
equal(inRecord.hasMore(), false);
});
}

Просмотреть файл

@ -1,7 +1,7 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
trr_test_setup();
let h2Port = trr_test_setup();
let httpServerIPv4 = new HttpServer();
let httpServerIPv6 = new HttpServer();
let trrServer;
@ -9,7 +9,6 @@ let testpath = "/simple";
let httpbody = "0123456789";
let CC_IPV4 = "example_cc_ipv4.com";
let CC_IPV6 = "example_cc_ipv6.com";
Services.prefs.clearUserPref("network.dns.native-is-localhost");
XPCOMUtils.defineLazyGetter(this, "URL_CC_IPV4", function() {
return `http://${CC_IPV4}:${httpServerIPv4.identity.primaryPort}${testpath}`;
@ -79,15 +78,10 @@ add_task(async function test_setup() {
`https://foo.example.com:${trrServer.port}/dns-query`
);
await registerDoHAnswers(true, true);
});
async function registerDoHAnswers(ipv4, ipv6) {
let hosts = ["example6a.com", "example6b.com"];
for (const host of hosts) {
let ipv4answers = [];
if (ipv4) {
ipv4answers = [
await trrServer.registerDoHAnswers(host, "A", {
answers: [
{
name: host,
ttl: 55,
@ -95,15 +89,11 @@ async function registerDoHAnswers(ipv4, ipv6) {
flush: false,
data: "127.0.0.1",
},
];
}
await trrServer.registerDoHAnswers(host, "A", {
answers: ipv4answers,
],
});
let ipv6answers = [];
if (ipv6) {
ipv6answers = [
await trrServer.registerDoHAnswers(host, "AAAA", {
answers: [
{
name: host,
ttl: 55,
@ -111,16 +101,10 @@ async function registerDoHAnswers(ipv4, ipv6) {
flush: false,
data: "::1",
},
];
}
await trrServer.registerDoHAnswers(host, "AAAA", {
answers: ipv6answers,
],
});
}
dns.clearCache(true);
}
});
let StatusCounter = function() {
this._statusCount = {};
@ -182,12 +166,12 @@ async function make_request(uri, check_events, succeeded) {
if (check_events) {
equal(
statusCounter._statusCount[0x804b000b] || 0,
statusCounter._statusCount[0x804b000b],
1,
"Expecting only one instance of NS_NET_STATUS_RESOLVED_HOST"
);
equal(
statusCounter._statusCount[0x804b0007] || 0,
statusCounter._statusCount[0x804b0007],
1,
"Expecting only one instance of NS_NET_STATUS_CONNECTING_TO"
);
@ -252,8 +236,9 @@ async function setup_connectivity(ipv6, ipv4) {
// present, but a ConnectionEntry have IPv6 prefered set.
// Speculative connections are disabled.
add_task(async function test_prefer_address_version_fail_trr3_1() {
dns.clearCache(true);
Services.prefs.setIntPref("network.http.speculative-parallel-limit", 0);
await registerDoHAnswers(true, true);
// Make a request to setup the address version preference to a ConnectionEntry.
await make_request(URL6a, true, true);
@ -266,11 +251,6 @@ add_task(async function test_prefer_address_version_fail_trr3_1() {
dns.clearCache(true);
// This will succeed as we query both DNS records
await make_request(URL6a, true, true);
// Now make the DNS server only return IPv4 records
await registerDoHAnswers(true, false);
// This will fail, because the server is not lisenting to IPv4 address as well,
// We should still get NS_NET_STATUS_RESOLVED_HOST and
// NS_NET_STATUS_CONNECTING_TO notification.
@ -284,8 +264,9 @@ add_task(async function test_prefer_address_version_fail_trr3_1() {
// present, but a ConnectionEntry have IPv6 prefered set.
// Speculative connections are enabled.
add_task(async function test_prefer_address_version_fail_trr3_2() {
dns.clearCache(true);
Services.prefs.setIntPref("network.http.speculative-parallel-limit", 6);
await registerDoHAnswers(true, true);
// Make a request to setup the address version preference to a ConnectionEntry.
await make_request(URL6b, false, true);
@ -298,11 +279,6 @@ add_task(async function test_prefer_address_version_fail_trr3_2() {
dns.clearCache(true);
// This will succeed as we query both DNS records
await make_request(URL6b, false, true);
// Now make the DNS server only return IPv4 records
await registerDoHAnswers(true, false);
// This will fail, because the server is not lisenting to IPv4 address as well,
// We should still get NS_NET_STATUS_RESOLVED_HOST and
// NS_NET_STATUS_CONNECTING_TO notification.

Просмотреть файл

@ -5,6 +5,7 @@
"use strict";
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
var { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
let trrServer;
@ -100,7 +101,7 @@ add_task(async function testEchConfigEnabled() {
],
});
let { inRecord } = await new TRRDNSListener("test.bar.com", {
let [, inRecord] = await new TRRDNSListener("test.bar.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});
@ -124,9 +125,9 @@ add_task(async function testEchConfigEnabled() {
Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
dns.clearCache(true);
({ inRecord } = await new TRRDNSListener("test.bar.com", {
[, inRecord] = await new TRRDNSListener("test.bar.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
checkResult(inRecord, false, false, {
expectedPriority: 2,
@ -202,7 +203,7 @@ add_task(async function testTwoRecordsHaveEchConfig() {
],
});
let { inRecord } = await new TRRDNSListener("test.foo.com", {
let [, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});
@ -225,9 +226,9 @@ add_task(async function testTwoRecordsHaveEchConfig() {
Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
dns.clearCache(true);
({ inRecord } = await new TRRDNSListener("test.foo.com", {
[, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
checkResult(inRecord, false, false, {
expectedPriority: 1,
@ -301,7 +302,7 @@ add_task(async function testTwoRecordsHaveEchConfig1() {
],
});
let { inRecord } = await new TRRDNSListener("test.foo.com", {
let [, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});
@ -328,9 +329,9 @@ add_task(async function testTwoRecordsHaveEchConfig1() {
Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
dns.clearCache(true);
({ inRecord } = await new TRRDNSListener("test.foo.com", {
[, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
checkResult(inRecord, false, false, {
expectedPriority: 1,
@ -404,7 +405,7 @@ add_task(async function testOneRecordsHasEchConfig() {
],
});
let { inRecord } = await new TRRDNSListener("test.foo.com", {
let [, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});
@ -427,9 +428,9 @@ add_task(async function testOneRecordsHasEchConfig() {
Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
dns.clearCache(true);
({ inRecord } = await new TRRDNSListener("test.foo.com", {
[, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
checkResult(inRecord, false, false, {
expectedPriority: 1,
@ -502,7 +503,7 @@ add_task(async function testHttp3AndHttp2Pref() {
],
});
let { inRecord } = await new TRRDNSListener("test.foo.com", {
let [, inRecord] = await new TRRDNSListener("test.foo.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});

Просмотреть файл

@ -15,6 +15,12 @@ const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
const certOverrideService = Cc[
"@mozilla.org/security/certoverride;1"
].getService(Ci.nsICertOverrideService);
const threadManager = Cc["@mozilla.org/thread-manager;1"].getService(
Ci.nsIThreadManager
);
const mainThread = threadManager.currentThread;
const defaultOriginAttributes = {};
function setup() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
@ -74,7 +80,7 @@ add_task(async function testStoreIPHint() {
],
});
let { inRecord } = await new TRRDNSListener("test.IPHint.com", {
let [, inRecord] = await new TRRDNSListener("test.IPHint.com", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
});
@ -118,7 +124,7 @@ add_task(async function testStoreIPHint() {
);
async function verifyAnswer(flags, answer) {
let { inRecord } = await new TRRDNSListener("test.IPHint.com", {
let [, inRecord] = await new TRRDNSListener("test.IPHint.com", {
flags,
expectedSuccess: false,
});
@ -180,7 +186,7 @@ add_task(async function testConnectionWithIPHint() {
);
// Resolving test.iphint.com should be failed.
let { inStatus } = await new TRRDNSListener("test.iphint.com", {
let [, , inStatus] = await new TRRDNSListener("test.iphint.com", {
expectedSuccess: false,
});
Assert.equal(
@ -259,7 +265,7 @@ add_task(async function testIPHintWithFreshDNS() {
],
});
let { inRecord } = await new TRRDNSListener("test.iphint.org", {
let [, inRecord] = await new TRRDNSListener("test.iphint.org", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});

Просмотреть файл

@ -79,7 +79,7 @@ add_task(async function testPriorityAndECHConfig() {
],
});
let { inRecord } = await new TRRDNSListener("test.priority.com", {
let [, inRecord] = await new TRRDNSListener("test.priority.com", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
});
@ -100,9 +100,9 @@ add_task(async function testPriorityAndECHConfig() {
Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
dns.clearCache(true);
({ inRecord } = await new TRRDNSListener("test.priority.com", {
[, inRecord] = await new TRRDNSListener("test.priority.com", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
}));
});
answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
Assert.equal(answer.length, 4);

Просмотреть файл

@ -61,7 +61,7 @@ add_task(async function testODoHConfig() {
"https://foo.example.com:" + h2Port + "/odohconfig"
);
let { inRecord } = await new TRRDNSListener("odoh_host.example.com", {
let [, inRecord] = await new TRRDNSListener("odoh_host.example.com", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
});
let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
@ -258,6 +258,4 @@ add_task(test_fqdn);
add_task(test_ipv6_trr_fallback);
add_task(test_ipv4_trr_fallback);
add_task(test_no_retry_without_doh);

Просмотреть файл

@ -26,7 +26,7 @@ async function waitForConfirmation(expectedResponseIP, confirmationShouldFail) {
// because of the increased delay between the emulator and host.
await new Promise(resolve => do_timeout(100 * (100 / count), resolve));
}
let { inRecord } = await new TRRDNSListener(
let [, inRecord] = await new TRRDNSListener(
`ip${count}.example.org`,
undefined,
false
@ -341,7 +341,7 @@ add_task(async function test_async_resolve_with_trr_server() {
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=2.2.2.2");
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"bar_with_trr6.example.com",
undefined,
false,
@ -406,13 +406,13 @@ add_task(async function test_async_resolve_with_trr_server() {
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=2.2.2.2");
({ inStatus } = await new TRRDNSListener(
[, , inStatus] = await new TRRDNSListener(
"only_once.example.com",
undefined,
false,
undefined,
`https://target.example.com:666/404`
));
);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -760,8 +760,6 @@ add_task(async function test_dohrollout_mode() {
add_task(test_ipv6_trr_fallback);
add_task(test_ipv4_trr_fallback);
add_task(test_no_retry_without_doh);
// This test checks that normally when the TRR mode goes from ON -> OFF

Просмотреть файл

@ -21,6 +21,8 @@ function makeChan(url) {
return chan;
}
let processId;
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
@ -237,7 +239,7 @@ add_task(async function test_parse_additional_section() {
],
});
let { inRecord } = await new TRRDNSListener("multiple.foo", {
let [, inRecord] = await new TRRDNSListener("multiple.foo", {
expectedAnswer: "9.9.9.9",
});
let IPs = [];
@ -249,9 +251,9 @@ add_task(async function test_parse_additional_section() {
equal(IPs.length, 1);
equal(IPs[0], "9.9.9.9");
IPs = [];
({ inRecord } = await new TRRDNSListener("yuiop.foo", {
[, inRecord] = await new TRRDNSListener("yuiop.foo", {
expectedSuccess: false,
}));
});
inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
inRecord.rewind();
while (inRecord.hasMore()) {

Просмотреть файл

@ -1,121 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
Ci.nsIDNSService
);
const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService(
Ci.nsINativeDNSResolverOverride
);
trr_test_setup();
registerCleanupFunction(async () => {
trr_clear_prefs();
});
let trrServer = null;
add_task(async function start_trr_server() {
trrServer = new TRRServer();
registerCleanupFunction(async () => {
await trrServer.stop();
});
await trrServer.start();
dump(`port = ${trrServer.port}\n`);
Services.prefs.setBoolPref("network.trr.skip-AAAA-when-not-supported", false);
Services.prefs.setCharPref(
"network.trr.uri",
`https://foo.example.com:${trrServer.port}/dns-query`
);
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
});
add_task(async function unspec_first() {
gOverride.clearOverrides();
dns.clearCache(true);
gOverride.addIPOverride("example.org", "1.1.1.1");
gOverride.addIPOverride("example.org", "::1");
await trrServer.registerDoHAnswers("example.org", "A", {
answers: [
{
name: "example.org",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
// This first request gets cached. IPv6 response gets served from the cache
await new TRRDNSListener("example.org", { expectedAnswer: "1.2.3.4" });
await new TRRDNSListener("example.org", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
expectedAnswer: "1.2.3.4",
});
let { inStatus } = await new TRRDNSListener("example.org", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
});
add_task(async function A_then_AAAA_fails() {
gOverride.clearOverrides();
dns.clearCache(true);
gOverride.addIPOverride("example.org", "1.1.1.1");
gOverride.addIPOverride("example.org", "::1");
await trrServer.registerDoHAnswers("example.org", "A", {
answers: [
{
name: "example.org",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
// We do individual IPv4/IPv6 requests - we expect IPv6 not to fallback to Do53 because we have an IPv4 record
await new TRRDNSListener("example.org", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
expectedAnswer: "1.2.3.4",
});
let { inStatus } = await new TRRDNSListener("example.org", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
});
add_task(async function just_AAAA_fails() {
gOverride.clearOverrides();
dns.clearCache(true);
gOverride.addIPOverride("example.org", "1.1.1.1");
gOverride.addIPOverride("example.org", "::1");
await trrServer.registerDoHAnswers("example.org", "A", {
answers: [
{
name: "example.org",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
// We only do an IPv6 req - we expect IPv6 not to fallback to Do53 because we have an IPv4 record
let { inStatus } = await new TRRDNSListener("example.org", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
});

Просмотреть файл

@ -7,6 +7,9 @@
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
Ci.nsIDNSService
);
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
trr_test_setup();
registerCleanupFunction(async () => {
@ -60,7 +63,7 @@ add_task(async function cancel_immediately() {
let r1 = new TRRDNSListener("example.org", { expectedSuccess: false });
let r2 = new TRRDNSListener("example.org", { expectedAnswer: "2.3.4.5" });
r1.cancel();
let { inStatus } = await r1;
let [, , inStatus] = await r1;
equal(inStatus, Cr.NS_ERROR_ABORT);
await r2;
equal(await trrServer.requestCount("example.org", "A"), 1);
@ -71,9 +74,9 @@ add_task(async function cancel_immediately() {
r2 = new TRRDNSListener("example.org", { expectedSuccess: false });
r1.cancel();
r2.cancel();
({ inStatus } = await r1);
[, , inStatus] = await r1;
equal(inStatus, Cr.NS_ERROR_ABORT);
({ inStatus } = await r2);
[, , inStatus] = await r2;
equal(inStatus, Cr.NS_ERROR_ABORT);
await new Promise(resolve => do_timeout(50, resolve));
equal(await trrServer.requestCount("example.org", "A"), 2);
@ -97,7 +100,7 @@ add_task(async function cancel_delayed() {
let r2 = new TRRDNSListener("example.com", { expectedAnswer: "1.1.1.1" });
await new Promise(resolve => do_timeout(50, resolve));
r1.cancel();
let { inStatus } = await r1;
let [, , inStatus] = await r1;
equal(inStatus, Cr.NS_ERROR_ABORT);
await r2;
});

Просмотреть файл

@ -21,6 +21,8 @@ function makeChan(url) {
return chan;
}
let processId;
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
@ -80,7 +82,7 @@ add_task(async function test_follow_cnames_same_response() {
},
],
});
let { inRecord } = await new TRRDNSListener("something.foo", {
let [, inRecord] = await new TRRDNSListener("something.foo", {
expectedAnswer: "1.2.3.4",
flags: Ci.nsIDNSService.RESOLVE_CANONICAL_NAME,
});

Просмотреть файл

@ -54,7 +54,7 @@ add_task(async function intermittent_dns_mode3() {
},
],
});
let { inStatus } = await new TRRDNSListener("example.com", {
let [, , inStatus] = await new TRRDNSListener("example.com", {
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);

Просмотреть файл

@ -21,6 +21,8 @@ function makeChan(url) {
return chan;
}
let processId;
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
@ -85,7 +87,7 @@ add_task(async function test_extended_error_bogus() {
});
// Check that we don't fall back to DNS
let { inStatus } = await new TRRDNSListener("a.foo", {
let [, , inStatus] = await new TRRDNSListener("a.foo", {
expectedSuccess: false,
});
Assert.ok(
@ -114,7 +116,7 @@ add_task(async function test_extended_error_filtered() {
});
// Check that we don't fall back to DNS
let { inStatus } = await new TRRDNSListener("b.foo", {
let [, , inStatus] = await new TRRDNSListener("b.foo", {
expectedSuccess: false,
});
Assert.ok(
@ -313,7 +315,7 @@ add_task(async function test_only_ipv4_extended_error() {
},
],
});
let { inStatus } = await new TRRDNSListener("only.com", {
let [, , inStatus] = await new TRRDNSListener("only.com", {
expectedSuccess: false,
});
Assert.ok(

Просмотреть файл

@ -49,7 +49,7 @@ add_task(async function testHTTPSSVC() {
);
}
let { inRecord } = await new TRRDNSListener("test.httpssvc.com", {
let [, inRecord] = await new TRRDNSListener("test.httpssvc.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});
let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
@ -266,7 +266,7 @@ add_task(async function test_aliasform() {
],
});
let { inStatus } = await new TRRDNSListener("no-ip-host.com", {
let [, , inStatus] = await new TRRDNSListener("no-ip-host.com", {
expectedSuccess: false,
});
Assert.ok(
@ -303,9 +303,9 @@ add_task(async function test_aliasform() {
],
});
({ inStatus } = await new TRRDNSListener("loop.com", {
[, , inStatus] = await new TRRDNSListener("loop.com", {
expectedSuccess: false,
}));
});
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -328,9 +328,9 @@ add_task(async function test_aliasform() {
],
});
({ inStatus } = await new TRRDNSListener("empty.com", {
[, , inStatus] = await new TRRDNSListener("empty.com", {
expectedSuccess: false,
}));
});
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -371,7 +371,7 @@ add_task(async function test_aliasform() {
],
});
let { inStatus: inStatus2 } = await new TRRDNSListener("multi.com", {
let [, , inStatus2] = await new TRRDNSListener("multi.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
});
@ -404,10 +404,10 @@ add_task(async function test_aliasform() {
],
});
({ inStatus: inStatus2 } = await new TRRDNSListener("order.com", {
[, , inStatus2] = await new TRRDNSListener("order.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
}));
});
Assert.ok(
!Components.isSuccessCode(inStatus2),
`${inStatus2} should be an error code`
@ -433,10 +433,10 @@ add_task(async function test_aliasform() {
],
});
({ inStatus: inStatus2 } = await new TRRDNSListener("duplicate.com", {
[, , inStatus2] = await new TRRDNSListener("duplicate.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
}));
});
Assert.ok(
!Components.isSuccessCode(inStatus2),
`${inStatus2} should be an error code`
@ -463,10 +463,10 @@ add_task(async function test_aliasform() {
],
});
({ inStatus: inStatus2 } = await new TRRDNSListener("mandatory.com", {
[, , inStatus2] = await new TRRDNSListener("mandatory.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
}));
});
Assert.ok(!Components.isSuccessCode(inStatus2), `${inStatus2} should fail`);
// mandatory svcparam
@ -504,9 +504,9 @@ add_task(async function test_aliasform() {
],
});
({ inStatus: inStatus2 } = await new TRRDNSListener("mandatory2.com", {
[, , inStatus2] = await new TRRDNSListener("mandatory2.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
Assert.ok(Components.isSuccessCode(inStatus2), `${inStatus2} should succeed`);
@ -527,10 +527,10 @@ add_task(async function test_aliasform() {
],
});
({ inStatus: inStatus2 } = await new TRRDNSListener("no-alias.com", {
[, , inStatus2] = await new TRRDNSListener("no-alias.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
}));
});
Assert.ok(!Components.isSuccessCode(inStatus2), `${inStatus2} should fail`);
@ -552,9 +552,9 @@ add_task(async function test_aliasform() {
});
let inRecord;
({ inRecord, inStatus: inStatus2 } = await new TRRDNSListener("service.com", {
[, inRecord, inStatus2] = await new TRRDNSListener("service.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
Assert.ok(Components.isSuccessCode(inStatus2), `${inStatus2} should work`);
let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
Assert.equal(answer[0].priority, 1);
@ -562,7 +562,7 @@ add_task(async function test_aliasform() {
});
add_task(async function testNegativeResponse() {
let { inStatus } = await new TRRDNSListener("negative_test.com", {
let [, , inStatus] = await new TRRDNSListener("negative_test.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
});
@ -588,10 +588,10 @@ add_task(async function testNegativeResponse() {
});
// Should still be failed because a negative response is from DNS cache.
({ inStatus } = await new TRRDNSListener("negative_test.com", {
[, , inStatus] = await new TRRDNSListener("negative_test.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
expectedSuccess: false,
}));
});
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -605,9 +605,9 @@ add_task(async function testNegativeResponse() {
}
let inRecord;
({ inRecord, inStatus } = await new TRRDNSListener("negative_test.com", {
[, inRecord, inStatus] = await new TRRDNSListener("negative_test.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
}));
});
Assert.ok(Components.isSuccessCode(inStatus), `${inStatus} should work`);
let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
Assert.equal(answer[0].priority, 1);

Просмотреть файл

@ -45,6 +45,8 @@ function makeChan(url) {
return chan;
}
let processId;
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
@ -94,7 +96,7 @@ add_task(async function test_add_nat64_prefix_to_trr() {
},
],
});
let { inRecord } = await new TRRDNSListener("xyz.foo", {
let [, inRecord] = await new TRRDNSListener("xyz.foo", {
expectedSuccess: false,
});

Просмотреть файл

@ -212,7 +212,7 @@ add_task(async function testFallback() {
],
});
let { inRecord } = await new TRRDNSListener("test.fallback.com", {
let [, inRecord] = await new TRRDNSListener("test.fallback.com", {
type: dns.RESOLVE_TYPE_HTTPSSVC,
});

Просмотреть файл

@ -102,7 +102,7 @@ async function test_A_record() {
setModeAndURI(3, "doh?responseIP=4.4.4.4&auth=true");
Services.prefs.setCharPref("network.trr.credentials", "evil:person");
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"wrong.example.com",
undefined,
false
@ -139,7 +139,7 @@ async function test_RFC1918() {
dns.clearCache(true);
setModeAndURI(3, "doh?responseIP=192.168.0.1");
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"rfc1918.example.com",
undefined,
false
@ -150,11 +150,11 @@ async function test_RFC1918() {
`${inStatus} should be an error code`
);
setModeAndURI(3, "doh?responseIP=::ffff:192.168.0.1");
({ inStatus } = await new TRRDNSListener(
[, , inStatus] = await new TRRDNSListener(
"rfc1918-ipv6.example.com",
undefined,
false
));
);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -209,7 +209,7 @@ async function test_timeout_mode3() {
Services.prefs.setIntPref("network.trr.request_timeout_ms", 10);
Services.prefs.setIntPref("network.trr.request_timeout_mode_trronly_ms", 10);
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"timeout.example.com",
undefined,
false
@ -238,7 +238,7 @@ async function test_strict_native_fallback() {
Services.prefs.setIntPref("network.trr.request_timeout_ms", 10);
Services.prefs.setIntPref("network.trr.request_timeout_mode_trronly_ms", 10);
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"timeout.example.com",
undefined,
false
@ -253,7 +253,7 @@ async function test_strict_native_fallback() {
setModeAndURI(2, "doh?responseIP=2.2.2.2");
Services.prefs.clearUserPref("network.trr.request_timeout_ms");
Services.prefs.clearUserPref("network.trr.request_timeout_mode_trronly_ms");
({ inStatus } = await new TRRDNSListener("closeme.com", undefined, false));
[, , inStatus] = await new TRRDNSListener("closeme.com", undefined, false);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -262,11 +262,11 @@ async function test_strict_native_fallback() {
info("Now a decode error");
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=2.2.2.2&corruptedAnswer=true");
({ inStatus } = await new TRRDNSListener(
[, , inStatus] = await new TRRDNSListener(
"bar.example.com",
undefined,
false
));
);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -389,12 +389,18 @@ async function test_CNAME() {
dns.clearCache(true);
// First mode 3.
if (runningODoHTests) {
let chan = makeChan(
`https://foo.example.com:${h2Port}/reset_cname_confirm`,
Ci.nsIRequest.TRR_DISABLED_MODE
);
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
setModeAndURI(3, "odoh?responseIP=none&cnameloop=true");
} else {
setModeAndURI(3, "doh?responseIP=none&cnameloop=true");
}
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"test18.example.com",
undefined,
false
@ -433,7 +439,7 @@ async function test_name_mismatch() {
// regardless of what was requested.
setModeAndURI(3, "doh?hostname=mismatch.example.com");
let { inStatus } = await new TRRDNSListener(
let [, , inStatus] = await new TRRDNSListener(
"bar.example.com",
undefined,
false
@ -712,7 +718,11 @@ async function test_connection_closed() {
await new TRRDNSListener("bar.example.com", "2.2.2.2");
// makes the TRR connection shut down.
let { inStatus } = await new TRRDNSListener("closeme.com", undefined, false);
let [, , inStatus] = await new TRRDNSListener(
"closeme.com",
undefined,
false
);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -729,7 +739,7 @@ async function test_connection_closed() {
await new TRRDNSListener("bar.example.com", "2.2.2.2");
// makes the TRR connection shut down.
({ inStatus } = await new TRRDNSListener("closeme.com", undefined, false));
[, , inStatus] = await new TRRDNSListener("closeme.com", undefined, false);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -745,7 +755,7 @@ async function test_connection_closed() {
await new TRRDNSListener("bar.example.com", "2.2.2.2");
// makes the TRR connection shut down.
({ inStatus } = await new TRRDNSListener("closeme.com", undefined, false));
[, , inStatus] = await new TRRDNSListener("closeme.com", undefined, false);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -764,7 +774,7 @@ async function test_connection_closed() {
await new TRRDNSListener("bar.example.com", "2.2.2.2");
// makes the TRR connection shut down.
({ inStatus } = await new TRRDNSListener("closeme.com", undefined, false));
[, , inStatus] = await new TRRDNSListener("closeme.com", undefined, false);
Assert.ok(
!Components.isSuccessCode(inStatus),
`${inStatus} should be an error code`
@ -837,6 +847,49 @@ async function test_fqdn() {
async function test_ipv6_trr_fallback() {
info("Testing fallback with ipv6");
dns.clearCache(true);
let httpserver = new HttpServer();
httpserver.registerPathHandler("/content", (metadata, response) => {
response.setHeader("Content-Type", "text/plain");
response.setHeader("Cache-Control", "no-cache");
const responseBody = "anybody";
response.bodyOutputStream.write(responseBody, responseBody.length);
});
httpserver.start(-1);
Services.prefs.setBoolPref("network.captive-portal-service.testMode", true);
let url = `http://127.0.0.1:666/doom_port_should_not_be_open`;
Services.prefs.setCharPref("network.connectivity-service.IPv6.url", url);
let ncs = Cc[
"@mozilla.org/network/network-connectivity-service;1"
].getService(Ci.nsINetworkConnectivityService);
function promiseObserverNotification(topic, matchFunc) {
return new Promise((resolve, reject) => {
Services.obs.addObserver(function observe(subject, topic, data) {
let matches =
typeof matchFunc != "function" || matchFunc(subject, data);
if (!matches) {
return;
}
Services.obs.removeObserver(observe, topic);
resolve({ subject, data });
}, topic);
});
}
let checks = promiseObserverNotification(
"network:connectivity-service:ip-checks-complete"
);
ncs.recheckIPConnectivity();
await checks;
equal(
ncs.IPv6,
Ci.nsINetworkConnectivityService.NOT_AVAILABLE,
"Check IPv6 support (expect NOT_AVAILABLE)"
);
setModeAndURI(2, "doh?responseIP=4.4.4.4");
const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
@ -844,46 +897,21 @@ async function test_ipv6_trr_fallback() {
);
gOverride.addIPOverride("ipv6.host.com", "1:1::2");
// Should not fallback to Do53 because A request for ipv6.host.com returns
// 4.4.4.4
let { inStatus } = await new TRRDNSListener("ipv6.host.com", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
// This time both requests fail, so we do fall back
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=none");
await new TRRDNSListener("ipv6.host.com", "1:1::2");
override.clearOverrides();
}
async function test_ipv4_trr_fallback() {
info("Testing fallback with ipv4");
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=1:2::3");
const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
Ci.nsINativeDNSResolverOverride
await new TRRDNSListener(
"ipv6.host.com",
"1:1::2",
true,
0,
"",
false,
Ci.nsIDNSService.RESOLVE_DISABLE_IPV4
);
gOverride.addIPOverride("ipv4.host.com", "3.4.5.6");
// Should not fallback to Do53 because A request for ipv4.host.com returns
// 1:2::3
let { inStatus } = await new TRRDNSListener("ipv4.host.com", {
flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
expectedSuccess: false,
});
equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
// This time both requests fail, so we do fall back
dns.clearCache(true);
setModeAndURI(2, "doh?responseIP=none");
await new TRRDNSListener("ipv4.host.com", "3.4.5.6");
Services.prefs.clearUserPref("network.captive-portal-service.testMode");
Services.prefs.clearUserPref("network.connectivity-service.IPv6.url");
override.clearOverrides();
await httpserver.stop();
}
async function test_no_retry_without_doh() {

Просмотреть файл

@ -1,4 +1,3 @@
[DEFAULT]
head = head_channels.js head_cache.js head_cache2.js head_cookies.js head_trr.js head_http3.js
support-files =
@ -600,7 +599,6 @@ skip-if =
run-sequentially = node server exceptions dont replay well
[test_bug1725766.js]
skip-if = os == "android" # skip because of bug 1589327
[test_trr_af_fallback.js]
[test_https_rr_ech_prefs.js]
skip-if = os == "android"
run-sequentially = node server exceptions dont replay well

Просмотреть файл

@ -15,7 +15,7 @@ let test_answer_addr = "127.0.0.1";
add_task(async function testTXTResolve() {
// use the h2 server as DOH provider
let { inRecord, inStatus } = await new TRRDNSListener("_esni.example.com", {
let [, inRecord, inStatus] = await new TRRDNSListener("_esni.example.com", {
type: dns.RESOLVE_TYPE_TXT,
});
Assert.equal(inStatus, Cr.NS_OK, "status OK");

Просмотреть файл

@ -234,6 +234,8 @@ var didRst = false;
var rstConnection = null;
var illegalheader_conn = null;
var cname_confirm = 0;
// eslint-disable-next-line complexity
function handleRequest(req, res) {
// We do this first to ensure nothing goes wonky in our tests that don't want
@ -247,62 +249,23 @@ function handleRequest(req, res) {
// PushService tests.
var pushPushServer1, pushPushServer2, pushPushServer3, pushPushServer4;
function createCNameContent(payload) {
let packet = dnsPacket.decode(payload);
if (
packet.questions[0].name == "cname.example.com" &&
packet.questions[0].type == "A"
) {
return dnsPacket.encode({
id: 0,
type: "response",
flags: dnsPacket.RECURSION_DESIRED,
questions: [{ name: packet.questions[0].name, type: "A", class: "IN" }],
answers: [
{
name: packet.questions[0].name,
ttl: 55,
type: "CNAME",
flush: false,
data: "pointing-elsewhere.example.com",
},
],
});
function createCNameContent() {
let rContent;
if (0 == cname_confirm) {
// ... this sends a CNAME back to pointing-elsewhere.example.com
rContent = Buffer.from(
"00000100000100010000000005636E616D65076578616D706C6503636F6D0000050001C00C0005000100000037002012706F696E74696E672D656C73657768657265076578616D706C6503636F6D00",
"hex"
);
cname_confirm++;
} else {
// ... this sends an A 99.88.77.66 entry back for pointing-elsewhere.example.com
rContent = Buffer.from(
"00000100000100010000000012706F696E74696E672D656C73657768657265076578616D706C6503636F6D0000010001C00C0001000100000037000463584D42",
"hex"
);
}
if (
packet.questions[0].name == "pointing-elsewhere.example.com" &&
packet.questions[0].type == "A"
) {
return dnsPacket.encode({
id: 0,
type: "response",
flags: dnsPacket.RECURSION_DESIRED,
questions: [{ name: packet.questions[0].name, type: "A", class: "IN" }],
answers: [
{
name: packet.questions[0].name,
ttl: 55,
type: "A",
flush: false,
data: "99.88.77.66",
},
],
});
}
return dnsPacket.encode({
id: 0,
type: "response",
flags: dnsPacket.RECURSION_DESIRED | dnsPacket.rcodes.toRcode("NXDOMAIN"),
questions: [
{
name: packet.questions[0].name,
type: packet.questions[0].type,
class: "IN",
},
],
answers: [],
});
return rContent;
}
function createCNameARecord() {
@ -865,25 +828,17 @@ function handleRequest(req, res) {
// for use with test_trr.js
else if (u.pathname === "/dns-cname") {
// asking for cname.example.com
let rContent = createCNameContent();
function emitResponse(response, payload) {
let pcontent = createCNameContent(payload);
response.setHeader("Content-Type", "application/dns-message");
response.setHeader("Content-Length", pcontent.length);
response.writeHead(200);
response.write(pcontent);
response.end("");
}
let payload = Buffer.from("");
req.on("data", function receiveData(chunk) {
payload = Buffer.concat([payload, chunk]);
});
req.on("end", function finishedData() {
emitResponse(res, payload);
});
res.setHeader("Content-Type", "application/dns-message");
res.setHeader("Content-Length", rContent.length);
res.writeHead(200);
res.write(rContent);
res.end("");
return;
} else if (u.pathname == "/doh") {
cname_confirm = 0; // back to first reply for dns-cname
let responseIP = u.query.responseIP;
if (!responseIP) {
responseIP = "5.5.5.5";
@ -1218,12 +1173,12 @@ function handleRequest(req, res) {
}
if (u.query.cname) {
let decryptedQuery = odoh.decrypt_query(payload);
odoh.decrypt_query(payload);
let rContent;
if (u.query.cname === "ARecord") {
rContent = createCNameARecord();
} else {
rContent = createCNameContent(Buffer.from(decryptedQuery.buffer));
rContent = createCNameContent();
}
let encryptedResponse = odoh.create_response(rContent);
res.setHeader("Content-Type", "application/oblivious-dns-message");
@ -1239,6 +1194,13 @@ function handleRequest(req, res) {
}
});
return;
} else if (u.pathname === "/reset_cname_confirm") {
cname_confirm = 0;
res.setHeader("Content-Length", 4);
res.writeHead(200);
res.write("done");
res.end();
return;
} else if (u.pathname === "/httpssvc_as_altsvc") {
let payload = Buffer.from("");
req.on("data", function receiveData(chunk) {