Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
  2. --- a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
  3. +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
  4. @@ -8,6 +8,8 @@ from marionette_driver import errors
  5.  
  6. from marionette_harness import MarionetteTestCase
  7.  
  8. +from time import sleep
  9. +
  10.  
  11. class TestProxyCapabilities(MarionetteTestCase):
  12.  
  13. @@ -68,6 +70,30 @@ class TestProxyCapabilities(MarionetteTe
  14. self.assertEqual(self.marionette.session_capabilities["proxy"],
  15. capabilities["proxy"])
  16.  
  17. + def test_proxy_type_manual_with_authentication(self):
  18. + proxy_hostname = "104.236.137.24"
  19. + username = "username"
  20. + password = "password"
  21. + capabilities = {"proxy": {
  22. + "proxyType": "manual",
  23. + "ftpProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
  24. + "httpProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
  25. + "sslProxy": "{}:{}@{}:3128".format(username, password, proxy_hostname),
  26. + }}
  27. +
  28. + self.marionette.start_session(capabilities)
  29. + self.assertEqual(self.marionette.session_capabilities["proxy"],
  30. + capabilities["proxy"])
  31. +
  32. + url = "https://www.google.com/search?q=my+ip+address"
  33. + self.marionette.navigate(url)
  34. + sleep(3)
  35. + self.marionette.switch_to_alert().accept()
  36. + sleep(3)
  37. + self.assertEqual(self.marionette.get_url(), url)
  38. + self.assertIn("104.236.137.24", self.marionette.page_source)
  39. +
  40. +
  41. def test_proxy_type_manual_socks_requires_version(self):
  42. proxy_port = 4444
  43. proxy_hostname = "marionette.test"
  44. diff --git a/testing/marionette/server.js b/testing/marionette/server.js
  45. --- a/testing/marionette/server.js
  46. +++ b/testing/marionette/server.js
  47. @@ -270,6 +270,13 @@ const RECOMMENDED_PREFS = new Map([
  48. // Ensure blocklist updates do not hit the network
  49. ["services.settings.server", "http://%(server)s/dummy/blocklist/"],
  50.  
  51. + // Prevent popup for proxy authentication when a login is stored
  52. + ["signon.autologin.proxy", true],
  53. + ["network.negotiate-auth.allow-proxies", false],
  54. + ["network.proxy.share_proxy_settings", false],
  55. + ["network.automatic-ntlm-auth.allow-proxies", false],
  56. + ["network.auth.use-sspi", false],
  57. +
  58. // Do not automatically fill sign-in forms with known usernames and
  59. // passwords
  60. ["signon.autofillForms", false],
  61. diff --git a/testing/marionette/session.js b/testing/marionette/session.js
  62. --- a/testing/marionette/session.js
  63. +++ b/testing/marionette/session.js
  64. @@ -8,6 +8,9 @@ const {classes: Cc, interfaces: Ci, util
  65.  
  66. Cu.importGlobalProperties(["URL"]);
  67.  
  68. +Cu.import("resource://gre/modules/Log.jsm");
  69. +const logger = Log.repository.getLogger("Marionette");
  70. +
  71. Cu.import("resource://gre/modules/Preferences.jsm");
  72. Cu.import("resource://gre/modules/Services.jsm");
  73.  
  74. @@ -130,6 +133,21 @@ session.Proxy = class {
  75. * a no-op.
  76. */
  77. init() {
  78. + function addProxyLogin(login) {
  79. + if (login) {
  80. + let logins = Services.logins.findLogins(
  81. + {}, login.hostname, "", login.httpRealm, {});
  82. + if (logins.length) {
  83. + if (login.username != logins[0].username ||
  84. + login.password != logins[0].password) {
  85. + // Throw exception here?
  86. + logger.debug("Cannot add two different logins for the same host");
  87. + }
  88. + } else {
  89. + Services.logins.addLogin(login);
  90. + }
  91. + }
  92. + }
  93. switch (this.proxyType) {
  94. case "autodetect":
  95. Preferences.set("network.proxy.type", 4);
  96. @@ -147,6 +165,7 @@ session.Proxy = class {
  97. if (Number.isInteger(this.ftpProxyPort)) {
  98. Preferences.set("network.proxy.ftp_port", this.ftpProxyPort);
  99. }
  100. + addProxyLogin(this.ftpLogin);
  101. }
  102.  
  103. if (this.httpProxy) {
  104. @@ -154,6 +173,7 @@ session.Proxy = class {
  105. if (Number.isInteger(this.httpProxyPort)) {
  106. Preferences.set("network.proxy.http_port", this.httpProxyPort);
  107. }
  108. + addProxyLogin(this.httpLogin);
  109. }
  110.  
  111. if (this.sslProxy) {
  112. @@ -161,6 +181,7 @@ session.Proxy = class {
  113. if (Number.isInteger(this.sslProxyPort)) {
  114. Preferences.set("network.proxy.ssl_port", this.sslProxyPort);
  115. }
  116. + addProxyLogin(this.sslLogin);
  117. }
  118.  
  119. if (this.socksProxy) {
  120. @@ -229,8 +250,6 @@ session.Proxy = class {
  121. throw new InvalidArgumentError(e.message);
  122. }
  123.  
  124. - let hostname = stripBracketsFromIpv6Hostname(url.hostname);
  125. -
  126. // If the port hasn't been set, use the default port of
  127. // the selected scheme (except for socks which doesn't have one).
  128. let port = parseInt(url.port);
  129. @@ -242,16 +261,23 @@ session.Proxy = class {
  130. }
  131. }
  132.  
  133. - if (url.username != "" ||
  134. - url.password != "" ||
  135. - url.pathname != "/" ||
  136. + let login = null;
  137. + if (url.username !== "") {
  138. + login = Cc["@mozilla.org/login-manager/loginInfo;1"]
  139. + .createInstance(Ci.nsILoginInfo);
  140. + login.init(`moz-proxy://${url.hostname}:${port}`, null, "Squid proxy-caching web server", url.username, url.password, "", "");
  141. + }
  142. +
  143. + let hostname = stripBracketsFromIpv6Hostname(url.hostname);
  144. +
  145. + if (url.pathname != "/" ||
  146. url.search != "" ||
  147. url.hash != "") {
  148. throw new InvalidArgumentError(
  149. - `${host} was not of the form host[:port]`);
  150. + `${host} was not of the form [username:password@]host[:port]`);
  151. }
  152.  
  153. - return [hostname, port];
  154. + return [hostname, port, login];
  155. }
  156.  
  157. let p = new session.Proxy();
  158. @@ -280,13 +306,13 @@ session.Proxy = class {
  159.  
  160. case "manual":
  161. if (typeof json.ftpProxy != "undefined") {
  162. - [p.ftpProxy, p.ftpProxyPort] = fromHost("ftp", json.ftpProxy);
  163. + [p.ftpProxy, p.ftpProxyPort, p.ftpLogin] = fromHost("ftp", json.ftpProxy);
  164. }
  165. if (typeof json.httpProxy != "undefined") {
  166. - [p.httpProxy, p.httpProxyPort] = fromHost("http", json.httpProxy);
  167. + [p.httpProxy, p.httpProxyPort, p.httpLogin] = fromHost("http", json.httpProxy);
  168. }
  169. if (typeof json.sslProxy != "undefined") {
  170. - [p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
  171. + [p.sslProxy, p.sslProxyPort, p.sslLogin] = fromHost("https", json.sslProxy);
  172. }
  173. if (typeof json.socksProxy != "undefined") {
  174. [p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
  175. @@ -329,7 +355,12 @@ session.Proxy = class {
  176. hostname = addBracketsToIpv6Hostname(hostname);
  177.  
  178. if (port != null) {
  179. - return `${hostname}:${port}`;
  180. + hostname = `${hostname}:${port}`;
  181. + }
  182. +
  183. + let logins = Services.logins.findLogins({}, `moz-proxy://${hostname}`, null, "Squid proxy-caching web server", {});
  184. + if (logins.length) {
  185. + hostname = `${logins[0].username}:${logins[0].password}@${hostname}`;
  186. }
  187.  
  188. return hostname;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement