Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb
1990 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Remote
25
module Http
26
describe Default do
27
let(:client) do
28
client = described_class.new
29
client.server_url = URI.parse('http://example.com')
30
31
client
32
end
33
34
it 'assigns default timeout to nil' do
35
http = client.send :http
36
37
expect(http.open_timeout).to eq 60
38
expect(http.read_timeout).to eq 60
39
end
40
41
describe '#initialize' do
42
let(:client) { described_class.new(read_timeout: 22, open_timeout: 23) }
43
44
it 'accepts read timeout options' do
45
expect(client.open_timeout).to eq 23
46
end
47
48
it 'accepts open timeout options' do
49
expect(client.read_timeout).to eq 22
50
end
51
end
52
53
it 'uses the specified proxy' do
54
client.proxy = Proxy.new(http: 'http://foo:[email protected]:8080')
55
http = client.send :http
56
57
expect(http).to be_proxy
58
expect(http.proxy_address).to eq('proxy.org')
59
expect(http.proxy_port).to eq(8080)
60
expect(http.proxy_user).to eq('foo')
61
expect(http.proxy_pass).to eq('bar')
62
63
expect(http.address).to eq('example.com')
64
end
65
66
it 'raises an error if the proxy is not an HTTP proxy' do
67
client.proxy = Proxy.new(ftp: 'ftp://example.com')
68
expect { client.send :http }.to raise_error(Error::WebDriverError)
69
end
70
71
%w[http_proxy HTTP_PROXY].each do |proxy_var|
72
it "honors the #{proxy_var} environment variable" do
73
with_env(proxy_var => 'http://proxy.org:8080') do
74
http = client.send :http
75
76
expect(http).to be_proxy
77
expect(http.proxy_address).to eq('proxy.org')
78
expect(http.proxy_port).to eq(8080)
79
end
80
end
81
82
it "handles #{proxy_var} without http://" do
83
with_env(proxy_var => 'proxy.org:8080') do
84
http = client.send :http
85
86
expect(http).to be_proxy
87
expect(http.proxy_address).to eq('proxy.org')
88
expect(http.proxy_port).to eq(8080)
89
end
90
end
91
end
92
93
%w[no_proxy NO_PROXY].each do |no_proxy_var|
94
it "honors the #{no_proxy_var} environment variable when matching" do
95
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'example.com') do
96
http = client.send :http
97
expect(http).not_to be_proxy
98
end
99
end
100
101
it "ignores the #{no_proxy_var} environment variable when not matching" do
102
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'foo.com') do
103
http = client.send :http
104
105
expect(http).to be_proxy
106
expect(http.proxy_address).to eq('proxy.org')
107
expect(http.proxy_port).to eq(8080)
108
end
109
end
110
111
it "understands a comma separated list of domains in #{no_proxy_var}" do
112
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'example.com,foo.com') do
113
http = client.send :http
114
expect(http).not_to be_proxy
115
end
116
end
117
118
it "understands subnetting in #{no_proxy_var}" do
119
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'localhost,127.0.0.0/8') do
120
client.server_url = URI.parse('http://127.0.0.1:4444/wd/hub')
121
122
http = client.send :http
123
expect(http).not_to be_proxy
124
end
125
end
126
end
127
128
it 'raises a sane error if a proxy is refusing connections' do
129
with_env('http_proxy' => 'http://localhost:1234') do
130
http = client.send :http
131
allow(http).to receive(:request).and_raise Errno::ECONNREFUSED.new('Connection refused')
132
133
expect {
134
client.call :post, 'http://example.com/foo/bar', {}
135
}.to raise_error(Errno::ECONNREFUSED, %r{using proxy: http://localhost:1234})
136
end
137
end
138
end
139
end # Http
140
end # Remote
141
end # WebDriver
142
end # Selenium
143
144