Skip to content

Commit

Permalink
fix: include the base URL in the link to the webhook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 24, 2020
1 parent d64e9ee commit 5363ab2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions lib/pact_broker/webhooks/webhook_request_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5363ab2

Please sign in to comment.