-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): set http options globally
New feature allows users to configure their HTTP options with classic environment variables (e.g. http_proxy, https_proxy, no_proxy). Additionally, allows users to ignore SSL verification if uploading certificates for every use case is not practical. - Fixes #191 - Fixes #192
- Loading branch information
Showing
6 changed files
with
93 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.3.4 | ||
2.4.0 |
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,32 @@ | ||
require 'pact_broker/services' | ||
|
||
module PactBroker | ||
class BuildHttpOptions | ||
extend PactBroker::Services | ||
|
||
def self.call uri | ||
uri = URI(uri) | ||
options = {} | ||
|
||
if uri.scheme == 'https' | ||
options[:use_ssl] = true | ||
options[:cert_store] = cert_store | ||
if disable_ssl_verification? | ||
options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE | ||
else | ||
options[:verify_mode] = OpenSSL::SSL::VERIFY_PEER | ||
end | ||
end | ||
options | ||
end | ||
|
||
def self.disable_ssl_verification? | ||
PactBroker.configuration.disable_ssl_verification | ||
end | ||
|
||
def self.cert_store | ||
certificate_service.cert_store | ||
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,47 @@ | ||
require 'spec_helper' | ||
require 'pact_broker/build_http_options' | ||
|
||
module PactBroker | ||
describe BuildHttpOptions do | ||
|
||
subject { PactBroker::BuildHttpOptions.call(url) } | ||
|
||
context "default http options" do | ||
before do | ||
PactBroker.configuration.disable_ssl_verification = false | ||
end | ||
|
||
describe "when given an insecure URL" do | ||
let(:url) { 'http://example.org/insecure' } | ||
|
||
it "should provide an empty configuration object" do | ||
expect(subject).to eq({}) | ||
end | ||
|
||
end | ||
|
||
describe "when given a secure URL" do | ||
let(:url) { 'https://example.org/secure' } | ||
|
||
it "should validate the full certificate chain" do | ||
expect(subject).to include({:use_ssl => true, :verify_mode => 1}) | ||
end | ||
|
||
end | ||
end | ||
|
||
context "disable_ssl_verification is set to true" do | ||
before do | ||
PactBroker.configuration.disable_ssl_verification = true | ||
end | ||
|
||
let(:url) { 'https://example.org/secure' } | ||
|
||
describe "when given a secure URL" do | ||
it "should not validate certificates" do | ||
expect(subject).to include({:use_ssl => true, :verify_mode => 0}) | ||
end | ||
end | ||
end | ||
end | ||
end |