|
17 | 17 | end
|
18 | 18 |
|
19 | 19 | shared_examples "*_PROXY var (testing var)" do
|
20 |
| - subject { HttpConnectionOptions.new("#{proxy_test_scheme}://example.com", {}) } |
21 |
| - it { expect(subject.proxy_from_env).to eq({ :host => "127.0.0.1", :port => 8083, :type => :http }) } |
| 20 | + subject { HttpConnectionOptions.new("#{proxy_test_scheme}://#{request_host}", {}) } |
| 21 | + let(:request_host) { 'example.com' } |
| 22 | + |
| 23 | + it { expect(subject.proxy_from_env(request_host)).to eq({ :host => "127.0.0.1", :port => 8083, :type => :http }) } |
22 | 24 | it { expect(subject.host).to eq "127.0.0.1" }
|
23 | 25 | it { expect(subject.port).to be 8083 }
|
24 | 26 | it do
|
|
201 | 203 | before(:all) do
|
202 | 204 | PROXY_ENV_VARS.each {|k| ENV.delete k }
|
203 | 205 | end
|
204 |
| - |
205 |
| - subject { HttpConnectionOptions.new("http://example.com", {}) } |
206 |
| - it { expect(subject.proxy_from_env).to be_nil } |
207 |
| - it { expect(subject.host).to eq "example.com" } |
| 206 | + let(:request_host) { 'example.com' } |
| 207 | + subject { HttpConnectionOptions.new("http://#{request_host}", {}) } |
| 208 | + it { expect(subject.proxy_from_env(request_host)).to be_nil } |
| 209 | + it { expect(subject.host).to eq request_host } |
208 | 210 | it { expect(subject.port).to be 80 }
|
209 | 211 | it { expect(subject.http_proxy?).to be_falsey }
|
210 | 212 | it { expect(subject.connect_proxy?).to be_falsey }
|
|
264 | 266 |
|
265 | 267 | include_examples "*_PROXY var (testing var)"
|
266 | 268 | end
|
| 269 | + |
| 270 | + context 'with $NO_PROXY env' do |
| 271 | + let(:request_host) { 'ignore.me' } |
| 272 | + let(:no_proxy_hosts) { ['host1', request_host, 'host2'] } |
| 273 | + subject { HttpConnectionOptions.new("http://#{request_host}", {}) } |
| 274 | + |
| 275 | + before(:each) do |
| 276 | + PROXY_ENV_VARS.each { |k| ENV.delete k } |
| 277 | + ENV['ALL_PROXY'] = 'http://127.0.0.1:8083' |
| 278 | + ENV[no_proxy_var_name] = no_proxy_hosts&.join(',') |
| 279 | + end |
| 280 | + |
| 281 | + describe 'when $NO_PROXY includes host from current request' do |
| 282 | + let(:no_proxy_var_name) { 'NO_PROXY' } |
| 283 | + |
| 284 | + it 'should not apply proxy from env' do |
| 285 | + expect(subject.proxy_from_env(request_host)).to be_nil |
| 286 | + end |
| 287 | + end |
| 288 | + |
| 289 | + describe 'when $NO_PROXY does not include host from current request' do |
| 290 | + let(:no_proxy_var_name) { 'NO_PROXY' } |
| 291 | + let(:no_proxy_hosts) { %w[host1 host2] } |
| 292 | + |
| 293 | + it 'should apply proxy from env' do |
| 294 | + expect(subject.proxy_from_env(request_host)).not_to be_nil |
| 295 | + end |
| 296 | + end |
| 297 | + |
| 298 | + describe 'when $no_proxy includes host from current request' do |
| 299 | + let(:no_proxy_var_name) { 'no_proxy' } |
| 300 | + |
| 301 | + it 'should not apply proxy from env' do |
| 302 | + expect(subject.proxy_from_env(request_host)).to be_nil |
| 303 | + end |
| 304 | + end |
| 305 | + |
| 306 | + describe 'when $no_proxy does not include host from current request' do |
| 307 | + let(:no_proxy_var_name) { 'no_proxy' } |
| 308 | + let(:no_proxy_hosts) { %w[host1 host2] } |
| 309 | + |
| 310 | + it 'should apply proxy from env' do |
| 311 | + expect(subject.proxy_from_env(request_host)).not_to be_nil |
| 312 | + end |
| 313 | + end |
| 314 | + |
| 315 | + describe 'when .domain is set in $no_proxy' do |
| 316 | + let(:no_proxy_var_name) { 'no_proxy' } |
| 317 | + let(:no_proxy_hosts) { %w[host1 .me host2] } |
| 318 | + |
| 319 | + it 'should not apply proxy from env' do |
| 320 | + expect(subject.proxy_from_env(request_host)).to be_nil |
| 321 | + end |
| 322 | + end |
| 323 | + end |
267 | 324 | end
|
268 | 325 | end
|
0 commit comments