Path: blob/trunk/py/test/selenium/webdriver/common/proxy_tests.py
1865 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.webdriver.common.options import ArgOptions20from selenium.webdriver.common.proxy import Proxy, ProxyType2122MANUAL_PROXY = {23"httpProxy": "some.url:1234",24# TODO: Remove ftpProxy in future (currently deprecated)25# https://github.com/SeleniumHQ/selenium/issues/1590526"ftpProxy": "ftp.proxy",27"noProxy": "localhost, foo.localhost",28"sslProxy": "ssl.proxy:1234",29"socksProxy": "socks.proxy:65555",30"socksUsername": "test",31"socksPassword": "test",32"socksVersion": 5,33}3435PAC_PROXY = {36"proxyAutoconfigUrl": "http://pac.url:1234",37}3839AUTODETECT_PROXY = {40"autodetect": True,41}424344def test_can_add_manual_proxy_to_options():45proxy = Proxy()46proxy.http_proxy = MANUAL_PROXY["httpProxy"]47# TODO: Remove ftpProxy in future (currently deprecated)48# https://github.com/SeleniumHQ/selenium/issues/1590549proxy.ftp_proxy = MANUAL_PROXY["ftpProxy"]50proxy.no_proxy = MANUAL_PROXY["noProxy"]51proxy.sslProxy = MANUAL_PROXY["sslProxy"]52proxy.socksProxy = MANUAL_PROXY["socksProxy"]53proxy.socksUsername = MANUAL_PROXY["socksUsername"]54proxy.socksPassword = MANUAL_PROXY["socksPassword"]55proxy.socksVersion = MANUAL_PROXY["socksVersion"]5657options = ArgOptions()58options.proxy = proxy5960proxy_capabilities = MANUAL_PROXY.copy()61proxy_capabilities["proxyType"] = "manual"62assert proxy_capabilities == options.to_capabilities().get("proxy")636465def test_can_add_autodetect_proxy_to_options():66proxy = Proxy()67proxy.auto_detect = AUTODETECT_PROXY["autodetect"]6869options = ArgOptions()70options.proxy = proxy7172proxy_capabilities = AUTODETECT_PROXY.copy()73proxy_capabilities["proxyType"] = "autodetect"74assert proxy_capabilities == options.to_capabilities().get("proxy")757677def test_can_add_pacproxy_to_options():78proxy = Proxy()79proxy.proxy_autoconfig_url = PAC_PROXY["proxyAutoconfigUrl"]8081options = ArgOptions()82options.proxy = proxy8384proxy_capabilities = PAC_PROXY.copy()85proxy_capabilities["proxyType"] = "pac"86assert proxy_capabilities == options.to_capabilities().get("proxy")878889def test_can_not_change_initialized_proxy_type():90proxy = Proxy(raw={"proxyType": "direct"})91with pytest.raises(Exception):92proxy.proxy_type = ProxyType.SYSTEM9394proxy = Proxy(raw={"proxyType": ProxyType.DIRECT})95with pytest.raises(Exception):96proxy.proxy_type = ProxyType.SYSTEM979899def test_can_init_manual_proxy():100proxy = Proxy(raw=MANUAL_PROXY)101102assert ProxyType.MANUAL == proxy.proxy_type103assert MANUAL_PROXY["httpProxy"] == proxy.http_proxy104# TODO: Remove ftpProxy in future (currently deprecated)105# https://github.com/SeleniumHQ/selenium/issues/15905106assert MANUAL_PROXY["ftpProxy"] == proxy.ftp_proxy107assert MANUAL_PROXY["noProxy"] == proxy.no_proxy108assert MANUAL_PROXY["sslProxy"] == proxy.sslProxy109assert MANUAL_PROXY["socksProxy"] == proxy.socksProxy110assert MANUAL_PROXY["socksUsername"] == proxy.socksUsername111assert MANUAL_PROXY["socksPassword"] == proxy.socksPassword112assert MANUAL_PROXY["socksVersion"] == proxy.socksVersion113114115def test_can_init_autodetect_proxy():116proxy = Proxy(raw=AUTODETECT_PROXY)117assert ProxyType.AUTODETECT == proxy.proxy_type118assert AUTODETECT_PROXY["autodetect"] == proxy.auto_detect119120121def test_can_init_pacproxy():122proxy = Proxy(raw=PAC_PROXY)123assert ProxyType.PAC == proxy.proxy_type124assert PAC_PROXY["proxyAutoconfigUrl"] == proxy.proxy_autoconfig_url125126127def test_can_init_empty_proxy():128proxy = Proxy()129assert ProxyType.UNSPECIFIED == proxy.proxy_type130assert "" == proxy.http_proxy131# TODO: Remove ftpProxy in future (currently deprecated)132# https://github.com/SeleniumHQ/selenium/issues/15905133assert "" == proxy.ftp_proxy134assert "" == proxy.no_proxy135assert "" == proxy.sslProxy136assert "" == proxy.socksProxy137assert "" == proxy.socksUsername138assert "" == proxy.socksPassword139assert proxy.auto_detect is False140assert "" == proxy.proxy_autoconfig_url141assert proxy.socks_version is None142143options = ArgOptions()144options.proxy = proxy145146proxy_capabilities = {}147proxy_capabilities["proxyType"] = "unspecified"148assert proxy_capabilities == options.to_capabilities().get("proxy")149150151