Skip to content

Commit

Permalink
fix: set default User-Agent header in webhook requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 24, 2020
1 parent cfd4c1f commit caa71f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/pact_broker/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'pact_broker/version'
require 'pact_broker/error'
require 'pact_broker/config/space_delimited_string_list'
require 'semantic_logger'
Expand Down Expand Up @@ -46,6 +47,7 @@ class Configuration
attr_accessor :warning_error_class_names
attr_accessor :check_for_potential_duplicate_pacticipant_names
attr_accessor :webhook_retry_schedule
attr_accessor :user_agent
attr_reader :webhook_http_method_whitelist, :webhook_scheme_whitelist, :webhook_host_whitelist
attr_accessor :semver_formats
attr_accessor :enable_public_badge_access, :shields_io_base_url, :badge_provider_mode
Expand Down Expand Up @@ -93,6 +95,7 @@ def self.default_configuration
require 'pact_broker/db/seed_example_data'
PactBroker::DB::SeedExampleData.call
end
config.user_agent = "Pact Broker v#{PactBroker::VERSION}"
config.base_equality_only_on_content_that_affects_verification_results = true
config.order_versions_by_date = true
config.semver_formats = ["%M.%m.%p%s%d", "%M.%m", "%M"]
Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/domain/webhook_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'delegate'
require 'rack/utils'
require 'pact_broker/webhooks/webhook_request_logger'
require 'pact_broker/configuration'

module PactBroker
module Domain
Expand Down Expand Up @@ -61,7 +62,7 @@ def http_request
@http_request ||= begin
req = Net::HTTP.const_get(method.capitalize).new(uri.request_uri)
req.delete("accept-encoding")
req.delete("user-agent")
req["user-agent"] = PactBroker.configuration.user_agent
headers.each_pair { | name, value | req[name] = value }
req.basic_auth(username, password) if username && username.size > 0
req.body = body unless body.nil?
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/domain/webhook_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Domain
describe "execute" do
let!(:http_request) do
stub_request(:post, "http://example.org/hook").
with(:headers => {'Content-Type'=>'text/plain'}, :body => request_body).
with(:headers => {'Content-Type'=>'text/plain', 'User-Agent' => /Pact Broker/}, :body => request_body).
to_return(:status => status, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
end

Expand Down

0 comments on commit caa71f9

Please sign in to comment.