|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Copyright 2020, Optimizely and contributors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# |
| 18 | +require 'spec_helper' |
| 19 | +require 'optimizely/config/proxy_config' |
| 20 | + |
| 21 | +describe Optimizely::Helpers::HttpUtils do |
| 22 | + context 'passing in a proxy config' do |
| 23 | + let(:url) { 'https://example.com' } |
| 24 | + let(:http_method) { :get } |
| 25 | + let(:host) { 'host' } |
| 26 | + let(:port) { 1234 } |
| 27 | + let(:username) { 'username' } |
| 28 | + let(:password) { 'password' } |
| 29 | + let(:http_class) { double(:http_class) } |
| 30 | + let(:http) { double(:http) } |
| 31 | + |
| 32 | + before do |
| 33 | + allow(http_class).to receive(:new).and_return(http) |
| 34 | + allow(http).to receive(:use_ssl=) |
| 35 | + allow(http).to receive(:request) |
| 36 | + end |
| 37 | + |
| 38 | + context 'with a proxy config that inclues host, port, username, and password' do |
| 39 | + let(:proxy_config) { Optimizely::ProxyConfig.new(host, port, username, password) } |
| 40 | + it 'with a full proxy config, it proxies the web request' do |
| 41 | + expect(Net::HTTP).to receive(:Proxy).with(host, port, username, password).and_return(http_class) |
| 42 | + described_class.make_request(url, http_method, nil, nil, nil, proxy_config) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'with a proxy config that only inclues host' do |
| 47 | + let(:proxy_config) { Optimizely::ProxyConfig.new(host) } |
| 48 | + it 'with a full proxy config, it proxies the web request' do |
| 49 | + expect(Net::HTTP).to receive(:Proxy).with(host, nil, nil, nil).and_return(http_class) |
| 50 | + described_class.make_request(url, http_method, nil, nil, nil, proxy_config) |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | +end |
0 commit comments