From 5363ab2e84fac436954c9c29e935491a99fa69dd Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 24 Apr 2020 11:15:43 +1000 Subject: [PATCH] fix: include the base URL in the link to the webhook docs --- .../webhook_execution_result_decorator.rb | 7 ++++++- lib/pact_broker/locale/en.yml | 2 +- .../webhooks/webhook_request_logger.rb | 16 ++++++++-------- .../webhooks/webhook_request_logger_spec.rb | 5 ++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb b/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb index 47aba5a2e..76372f67a 100644 --- a/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb @@ -78,8 +78,13 @@ def body } end + def to_hash(options) + @to_hash_options = options + super + end + def response_hidden_message - PactBroker::Messages.message('messages.response_body_hidden') + PactBroker::Messages.message('messages.response_body_hidden', base_url: @to_hash_options[:user_options][:base_url]) end end end diff --git a/lib/pact_broker/locale/en.yml b/lib/pact_broker/locale/en.yml index 8e9790bdd..1c8f31a21 100644 --- a/lib/pact_broker/locale/en.yml +++ b/lib/pact_broker/locale/en.yml @@ -12,7 +12,7 @@ en: pact_broker: messages: - response_body_hidden: For security purposes, the response details are not logged. To enable response logging, configure the webhook_host_whitelist property. See /doc/webhooks#whitelist for more information. + response_body_hidden: For security purposes, the response details are not logged. To enable response logging, configure the webhook_host_whitelist property. See %{base_url}/doc/webhooks#whitelist for more information. matrix: pre_verified: This pact was "pre-verified" as it has identical content to a previously verified pact. webhooks: diff --git a/lib/pact_broker/webhooks/webhook_request_logger.rb b/lib/pact_broker/webhooks/webhook_request_logger.rb index 8175bdd0a..319c4d0a0 100644 --- a/lib/pact_broker/webhooks/webhook_request_logger.rb +++ b/lib/pact_broker/webhooks/webhook_request_logger.rb @@ -33,8 +33,8 @@ def log(uuid, webhook_request, http_response, error, webhook_context) safe_response = http_response ? HttpResponseWithUtf8SafeBody.new(http_response) : nil log_webhook_context(webhook_context) log_request(webhook_request) - log_response(uuid, safe_response) if safe_response - log_error(uuid, error) if error + log_response(uuid, safe_response, webhook_context[:base_url]) if safe_response + log_error(uuid, error, webhook_context[:base_url]) if error log_completion_message(success?(safe_response)) log_stream.string end @@ -61,17 +61,17 @@ def log_request(webhook_request) execution_logger.info(webhook_request.body) if webhook_request.body end - def log_response uuid, response + def log_response uuid, response, base_url log_response_to_application_logger(uuid, response) if options.fetch(:show_response) log_response_to_execution_logger(response) else - execution_logger.info response_body_hidden_message + execution_logger.info response_body_hidden_message(base_url) end end - def response_body_hidden_message - PactBroker::Messages.message('messages.response_body_hidden') + def response_body_hidden_message(base_url) + PactBroker::Messages.message('messages.response_body_hidden', base_url: base_url) end def log_response_to_application_logger uuid, response @@ -106,13 +106,13 @@ def log_completion_message success end end - def log_error uuid, e + def log_error uuid, e, base_url logger.info "Error executing webhook #{uuid} #{e.class.name} - #{e.message} #{e.backtrace.join("\n")}" if options[:show_response] execution_logger.error "Error executing webhook #{uuid} #{e.class.name} - #{e.message}" else - execution_logger.error "Error executing webhook #{uuid}. #{response_body_hidden_message}" + execution_logger.error "Error executing webhook #{uuid}. #{response_body_hidden_message(base_url)}" end end diff --git a/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb b/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb index 57711decd..37f49f15c 100644 --- a/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +++ b/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb @@ -50,7 +50,8 @@ module Webhooks } end - let(:webhook_context) { { consumer_version_number: "123" } } + let(:base_url) { "http://example.org" } + let(:webhook_context) { { consumer_version_number: "123", base_url: base_url } } let(:webhook_request_logger) { WebhookRequestLogger.new(options) } @@ -117,6 +118,7 @@ module Webhooks end it "logs a message about why the response is hidden" do + expect(logs).to include base_url expect(logs).to include "security purposes" end end @@ -192,6 +194,7 @@ class WebhookTestError < StandardError; end end it "logs a message about why the response is hidden" do + expect(logs).to include base_url expect(logs).to include "security purposes" end end