Skip to content

Commit 5363ab2

Browse files
committed
fix: include the base URL in the link to the webhook docs
1 parent d64e9ee commit 5363ab2

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ def body
7878
}
7979
end
8080

81+
def to_hash(options)
82+
@to_hash_options = options
83+
super
84+
end
85+
8186
def response_hidden_message
82-
PactBroker::Messages.message('messages.response_body_hidden')
87+
PactBroker::Messages.message('messages.response_body_hidden', base_url: @to_hash_options[:user_options][:base_url])
8388
end
8489
end
8590
end

lib/pact_broker/locale/en.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ en:
1212

1313
pact_broker:
1414
messages:
15-
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.
15+
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.
1616
matrix:
1717
pre_verified: This pact was "pre-verified" as it has identical content to a previously verified pact.
1818
webhooks:

lib/pact_broker/webhooks/webhook_request_logger.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def log(uuid, webhook_request, http_response, error, webhook_context)
3333
safe_response = http_response ? HttpResponseWithUtf8SafeBody.new(http_response) : nil
3434
log_webhook_context(webhook_context)
3535
log_request(webhook_request)
36-
log_response(uuid, safe_response) if safe_response
37-
log_error(uuid, error) if error
36+
log_response(uuid, safe_response, webhook_context[:base_url]) if safe_response
37+
log_error(uuid, error, webhook_context[:base_url]) if error
3838
log_completion_message(success?(safe_response))
3939
log_stream.string
4040
end
@@ -61,17 +61,17 @@ def log_request(webhook_request)
6161
execution_logger.info(webhook_request.body) if webhook_request.body
6262
end
6363

64-
def log_response uuid, response
64+
def log_response uuid, response, base_url
6565
log_response_to_application_logger(uuid, response)
6666
if options.fetch(:show_response)
6767
log_response_to_execution_logger(response)
6868
else
69-
execution_logger.info response_body_hidden_message
69+
execution_logger.info response_body_hidden_message(base_url)
7070
end
7171
end
7272

73-
def response_body_hidden_message
74-
PactBroker::Messages.message('messages.response_body_hidden')
73+
def response_body_hidden_message(base_url)
74+
PactBroker::Messages.message('messages.response_body_hidden', base_url: base_url)
7575
end
7676

7777
def log_response_to_application_logger uuid, response
@@ -106,13 +106,13 @@ def log_completion_message success
106106
end
107107
end
108108

109-
def log_error uuid, e
109+
def log_error uuid, e, base_url
110110
logger.info "Error executing webhook #{uuid} #{e.class.name} - #{e.message} #{e.backtrace.join("\n")}"
111111

112112
if options[:show_response]
113113
execution_logger.error "Error executing webhook #{uuid} #{e.class.name} - #{e.message}"
114114
else
115-
execution_logger.error "Error executing webhook #{uuid}. #{response_body_hidden_message}"
115+
execution_logger.error "Error executing webhook #{uuid}. #{response_body_hidden_message(base_url)}"
116116
end
117117
end
118118

spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ module Webhooks
5050
}
5151
end
5252

53-
let(:webhook_context) { { consumer_version_number: "123" } }
53+
let(:base_url) { "http://example.org" }
54+
let(:webhook_context) { { consumer_version_number: "123", base_url: base_url } }
5455

5556
let(:webhook_request_logger) { WebhookRequestLogger.new(options) }
5657

@@ -117,6 +118,7 @@ module Webhooks
117118
end
118119

119120
it "logs a message about why the response is hidden" do
121+
expect(logs).to include base_url
120122
expect(logs).to include "security purposes"
121123
end
122124
end
@@ -192,6 +194,7 @@ class WebhookTestError < StandardError; end
192194
end
193195

194196
it "logs a message about why the response is hidden" do
197+
expect(logs).to include base_url
195198
expect(logs).to include "security purposes"
196199
end
197200
end

0 commit comments

Comments
 (0)