diff --git a/testing/mozbase/mozprofile/mozprofile/permissions.py b/testing/mozbase/mozprofile/mozprofile/permissions.py index ade71467206..b41433e7177 100644 --- a/testing/mozbase/mozprofile/mozprofile/permissions.py +++ b/testing/mozbase/mozprofile/mozprofile/permissions.py @@ -316,34 +316,40 @@ var uriRegex = new RegExp('^([a-z][-a-z0-9+.]*)' + '(?:[^/@]*@)?' + '(.*?)' + '(?::(\\\\d+))?/'); +var defaultPortsForScheme = { + 'http': 80, + 'ws': 80, + 'https': 443, + 'wss': 443 +}; +var originSchemesRemap = { + 'ws': 'http', + 'wss': 'https' +}; +var proxyForScheme = { + 'http': 'PROXY %(remote)s:%(http)s', + 'https': 'PROXY %(remote)s:%(https)s', + 'ws': 'PROXY %(remote)s:%(ws)s', + 'wss': 'PROXY %(remote)s:%(wss)s' +}; function FindProxyForURL(url, host) { var matches = uriRegex.exec(url); if (!matches) return 'DIRECT'; - var isHttp = matches[1] == 'http'; - var isHttps = matches[1] == 'https'; - var isWebSocket = matches[1] == 'ws'; - var isWebSocketSSL = matches[1] == 'wss'; - if (!matches[3]) - { - if (isHttp | isWebSocket) matches[3] = '80'; - if (isHttps | isWebSocketSSL) matches[3] = '443'; + var originalScheme = matches[1]; + var host = matches[2]; + var port = matches[3]; + if (!port && originalScheme in defaultPortsForScheme) { + port = defaultPortsForScheme[originalScheme]; } - if (isWebSocket) - matches[1] = 'http'; - if (isWebSocketSSL) - matches[1] = 'https'; + var schemeForOriginChecking = originSchemesRemap[originalScheme] || originalScheme; - var origin = matches[1] + '://' + matches[2] + ':' + matches[3]; + var origin = schemeForOriginChecking + '://' + host + ':' + port; if (!(origin in knownOrigins)) return 'DIRECT'; - if (isHttp) return 'PROXY %(remote)s:%(http)s'; - if (isHttps) return 'PROXY %(remote)s:%(https)s'; - if (isWebSocket) return 'PROXY %(remote)s:%(ws)s'; - if (isWebSocketSSL) return 'PROXY %(remote)s:%(wss)s'; - return 'DIRECT'; + return proxyForScheme[originalScheme] || 'DIRECT'; }""" % proxy pacURL = "".join(pacURL.splitlines()) diff --git a/testing/mozbase/mozprofile/tests/permissions.py b/testing/mozbase/mozprofile/tests/permissions.py index 48d391b6536..801570aad69 100755 --- a/testing/mozbase/mozprofile/tests/permissions.py +++ b/testing/mozbase/mozprofile/tests/permissions.py @@ -126,10 +126,10 @@ http://127.0.0.1:8888 privileged origins_decl = "var knownOrigins = (function () { return ['http://mochi.test:8888', 'http://127.0.0.1:80', 'http://127.0.0.1:8888'].reduce" self.assertTrue(origins_decl in user_prefs[1][1]) - proxy_check = ("if (isHttp) return 'PROXY mochi.test:8888';", - "if (isHttps) return 'PROXY mochi.test:4443';", - "if (isWebSocket) return 'PROXY mochi.test:4443';", - "if (isWebSocketSSL) return 'PROXY mochi.test:4443';") + proxy_check = ("'http': 'PROXY mochi.test:8888'", + "'https': 'PROXY mochi.test:4443'", + "'ws': 'PROXY mochi.test:4443'", + "'wss': 'PROXY mochi.test:4443'") self.assertTrue(all(c in user_prefs[1][1] for c in proxy_check)) def verify_user_version(self, version):