Skip to content

Commit db2f9d1

Browse files
committed
fix: correct logic for showing webhook response bodies in logs when a whitelist is configured
1 parent 86bc1ec commit db2f9d1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/pact_broker/webhooks/service.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def self.find_all
6161

6262
def self.execute_webhook_now webhook, pact, verification = nil
6363
triggered_webhook = webhook_repository.create_triggered_webhook(next_uuid, webhook, pact, verification, USER)
64-
options = { failure_log_message: "Webhook execution failed", show_response: PactBroker.configuration.show_webhook_response?}
64+
options = { failure_log_message: "Webhook execution failed"}
6565
webhook_execution_result = execute_triggered_webhook_now triggered_webhook, options
6666
if webhook_execution_result.success?
6767
webhook_repository.update_triggered_webhook_status triggered_webhook, TriggeredWebhook::STATUS_SUCCESS
@@ -72,7 +72,7 @@ def self.execute_webhook_now webhook, pact, verification = nil
7272
end
7373

7474
def self.execute_triggered_webhook_now triggered_webhook, options
75-
webhook_execution_result = triggered_webhook.execute options
75+
webhook_execution_result = triggered_webhook.execute options.merge(show_response: PactBroker.configuration.show_webhook_response?)
7676
webhook_repository.create_execution triggered_webhook, webhook_execution_result
7777
webhook_execution_result
7878
end

spec/lib/pact_broker/webhooks/service_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ module Webhooks
104104

105105
subject { PactBroker::Webhooks::Service.execute_webhook_now td.webhook, pact, td.verification }
106106

107-
it "executes the triggered webhook with the correct options" do
108-
allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo')
109-
expected_options = { :failure_log_message => "Webhook execution failed", :show_response => 'foo' }
110-
expect_any_instance_of(PactBroker::Webhooks::TriggeredWebhook).to receive(:execute).with(expected_options).and_call_original
111-
subject
112-
end
113-
114107
it "executes the HTTP request of the webhook" do
115108
subject
116109
expect(http_request).to have_been_made
@@ -165,6 +158,13 @@ module Webhooks
165158
expect(http_request).to have_been_made
166159
end
167160

161+
it "executes the webhook with the correct options" do
162+
allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo')
163+
expected_options = {:show_response => 'foo' }
164+
expect_any_instance_of(PactBroker::Domain::WebhookRequest).to receive(:execute).with(anything, anything, hash_including(expected_options)).and_call_original
165+
subject
166+
end
167+
168168
it "saves the triggered webhook" do
169169
expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(1)
170170
end

0 commit comments

Comments
 (0)