/* 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 lazy = {};
// Ensure DNS lookups don't hit the server
XPCOMUtils.defineLazyServiceGetter(
lazy, "gDNSOverride", "@mozilla.org/network/native-dns-override;1", "nsINativeDNSResolverOverride"
);
add_task(async function test_uri_with_force_fixup() {
let listener = new Listener();
let { fixedURI } = Services.uriFixup.forceHttpFixup("http://www.example.com");
add_task(async function test_intranet_like_uri() {
let listener = new Listener();
let uri = Services.io.newURI("http://someintranet");
lazy.gDNSOverride.addIPOverride(uri.displayHost, FAKE_IP); // Hosts without periods should end with a period to make them FQN
lazy.gDNSOverride.addIPOverride(uri.displayHost + ".", FAKE_INTRANET_IP);
add_task(async function test_intranet_like_uri_without_fixup() {
let listener = new Listener();
let uri = Services.io.newURI("http://someintranet");
Services.prefs.setBoolPref( "browser.urlbar.dnsResolveFullyQualifiedNames", false
);
lazy.gDNSOverride.addIPOverride(uri.displayHost, FAKE_IP); // Hosts without periods should end with a period to make them FQN
lazy.gDNSOverride.addIPOverride(uri.displayHost + ".", FAKE_INTRANET_IP);
Services.uriFixup.checkHost(uri, listener, ORIGIN_ATTRIBUTE); Assert.deepEqual(
await listener.addresses(),
FAKE_IP, "Should've received non-fixed up IP"
);
add_task(async function test_ip_address() {
let listener = new Listener();
let uri = Services.io.newURI("http://192.168.0.1");
// Testing IP address being passed into the method // requires observing if the asyncResolve method gets called
let didResolve = false;
let topic = "uri-fixup-check-dns";
let observer = {
observe(aSubject, aTopicInner) { if (aTopicInner == topic) {
didResolve = true;
}
},
};
Services.obs.addObserver(observer, topic);
lazy.gDNSOverride.addIPOverride(uri.displayHost, FAKE_IP);
Services.uriFixup.checkHost(uri, listener, ORIGIN_ATTRIBUTE); Assert.equal(
didResolve, false, "Passing an IP address should not conduct a host lookup"
);
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 ist noch experimentell.