Skip to content

Commit

Permalink
feat(webhooks): do not redact a password with a parameter in it
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 25, 2019
1 parent 66c1dc4 commit 47c602e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/webhooks/webhook_request_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def description
end

def display_password
password.nil? ? nil : "**********"
password.nil? ? nil : (PactBroker::Webhooks::Render.includes_parameter?(password) ? password : "**********")
end

def redacted_headers
Expand Down
25 changes: 24 additions & 1 deletion spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Webhooks
method: 'POST',
url: url,
username: "username",
password: "password",
password: password,
uuid: "1234",
body: body,
headers: headers
Expand All @@ -27,6 +27,7 @@ module Webhooks
}
end

let(:password) { "password" }
let(:headers) { {'headername' => 'headervalue'} }
let(:url) { "http://example.org/hook?foo=bar" }
let(:base_url) { "http://broker" }
Expand Down Expand Up @@ -156,6 +157,28 @@ module Webhooks
end
end
end

describe "display_password" do
subject { WebhookRequestTemplate.new(attributes) }

context "when it is nil" do
let(:password) { nil }

its(:display_password) { is_expected.to be nil }
end

context "when the password contains a parameter" do
let(:password) { "${pactbroker.foo}" }

its(:display_password) { is_expected.to eq password }
end

context "when the password does not contains a parameter" do
let(:password) { "foo" }

its(:display_password) { is_expected.to eq "**********" }
end
end
end
end
end

0 comments on commit 47c602e

Please sign in to comment.