def test_sauceconnect_tunnel_domains(): with mock.patch.object(sauce.SauceConnect, "upload_prerun_exec"),\ mock.patch.object(sauce.subprocess, "Popen") as Popen,\ mock.patch.object(sauce.os.path, "exists") as exists: Popen.return_value.poll.return_value = None Popen.return_value.returncode = None exists.return_value = True sauce_connect = sauce.SauceConnect(sauce_user="******", sauce_key="bbb", sauce_tunnel_id="ccc", sauce_connect_binary="ddd", sauce_connect_args=[]) with ConfigBuilder(browser_host="example.net", alternate_hosts={"alt": "example.org"}, subdomains={"a", "b"}, not_subdomains={"x", "y"}) as env_config: sauce_connect(None, env_config) with sauce_connect: Popen.assert_called_once() args, kwargs = Popen.call_args cmd = args[0] assert "--tunnel-domains" in cmd i = cmd.index("--tunnel-domains") rest = cmd[i + 1:] assert len(rest) >= 1 if len(rest) > 1: assert rest[1].startswith( "-" ), "--tunnel-domains takes a comma separated list (not a space separated list)" assert set(rest[0].split(",")) == { 'example.net', 'a.example.net', 'b.example.net', 'example.org', 'a.example.org', 'b.example.org' }
def test_sauceconnect_cleanup(): """Ensure that execution pauses when the process is closed while exiting the context manager. This allow Sauce Connect to close any active tunnels.""" with mock.patch.object(sauce.SauceConnect, "upload_prerun_exec"),\ mock.patch.object(sauce.subprocess, "Popen") as Popen,\ mock.patch.object(sauce.os.path, "exists") as exists,\ mock.patch.object(sauce.time, "sleep") as sleep: Popen.return_value.poll.return_value = True Popen.return_value.returncode = None exists.return_value = True sauce_connect = sauce.SauceConnect(sauce_user="******", sauce_key="bbb", sauce_tunnel_id="ccc", sauce_connect_binary="ddd", sauce_connect_args=[]) with ConfigBuilder(logger, browser_host="example.net") as env_config: sauce_connect(None, env_config) with sauce_connect: Popen.return_value.poll.return_value = None sleep.assert_not_called() sleep.assert_called()
def test_sauceconnect_failure_never_ready(): with mock.patch.object(sauce.SauceConnect, "upload_prerun_exec"),\ mock.patch.object(sauce.subprocess, "Popen") as Popen,\ mock.patch.object(sauce.os.path, "exists") as exists,\ mock.patch.object(sauce.time, "sleep") as sleep: Popen.return_value.poll.return_value = None Popen.return_value.returncode = None exists.return_value = False sauce_connect = sauce.SauceConnect(sauce_user="******", sauce_key="bbb", sauce_tunnel_id="ccc", sauce_connect_binary="ddd", sauce_connect_args=[]) with ConfigBuilder(logger, browser_host="example.net") as env_config: sauce_connect(None, env_config) with pytest.raises(sauce.SauceException): with sauce_connect: pass # We should sleep while waiting for it to create the readyfile sleep.assert_called() # Check we actually kill it after termination fails Popen.return_value.terminate.assert_called() Popen.return_value.kill.assert_called()
def test_webkitgtk_certificate_domain_list(product): def domain_is_inside_certificate_list_cert(domain_to_find, webkitgtk_certificate_list, cert_file): for domain in webkitgtk_certificate_list: if domain["host"] == domain_to_find and domain[ "certificateFile"] == cert_file: return True return False if product not in ["epiphany", "webkit", "webkitgtk_minibrowser"]: pytest.skip("%s doesn't support certificate_domain_list" % product) (check_args, target_browser_cls, get_browser_kwargs, executor_classes, get_executor_kwargs, env_options, get_env_extras, run_info_extras) = products.load_product({}, product) cert_file = "/home/user/wpt/tools/certs/cacert.pem" valid_domains_test = [ "a.example.org", "b.example.org", "example.org", "a.example.net", "b.example.net", "example.net" ] invalid_domains_test = [ "x.example.org", "y.example.org", "example.it", "x.example.net", "y.example.net", "z.example.net" ] kwargs = {} kwargs["timeout_multiplier"] = 1 kwargs["debug_info"] = None kwargs["host_cert_path"] = cert_file kwargs["webkit_port"] = "gtk" kwargs["binary"] = None kwargs["webdriver_binary"] = None kwargs["pause_after_test"] = False kwargs["pause_on_unexpected"] = False kwargs["debug_test"] = False with ConfigBuilder(browser_host="example.net", alternate_hosts={"alt": "example.org"}, subdomains={"a", "b"}, not_subdomains={"x", "y"}) as env_config: executor_args = get_executor_kwargs(None, None, env_config, None, None, **kwargs) assert ('capabilities' in executor_args) assert ('webkitgtk:browserOptions' in executor_args['capabilities']) assert ('certificates' in executor_args['capabilities']['webkitgtk:browserOptions']) cert_list = executor_args['capabilities']['webkitgtk:browserOptions'][ 'certificates'] for valid_domain in valid_domains_test: assert (domain_is_inside_certificate_list_cert( valid_domain, cert_list, cert_file)) assert (not domain_is_inside_certificate_list_cert( valid_domain, cert_list, cert_file + ".backup_non_existent")) for invalid_domain in invalid_domains_test: assert (not domain_is_inside_certificate_list_cert( invalid_domain, cert_list, cert_file)) assert (not domain_is_inside_certificate_list_cert( invalid_domain, cert_list, cert_file + ".backup_non_existent"))
def test_webkitgtk_certificate_domain_list(product): def domain_is_inside_certificate_list_cert(domain_to_find, webkitgtk_certificate_list, cert_file): for domain in webkitgtk_certificate_list: if domain["host"] == domain_to_find and domain["certificateFile"] == cert_file: return True return False if product not in ["epiphany", "webkit", "webkitgtk_minibrowser"]: pytest.skip("%s doesn't support certificate_domain_list" % product) product_data = products.Product({}, product) cert_file = "/home/user/wpt/tools/certs/cacert.pem" valid_domains_test = ["a.example.org", "b.example.org", "example.org", "a.example.net", "b.example.net", "example.net"] invalid_domains_test = ["x.example.org", "y.example.org", "example.it", "x.example.net", "y.example.net", "z.example.net"] kwargs = {} kwargs["timeout_multiplier"] = 1 kwargs["debug_info"] = None kwargs["host_cert_path"] = cert_file kwargs["webkit_port"] = "gtk" kwargs["binary"] = None kwargs["webdriver_binary"] = None kwargs["pause_after_test"] = False kwargs["pause_on_unexpected"] = False kwargs["debug_test"] = False with ConfigBuilder(logger, browser_host="example.net", alternate_hosts={"alt": "example.org"}, subdomains={"a", "b"}, not_subdomains={"x", "y"}) as env_config: # We don't want to actually create a test environment; the get_executor_kwargs # function only really wants an object with the config key class MockEnvironment: def __init__(self, config): self.config = config executor_args = product_data.get_executor_kwargs(None, None, MockEnvironment(env_config), {}, **kwargs) assert('capabilities' in executor_args) assert('webkitgtk:browserOptions' in executor_args['capabilities']) assert('certificates' in executor_args['capabilities']['webkitgtk:browserOptions']) cert_list = executor_args['capabilities']['webkitgtk:browserOptions']['certificates'] for valid_domain in valid_domains_test: assert(domain_is_inside_certificate_list_cert(valid_domain, cert_list, cert_file)) assert(not domain_is_inside_certificate_list_cert(valid_domain, cert_list, cert_file + ".backup_non_existent")) for invalid_domain in invalid_domains_test: assert(not domain_is_inside_certificate_list_cert(invalid_domain, cert_list, cert_file)) assert(not domain_is_inside_certificate_list_cert(invalid_domain, cert_list, cert_file + ".backup_non_existent"))
def test_sauceconnect_success(): with mock.patch.object(sauce.SauceConnect, "upload_prerun_exec"),\ mock.patch.object(sauce.subprocess, "Popen") as Popen,\ mock.patch.object(sauce.os.path, "exists") as exists: # Act as if it's still running Popen.return_value.poll.return_value = None Popen.return_value.returncode = None # Act as if file created exists.return_value = True sauce_connect = sauce.SauceConnect(sauce_user="******", sauce_key="bbb", sauce_tunnel_id="ccc", sauce_connect_binary="ddd") with ConfigBuilder(browser_host="example.net") as env_config: sauce_connect(None, env_config) with sauce_connect: pass
def test_sauceconnect_failure_exit(readyfile, returncode): with mock.patch.object(sauce.SauceConnect, "upload_prerun_exec"),\ mock.patch.object(sauce.subprocess, "Popen") as Popen,\ mock.patch.object(sauce.os.path, "exists") as exists,\ mock.patch.object(sauce.time, "sleep") as sleep: Popen.return_value.poll.return_value = returncode Popen.return_value.returncode = returncode exists.return_value = readyfile sauce_connect = sauce.SauceConnect(sauce_user="******", sauce_key="bbb", sauce_tunnel_id="ccc", sauce_connect_binary="ddd") with ConfigBuilder(browser_host="example.net") as env_config: sauce_connect(None, env_config) with pytest.raises(sauce.SauceException): with sauce_connect: pass # Given we appear to exit immediately with these mocks, sleep shouldn't be called sleep.assert_not_called()