mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Backed out changeset 901b3eec4eb6 (bug 1618130) for xpcshell failures at netwerk/test/unit/test_dns_override.js on a CLOSED TREE
This commit is contained in:
parent
24486add05
commit
a4bb946bff
@ -112,15 +112,6 @@ Classes = [
|
||||
'headers': ['/netwerk/dns/nsDNSService2.h'],
|
||||
'processes': ProcessSelector.ALLOW_IN_SOCKET_PROCESS,
|
||||
},
|
||||
{
|
||||
'cid': '{4ffae79e-57bd-4d7a-a0c9-0045a17b3615}',
|
||||
'contract_ids': ['@mozilla.org/network/native-dns-override;1'],
|
||||
'singleton': True,
|
||||
'type': 'nsINativeDNSResolverOverride',
|
||||
'constructor': 'mozilla::net::NativeDNSResolverOverride::GetSingleton',
|
||||
'headers': ['/netwerk/dns/GetAddrInfo.h'],
|
||||
'processes': ProcessSelector.ALLOW_IN_SOCKET_PROCESS,
|
||||
},
|
||||
{
|
||||
'cid': '{510a86bb-6019-4ed1-bb4f-965cffd23ece}',
|
||||
'contract_ids': ['@mozilla.org/network/downloader;1'],
|
||||
|
@ -29,8 +29,6 @@
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
static StaticRefPtr<NativeDNSResolverOverride> gOverrideService;
|
||||
|
||||
static LazyLogModule gGetAddrInfoLog("GetAddrInfo");
|
||||
#define LOG(msg, ...) \
|
||||
MOZ_LOG(gGetAddrInfoLog, LogLevel::Debug, ("[DNS]: " msg, ##__VA_ARGS__))
|
||||
@ -188,41 +186,6 @@ nsresult GetAddrInfoShutdown() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool FindAddrOverride(const nsACString& aHost, uint16_t aAddressFamily,
|
||||
uint16_t aFlags, AddrInfo** aAddrInfo) {
|
||||
RefPtr<NativeDNSResolverOverride> overrideService = gOverrideService;
|
||||
if (!overrideService) {
|
||||
return false;
|
||||
}
|
||||
AutoReadLock lock(overrideService->mLock);
|
||||
nsTArray<PRNetAddr>* overrides = overrideService->mOverrides.GetValue(aHost);
|
||||
if (!overrides) {
|
||||
return false;
|
||||
}
|
||||
nsCString* cname = nullptr;
|
||||
if (aFlags & nsHostResolver::RES_CANON_NAME) {
|
||||
cname = overrideService->mCnames.GetValue(aHost);
|
||||
}
|
||||
|
||||
RefPtr<AddrInfo> ai;
|
||||
|
||||
if (!cname) {
|
||||
ai = new AddrInfo(aHost, 0);
|
||||
} else {
|
||||
ai = new AddrInfo(aHost, *cname, 0);
|
||||
}
|
||||
|
||||
for (const auto& ip : *overrides) {
|
||||
if (aAddressFamily != AF_UNSPEC && ip.raw.family != aAddressFamily) {
|
||||
continue;
|
||||
}
|
||||
ai->AddAddress(new NetAddrElement(&ip));
|
||||
}
|
||||
|
||||
ai.forget(aAddrInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
|
||||
uint16_t aFlags, AddrInfo** aAddrInfo, bool aGetTtl) {
|
||||
if (NS_WARN_IF(aHost.IsEmpty()) || NS_WARN_IF(!aAddrInfo)) {
|
||||
@ -236,12 +199,6 @@ nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
|
||||
}
|
||||
#endif
|
||||
|
||||
// If there is an override for this host, then we synthetize a result.
|
||||
if (gOverrideService &&
|
||||
FindAddrOverride(aHost, aAddressFamily, aFlags, aAddrInfo)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString host(aHost);
|
||||
if (gNativeIsLocalhost) {
|
||||
// pretend we use the given host but use IPv4 localhost instead!
|
||||
@ -279,70 +236,5 @@ nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
|
||||
return rv;
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsINativeDNSResolverOverride>
|
||||
NativeDNSResolverOverride::GetSingleton() {
|
||||
if (gOverrideService) {
|
||||
return do_AddRef(gOverrideService);
|
||||
}
|
||||
|
||||
gOverrideService = new NativeDNSResolverOverride();
|
||||
ClearOnShutdown(&gOverrideService);
|
||||
return do_AddRef(gOverrideService);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(NativeDNSResolverOverride, nsINativeDNSResolverOverride)
|
||||
|
||||
NS_IMETHODIMP NativeDNSResolverOverride::AddIPOverride(
|
||||
const nsACString& aHost, const nsACString& aIPLiteral) {
|
||||
PRNetAddr tempAddr;
|
||||
// Unfortunately, PR_StringToNetAddr does not properly initialize
|
||||
// the output buffer in the case of IPv6 input. See bug 223145.
|
||||
memset(&tempAddr, 0, sizeof(PRNetAddr));
|
||||
|
||||
if (PR_StringToNetAddr(nsCString(aIPLiteral).get(), &tempAddr) !=
|
||||
PR_SUCCESS) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
AutoWriteLock lock(mLock);
|
||||
auto& overrides = mOverrides.GetOrInsert(aHost);
|
||||
overrides.AppendElement(tempAddr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP NativeDNSResolverOverride::SetCnameOverride(
|
||||
const nsACString& aHost, const nsACString& aCNAME) {
|
||||
if (aCNAME.IsEmpty()) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
AutoWriteLock lock(mLock);
|
||||
mCnames.Put(aHost, nsCString(aCNAME));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP NativeDNSResolverOverride::ClearHostOverride(
|
||||
const nsACString& aHost) {
|
||||
AutoWriteLock lock(mLock);
|
||||
mCnames.Remove(aHost);
|
||||
auto overrides = mOverrides.GetAndRemove(aHost);
|
||||
if (!overrides) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
overrides->Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP NativeDNSResolverOverride::ClearOverrides() {
|
||||
AutoWriteLock lock(mLock);
|
||||
mOverrides.Clear();
|
||||
mCnames.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
@ -9,10 +9,6 @@
|
||||
|
||||
#include "nsError.h"
|
||||
#include "nscore.h"
|
||||
#include "nsINativeDNSResolverOverride.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "mozilla/RWLock.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
# define DNSQUERY_AVAILABLE 1
|
||||
@ -60,25 +56,6 @@ nsresult GetAddrInfoInit();
|
||||
*/
|
||||
nsresult GetAddrInfoShutdown();
|
||||
|
||||
class NativeDNSResolverOverride : public nsINativeDNSResolverOverride {
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
|
||||
public:
|
||||
NativeDNSResolverOverride() : mLock("NativeDNSResolverOverride") {}
|
||||
|
||||
static already_AddRefed<nsINativeDNSResolverOverride> GetSingleton();
|
||||
|
||||
private:
|
||||
virtual ~NativeDNSResolverOverride() = default;
|
||||
mozilla::RWLock mLock;
|
||||
|
||||
nsDataHashtable<nsCStringHashKey, nsTArray<PRNetAddr>> mOverrides;
|
||||
nsDataHashtable<nsCStringHashKey, nsCString> mCnames;
|
||||
|
||||
friend bool FindAddrOverride(const nsACString& aHost, uint16_t aAddressFamily,
|
||||
uint16_t aFlags, AddrInfo** aAddrInfo);
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -19,7 +19,6 @@ XPIDL_SOURCES += [
|
||||
'nsIDNSService.idl',
|
||||
'nsIEffectiveTLDService.idl',
|
||||
'nsIIDNService.idl',
|
||||
'nsINativeDNSResolverOverride.idl',
|
||||
'nsPIDNSService.idl',
|
||||
]
|
||||
|
||||
|
@ -1,29 +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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(8e38d536-5501-48c0-a412-6c450040c8c8)]
|
||||
interface nsINativeDNSResolverOverride : nsISupports
|
||||
{
|
||||
/**
|
||||
* Adds an IP override for this specific host.
|
||||
*/
|
||||
void addIPOverride(in AUTF8String aHost, in ACString aIPLiteral);
|
||||
|
||||
/**
|
||||
* Sets a CNAME override for this specific host.
|
||||
*/
|
||||
void setCnameOverride(in AUTF8String aHost, in ACString aCNAME);
|
||||
|
||||
/**
|
||||
* Clears the overrides for this specific host
|
||||
*/
|
||||
void clearHostOverride(in AUTF8String aHost);
|
||||
|
||||
/**
|
||||
* Clears all the host overrides that were previously set.
|
||||
*/
|
||||
void clearOverrides();
|
||||
};
|
@ -1,271 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
|
||||
Ci.nsIDNSService
|
||||
);
|
||||
const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
|
||||
Ci.nsINativeDNSResolverOverride
|
||||
);
|
||||
const defaultOriginAttributes = {};
|
||||
const threadManager = Cc["@mozilla.org/thread-manager;1"].getService(
|
||||
Ci.nsIThreadManager
|
||||
);
|
||||
const mainThread = threadManager.currentThread;
|
||||
|
||||
class Listener {
|
||||
constructor() {
|
||||
this.promise = new Promise(resolve => {
|
||||
this.resolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
onLookupComplete(inRequest, inRecord, inStatus) {
|
||||
this.resolve([inRequest, inRecord, inStatus]);
|
||||
}
|
||||
|
||||
async firstAddress() {
|
||||
let all = await this.addresses();
|
||||
return all[0];
|
||||
}
|
||||
|
||||
async addresses() {
|
||||
let [inRequest, inRecord, inStatus] = await this.promise;
|
||||
let addresses = [];
|
||||
while (inRecord.hasMore()) {
|
||||
addresses.push(inRecord.getNextAddrAsString());
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
then() {
|
||||
return this.promise.then.apply(this.promise, arguments);
|
||||
}
|
||||
}
|
||||
Listener.prototype.QueryInterface = ChromeUtils.generateQI(["nsIDNSListener"]);
|
||||
|
||||
add_task(async function test_bad_IPs() {
|
||||
Assert.throws(
|
||||
() => override.addIPOverride("test.com", "test.com"),
|
||||
/NS_ERROR_UNEXPECTED/,
|
||||
"Should throw if input is not an IP address"
|
||||
);
|
||||
Assert.throws(
|
||||
() => override.addIPOverride("test.com", ""),
|
||||
/NS_ERROR_UNEXPECTED/,
|
||||
"Should throw if input is not an IP address"
|
||||
);
|
||||
Assert.throws(
|
||||
() => override.addIPOverride("test.com", " "),
|
||||
/NS_ERROR_UNEXPECTED/,
|
||||
"Should throw if input is not an IP address"
|
||||
);
|
||||
Assert.throws(
|
||||
() => override.addIPOverride("test.com", "1-2-3-4"),
|
||||
/NS_ERROR_UNEXPECTED/,
|
||||
"Should throw if input is not an IP address"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_ipv4() {
|
||||
let listener = new Listener();
|
||||
override.addIPOverride("test.com", "1.2.3.4");
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.equal(await listener.firstAddress(), "1.2.3.4");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_ipv6() {
|
||||
let listener = new Listener();
|
||||
override.addIPOverride("test.com", "fe80::6a99:9b2b:6ccc:6e1b");
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.equal(await listener.firstAddress(), "fe80::6a99:9b2b:6ccc:6e1b");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_clearOverrides() {
|
||||
let listener = new Listener();
|
||||
override.addIPOverride("test.com", "1.2.3.4");
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.equal(await listener.firstAddress(), "1.2.3.4");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
|
||||
listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.notEqual(await listener.firstAddress(), "1.2.3.4");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_clearHostOverride() {
|
||||
override.addIPOverride("test.com", "2.2.2.2");
|
||||
override.addIPOverride("example.com", "2.2.2.2");
|
||||
override.clearHostOverride("test.com");
|
||||
let listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.notEqual(await listener.firstAddress(), "2.2.2.2");
|
||||
|
||||
listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"example.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.equal(await listener.firstAddress(), "2.2.2.2");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_multiple_IPs() {
|
||||
override.addIPOverride("test.com", "2.2.2.2");
|
||||
override.addIPOverride("test.com", "1.1.1.1");
|
||||
override.addIPOverride("test.com", "::1");
|
||||
override.addIPOverride("test.com", "fe80::6a99:9b2b:6ccc:6e1b");
|
||||
let listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.deepEqual(await listener.addresses(), [
|
||||
"2.2.2.2",
|
||||
"1.1.1.1",
|
||||
"::1",
|
||||
"fe80::6a99:9b2b:6ccc:6e1b",
|
||||
]);
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_address_family_flags() {
|
||||
override.addIPOverride("test.com", "2.2.2.2");
|
||||
override.addIPOverride("test.com", "1.1.1.1");
|
||||
override.addIPOverride("test.com", "::1");
|
||||
override.addIPOverride("test.com", "fe80::6a99:9b2b:6ccc:6e1b");
|
||||
let listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.deepEqual(await listener.addresses(), [
|
||||
"::1",
|
||||
"fe80::6a99:9b2b:6ccc:6e1b",
|
||||
]);
|
||||
|
||||
listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
Assert.deepEqual(await listener.addresses(), ["2.2.2.2", "1.1.1.1"]);
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
||||
|
||||
add_task(async function test_cname_flag() {
|
||||
override.addIPOverride("test.com", "2.2.2.2");
|
||||
let listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
0,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
let [inRequest, inRecord, inStatus] = await listener;
|
||||
Assert.throws(
|
||||
() => inRecord.canonicalName,
|
||||
/NS_ERROR_NOT_AVAILABLE/,
|
||||
"No canonical name flag"
|
||||
);
|
||||
Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2");
|
||||
|
||||
listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
Ci.nsIDNSService.RESOLVE_CANONICAL_NAME,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
[inRequest, inRecord, inStatus] = await listener;
|
||||
Assert.equal(
|
||||
inRecord.canonicalName,
|
||||
"test.com",
|
||||
"No canonical name specified"
|
||||
);
|
||||
Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
|
||||
override.addIPOverride("test.com", "2.2.2.2");
|
||||
override.setCnameOverride("test.com", "example.com");
|
||||
listener = new Listener();
|
||||
dns.asyncResolve(
|
||||
"test.com",
|
||||
Ci.nsIDNSService.RESOLVE_CANONICAL_NAME,
|
||||
listener,
|
||||
mainThread,
|
||||
defaultOriginAttributes
|
||||
);
|
||||
[inRequest, inRecord, inStatus] = await listener;
|
||||
Assert.equal(
|
||||
inRecord.canonicalName,
|
||||
"example.com",
|
||||
"Must have correct CNAME"
|
||||
);
|
||||
Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2");
|
||||
|
||||
dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
});
|
@ -418,4 +418,3 @@ skip-if = os == "android"
|
||||
[test_obs-fold.js]
|
||||
[test_defaultURI.js]
|
||||
[test_port_remapping.js]
|
||||
[test_dns_override.js]
|
||||
|
Loading…
Reference in New Issue
Block a user