Skip to content

Commit 47c602e

Browse files
committed
feat(webhooks): do not redact a password with a parameter in it
1 parent 66c1dc4 commit 47c602e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/pact_broker/webhooks/webhook_request_template.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def description
4848
end
4949

5050
def display_password
51-
password.nil? ? nil : "**********"
51+
password.nil? ? nil : (PactBroker::Webhooks::Render.includes_parameter?(password) ? password : "**********")
5252
end
5353

5454
def redacted_headers

spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Webhooks
88
method: 'POST',
99
url: url,
1010
username: "username",
11-
password: "password",
11+
password: password,
1212
uuid: "1234",
1313
body: body,
1414
headers: headers
@@ -27,6 +27,7 @@ module Webhooks
2727
}
2828
end
2929

30+
let(:password) { "password" }
3031
let(:headers) { {'headername' => 'headervalue'} }
3132
let(:url) { "http://example.org/hook?foo=bar" }
3233
let(:base_url) { "http://broker" }
@@ -156,6 +157,28 @@ module Webhooks
156157
end
157158
end
158159
end
160+
161+
describe "display_password" do
162+
subject { WebhookRequestTemplate.new(attributes) }
163+
164+
context "when it is nil" do
165+
let(:password) { nil }
166+
167+
its(:display_password) { is_expected.to be nil }
168+
end
169+
170+
context "when the password contains a parameter" do
171+
let(:password) { "${pactbroker.foo}" }
172+
173+
its(:display_password) { is_expected.to eq password }
174+
end
175+
176+
context "when the password does not contains a parameter" do
177+
let(:password) { "foo" }
178+
179+
its(:display_password) { is_expected.to eq "**********" }
180+
end
181+
end
159182
end
160183
end
161184
end

0 commit comments

Comments
 (0)