Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 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. @@ -61,16 +61,29 @@ class TestProxyCapabilities(MarionetteTe
  5. "socksProxy": proxy_hostname,
  6. "socksVersion": 4,
  7. }}
  8.  
  9. self.marionette.start_session(capabilities)
  10. self.assertEqual(self.marionette.session_capabilities["proxy"],
  11. capabilities["proxy"])
  12.  
  13. + def test_proxy_type_manual_with_authentication(self):
  14. + proxy_hostname = "marionette.test"
  15. + username = "username"
  16. + password = "password"
  17. + capabilities = {"proxy": {
  18. + "proxyType": "manual",
  19. + "ftpProxy": "{}:{}@{}:21".format(username, password, proxy_hostname)
  20. + }}
  21. +
  22. + self.marionette.start_session(capabilities)
  23. + self.assertEqual(self.marionette.session_capabilities["proxy"],
  24. + capabilities["proxy"])
  25. +
  26. def test_proxy_type_manual_socks_requires_version(self):
  27. proxy_port = 4444
  28. proxy_hostname = "marionette.test"
  29. proxy_host = "{}:{}".format(proxy_hostname, proxy_port)
  30. capabilities = {"proxy": {
  31. "proxyType": "manual",
  32. "socksProxy": proxy_host,
  33. }}
  34. diff --git a/testing/marionette/session.js b/testing/marionette/session.js
  35. --- a/testing/marionette/session.js
  36. +++ b/testing/marionette/session.js
  37. @@ -225,23 +225,29 @@ session.Proxy = class {
  38. if (!Number.isInteger(port)) {
  39. if (scheme === "socks") {
  40. port = null;
  41. } else {
  42. port = Services.io.getProtocolHandler(scheme).defaultPort;
  43. }
  44. }
  45.  
  46. - if (url.username != "" ||
  47. - url.password != "" ||
  48. - url.pathname != "/" ||
  49. + if (url.username !== "") {
  50. + let login = Cc["@mozilla.org/login-manager/loginInfo;1"]
  51. + .createInstance(Ci.nsILoginInfo);
  52. + login.init(`${scheme}://${url.hostname}`, null, url.hostname, url.username, url.password, "", "");
  53. + // dump(`Adding login for ${scheme}://${url.hostname}`);
  54. + Services.logins.addLogin(login);
  55. + }
  56. +
  57. + if (url.pathname != "/" ||
  58. url.search != "" ||
  59. url.hash != "") {
  60. throw new InvalidArgumentError(
  61. - `${host} was not of the form host[:port]`);
  62. + `${host} was not of the form [username:password@]host[:port]`);
  63. }
  64.  
  65. return [url.hostname, port];
  66. }
  67.  
  68. let p = new session.Proxy();
  69. if (typeof json == "undefined" || json === null) {
  70. return p;
  71. @@ -293,35 +299,41 @@ session.Proxy = class {
  72. return p;
  73. }
  74.  
  75. /**
  76. * @return {Object.<string, (number|string)>}
  77. * JSON serialisation of proxy object.
  78. */
  79. toJSON() {
  80. - function toHost(hostname, port) {
  81. + function toHost(scheme, hostname, port) {
  82. if (!hostname) {
  83. return null;
  84. }
  85.  
  86. + let logins = Services.logins.findLogins({}, `${scheme}://${hostname}`, "", "", {});
  87. + if (logins.length) {
  88. + let login = logins[0];
  89. + hostname = `${login.username}:${login.password}@${hostname}`;
  90. + }
  91. +
  92. if (port != null) {
  93. return `${hostname}:${port}`;
  94. }
  95.  
  96. return hostname;
  97. }
  98.  
  99. return marshal({
  100. proxyType: this.proxyType,
  101. - ftpProxy: toHost(this.ftpProxy, this.ftpProxyPort),
  102. - httpProxy: toHost(this.httpProxy, this.httpProxyPort),
  103. + ftpProxy: toHost("ftp", this.ftpProxy, this.ftpProxyPort),
  104. + httpProxy: toHost("http", this.httpProxy, this.httpProxyPort),
  105. noProxy: this.noProxy,
  106. - sslProxy: toHost(this.sslProxy, this.sslProxyPort),
  107. - socksProxy: toHost(this.socksProxy, this.socksProxyPort),
  108. + sslProxy: toHost("https", this.sslProxy, this.sslProxyPort),
  109. + socksProxy: toHost("socks", this.socksProxy, this.socksProxyPort),
  110. socksVersion: this.socksVersion,
  111. proxyAutoconfigUrl: this.proxyAutoconfigUrl,
  112. });
  113. }
  114.  
  115. toString() { return "[object session.Proxy]"; }
  116. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement