Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../../spec_helper', __dir__)2021module Selenium22module WebDriver23module Remote24module Http25describe Default do26let(:client) do27client = described_class.new28client.server_url = URI.parse('http://example.com')2930client31end3233it 'assigns default timeout to nil' do34http = client.send :http3536expect(http.open_timeout).to eq 6037expect(http.read_timeout).to eq 6038end3940describe '#initialize' do41let(:client) { described_class.new(read_timeout: 22, open_timeout: 23) }4243it 'accepts read timeout options' do44expect(client.open_timeout).to eq 2345end4647it 'accepts open timeout options' do48expect(client.read_timeout).to eq 2249end50end5152it 'uses the specified proxy' do53client.proxy = Proxy.new(http: 'http://foo:[email protected]:8080')54http = client.send :http5556expect(http).to be_proxy57expect(http.proxy_address).to eq('proxy.org')58expect(http.proxy_port).to eq(8080)59expect(http.proxy_user).to eq('foo')60expect(http.proxy_pass).to eq('bar')6162expect(http.address).to eq('example.com')63end6465it 'raises an error if the proxy is not an HTTP proxy' do66client.proxy = Proxy.new(ftp: 'ftp://example.com')67expect { client.send :http }.to raise_error(Error::WebDriverError)68end6970%w[http_proxy HTTP_PROXY].each do |proxy_var|71it "honors the #{proxy_var} environment variable" do72with_env(proxy_var => 'http://proxy.org:8080') do73http = client.send :http7475expect(http).to be_proxy76expect(http.proxy_address).to eq('proxy.org')77expect(http.proxy_port).to eq(8080)78end79end8081it "handles #{proxy_var} without http://" do82with_env(proxy_var => 'proxy.org:8080') do83http = client.send :http8485expect(http).to be_proxy86expect(http.proxy_address).to eq('proxy.org')87expect(http.proxy_port).to eq(8080)88end89end90end9192%w[no_proxy NO_PROXY].each do |no_proxy_var|93it "honors the #{no_proxy_var} environment variable when matching" do94with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'example.com') do95http = client.send :http96expect(http).not_to be_proxy97end98end99100it "ignores the #{no_proxy_var} environment variable when not matching" do101with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'foo.com') do102http = client.send :http103104expect(http).to be_proxy105expect(http.proxy_address).to eq('proxy.org')106expect(http.proxy_port).to eq(8080)107end108end109110it "understands a comma separated list of domains in #{no_proxy_var}" do111with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'example.com,foo.com') do112http = client.send :http113expect(http).not_to be_proxy114end115end116117it "understands subnetting in #{no_proxy_var}" do118with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'localhost,127.0.0.0/8') do119client.server_url = URI.parse('http://127.0.0.1:4444/wd/hub')120121http = client.send :http122expect(http).not_to be_proxy123end124end125end126127it 'raises a sane error if a proxy is refusing connections' do128with_env('http_proxy' => 'http://localhost:1234') do129http = client.send :http130allow(http).to receive(:request).and_raise Errno::ECONNREFUSED.new('Connection refused')131132expect {133client.call :post, 'http://example.com/foo/bar', {}134}.to raise_error(Errno::ECONNREFUSED, %r{using proxy: http://localhost:1234})135end136end137end138end # Http139end # Remote140end # WebDriver141end # Selenium142143144