diff --git a/lib/pact_broker/configuration.rb b/lib/pact_broker/configuration.rb index 8777957fa..a9fa828ad 100644 --- a/lib/pact_broker/configuration.rb +++ b/lib/pact_broker/configuration.rb @@ -1,3 +1,4 @@ +require 'pact_broker/version' require 'pact_broker/error' require 'pact_broker/config/space_delimited_string_list' require 'semantic_logger' @@ -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 @@ -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"] diff --git a/lib/pact_broker/domain/webhook_request.rb b/lib/pact_broker/domain/webhook_request.rb index b914757e0..b0f660a92 100644 --- a/lib/pact_broker/domain/webhook_request.rb +++ b/lib/pact_broker/domain/webhook_request.rb @@ -9,6 +9,7 @@ require 'delegate' require 'rack/utils' require 'pact_broker/webhooks/webhook_request_logger' +require 'pact_broker/configuration' module PactBroker module Domain @@ -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? diff --git a/spec/lib/pact_broker/domain/webhook_request_spec.rb b/spec/lib/pact_broker/domain/webhook_request_spec.rb index c28dbfb5d..dfaf3a437 100644 --- a/spec/lib/pact_broker/domain/webhook_request_spec.rb +++ b/spec/lib/pact_broker/domain/webhook_request_spec.rb @@ -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