Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
- --- a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
- +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
- @@ -8,6 +8,8 @@ from marionette_driver import errors
- from marionette_harness import MarionetteTestCase
- +from time import sleep
- +
- class TestProxyCapabilities(MarionetteTestCase):
- @@ -68,6 +70,30 @@ class TestProxyCapabilities(MarionetteTe
- self.assertEqual(self.marionette.session_capabilities["proxy"],
- capabilities["proxy"])
- + def test_proxy_type_manual_with_authentication(self):
- + proxy_hostname = "104.236.137.24"
- + username = "username"
- + password = "password"
- + capabilities = {"proxy": {
- + "proxyType": "manual",
- + "ftpProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
- + "httpProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
- + "sslProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
- + }}
- +
- + self.marionette.start_session(capabilities)
- + self.assertEqual(self.marionette.session_capabilities["proxy"],
- + capabilities["proxy"])
- +
- + url = "https://www.google.com/search?q=my+ip+address"
- + self.marionette.navigate(url)
- + sleep(3)
- + self.marionette.switch_to_alert().accept()
- + sleep(3)
- + self.assertEqual(self.marionette.get_url(), url)
- + self.assertIn("104.236.137.24", self.marionette.page_source)
- +
- +
- def test_proxy_type_manual_socks_requires_version(self):
- proxy_port = 4444
- proxy_hostname = "marionette.test"
- diff --git a/testing/marionette/server.js b/testing/marionette/server.js
- --- a/testing/marionette/server.js
- +++ b/testing/marionette/server.js
- @@ -270,6 +270,13 @@ const RECOMMENDED_PREFS = new Map([
- // Ensure blocklist updates do not hit the network
- ["services.settings.server", "http://%(server)s/dummy/blocklist/"],
- + // Prevent popup for proxy authentication when a login is stored
- + ["signon.autologin.proxy", true],
- + ["network.negotiate-auth.allow-proxies", false],
- + ["network.proxy.share_proxy_settings", false],
- + ["network.automatic-ntlm-auth.allow-proxies", false],
- + ["network.auth.use-sspi", false],
- +
- // Do not automatically fill sign-in forms with known usernames and
- // passwords
- ["signon.autofillForms", false],
- diff --git a/testing/marionette/session.js b/testing/marionette/session.js
- --- a/testing/marionette/session.js
- +++ b/testing/marionette/session.js
- @@ -8,6 +8,9 @@ const {classes: Cc, interfaces: Ci, util
- Cu.importGlobalProperties(["URL"]);
- +Cu.import("resource://gre/modules/Log.jsm");
- +const logger = Log.repository.getLogger("Marionette");
- +
- Cu.import("resource://gre/modules/Preferences.jsm");
- Cu.import("resource://gre/modules/Services.jsm");
- @@ -130,6 +133,21 @@ session.Proxy = class {
- * a no-op.
- */
- init() {
- + function addProxyLogin(login) {
- + if (login) {
- + let logins = Services.logins.findLogins(
- + {}, login.hostname, "", login.httpRealm, {});
- + if (logins.length) {
- + if (login.username != logins[0].username ||
- + login.password != logins[0].password) {
- + // Throw exception here?
- + logger.debug("Cannot add two different logins for the same host");
- + }
- + } else {
- + Services.logins.addLogin(login);
- + }
- + }
- + }
- switch (this.proxyType) {
- case "autodetect":
- Preferences.set("network.proxy.type", 4);
- @@ -147,6 +165,7 @@ session.Proxy = class {
- if (Number.isInteger(this.ftpProxyPort)) {
- Preferences.set("network.proxy.ftp_port", this.ftpProxyPort);
- }
- + addProxyLogin(this.ftpLogin);
- }
- if (this.httpProxy) {
- @@ -154,6 +173,7 @@ session.Proxy = class {
- if (Number.isInteger(this.httpProxyPort)) {
- Preferences.set("network.proxy.http_port", this.httpProxyPort);
- }
- + addProxyLogin(this.httpLogin);
- }
- if (this.sslProxy) {
- @@ -161,6 +181,7 @@ session.Proxy = class {
- if (Number.isInteger(this.sslProxyPort)) {
- Preferences.set("network.proxy.ssl_port", this.sslProxyPort);
- }
- + addProxyLogin(this.sslLogin);
- }
- if (this.socksProxy) {
- @@ -229,8 +250,6 @@ session.Proxy = class {
- throw new InvalidArgumentError(e.message);
- }
- - let hostname = stripBracketsFromIpv6Hostname(url.hostname);
- -
- // If the port hasn't been set, use the default port of
- // the selected scheme (except for socks which doesn't have one).
- let port = parseInt(url.port);
- @@ -242,16 +261,23 @@ session.Proxy = class {
- }
- }
- - if (url.username != "" ||
- - url.password != "" ||
- - url.pathname != "/" ||
- + let login = null;
- + if (url.username !== "") {
- + login = Cc["@mozilla.org/login-manager/loginInfo;1"]
- + .createInstance(Ci.nsILoginInfo);
- + login.init(`moz-proxy://${url.hostname}:${port}`, null, "Squid proxy-caching web server", url.username, url.password, "", "");
- + }
- +
- + let hostname = stripBracketsFromIpv6Hostname(url.hostname);
- +
- + if (url.pathname != "/" ||
- url.search != "" ||
- url.hash != "") {
- throw new InvalidArgumentError(
- - `${host} was not of the form host[:port]`);
- + `${host} was not of the form [username:password@]host[:port]`);
- }
- - return [hostname, port];
- + return [hostname, port, login];
- }
- let p = new session.Proxy();
- @@ -280,13 +306,13 @@ session.Proxy = class {
- case "manual":
- if (typeof json.ftpProxy != "undefined") {
- - [p.ftpProxy, p.ftpProxyPort] = fromHost("ftp", json.ftpProxy);
- + [p.ftpProxy, p.ftpProxyPort, p.ftpLogin] = fromHost("ftp", json.ftpProxy);
- }
- if (typeof json.httpProxy != "undefined") {
- - [p.httpProxy, p.httpProxyPort] = fromHost("http", json.httpProxy);
- + [p.httpProxy, p.httpProxyPort, p.httpLogin] = fromHost("http", json.httpProxy);
- }
- if (typeof json.sslProxy != "undefined") {
- - [p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
- + [p.sslProxy, p.sslProxyPort, p.sslLogin] = fromHost("https", json.sslProxy);
- }
- if (typeof json.socksProxy != "undefined") {
- [p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
- @@ -329,7 +355,12 @@ session.Proxy = class {
- hostname = addBracketsToIpv6Hostname(hostname);
- if (port != null) {
- - return `${hostname}:${port}`;
- + hostname = `${hostname}:${port}`;
- + }
- +
- + let logins = Services.logins.findLogins({}, `moz-proxy://${hostname}`, null, "Squid proxy-caching web server", {});
- + if (logins.length) {
- + hostname = `${logins[0].username}:${logins[0].password}@${hostname}`;
- }
- return hostname;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement