-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ability to use http proxy when making web requests * fix: linting * ignore spellcheck * headers and missing test * update to use master mdspell Co-authored-by: Ryan Loomba <ryan@loomba.io> Co-authored-by: Owais Akbani <owais.akbani92@gmail.com>
- Loading branch information
1 parent
6ea2681
commit 5a18ac0
Showing
11 changed files
with
195 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2020, Optimizely and contributors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# | ||
|
||
module Optimizely | ||
class ProxyConfig | ||
attr_reader :host, :port, :username, :password | ||
|
||
def initialize(host, port = nil, username = nil, password = nil) | ||
# host - DNS name or IP address of proxy | ||
# port - port to use to acess the proxy | ||
# username - username if authorization is required | ||
# password - password if authorization is required | ||
@host = host | ||
@port = port | ||
@username = username | ||
@password = password | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# | ||
# Copyright 2020, Optimizely and contributors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
require 'spec_helper' | ||
require 'optimizely/config/proxy_config' | ||
|
||
describe Optimizely::ProxyConfig do | ||
let(:host) { 'host' } | ||
let(:port) { 1234 } | ||
let(:username) { 'username' } | ||
let(:password) { 'password' } | ||
|
||
describe '#initialize' do | ||
it 'defines getters for host, port, username, and password' do | ||
proxy_config = described_class.new(host, port, username, password) | ||
|
||
expect(proxy_config.host).to eq(host) | ||
expect(proxy_config.port).to eq(port) | ||
expect(proxy_config.username).to eq(username) | ||
expect(proxy_config.password).to eq(password) | ||
end | ||
|
||
it 'sets port, username, and password to nil if they are not passed in' do | ||
proxy_config = described_class.new(host) | ||
expect(proxy_config.port).to eq(nil) | ||
expect(proxy_config.username).to eq(nil) | ||
expect(proxy_config.password).to eq(nil) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2020, Optimizely and contributors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# | ||
require 'spec_helper' | ||
require 'optimizely/config/proxy_config' | ||
|
||
describe Optimizely::Helpers::HttpUtils do | ||
context 'passing in a proxy config' do | ||
let(:url) { 'https://example.com' } | ||
let(:http_method) { :get } | ||
let(:host) { 'host' } | ||
let(:port) { 1234 } | ||
let(:username) { 'username' } | ||
let(:password) { 'password' } | ||
let(:http_class) { double(:http_class) } | ||
let(:http) { double(:http) } | ||
|
||
before do | ||
allow(http_class).to receive(:new).and_return(http) | ||
allow(http).to receive(:use_ssl=) | ||
allow(http).to receive(:request) | ||
end | ||
|
||
context 'with a proxy config that inclues host, port, username, and password' do | ||
let(:proxy_config) { Optimizely::ProxyConfig.new(host, port, username, password) } | ||
it 'with a full proxy config, it proxies the web request' do | ||
expect(Net::HTTP).to receive(:Proxy).with(host, port, username, password).and_return(http_class) | ||
described_class.make_request(url, http_method, nil, nil, nil, proxy_config) | ||
end | ||
end | ||
|
||
context 'with a proxy config that only inclues host' do | ||
let(:proxy_config) { Optimizely::ProxyConfig.new(host) } | ||
it 'with a full proxy config, it proxies the web request' do | ||
expect(Net::HTTP).to receive(:Proxy).with(host, nil, nil, nil).and_return(http_class) | ||
described_class.make_request(url, http_method, nil, nil, nil, proxy_config) | ||
end | ||
end | ||
end | ||
end |