From 30d66cf7f3030ddd6d84f023e141163afc593cbc Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 6 Nov 2021 14:04:56 +1100 Subject: [PATCH] fix: correct logic when redacting database URL without a password --- .../config/runtime_configuration_logging_methods.rb | 8 ++++++-- .../config/runtime_configuration_logging_methods_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/config/runtime_configuration_logging_methods.rb b/lib/pact_broker/config/runtime_configuration_logging_methods.rb index 7dfb1ec00..f21b0b1fe 100644 --- a/lib/pact_broker/config/runtime_configuration_logging_methods.rb +++ b/lib/pact_broker/config/runtime_configuration_logging_methods.rb @@ -38,8 +38,12 @@ def redact name, value if value && name.to_s.end_with?("_url") begin uri = URI(value) - uri.password = "*****" - uri.to_s + if uri.password + uri.password = "*****" + uri.to_s + else + value + end rescue StandardError "*****" end diff --git a/spec/lib/pact_broker/config/runtime_configuration_logging_methods_spec.rb b/spec/lib/pact_broker/config/runtime_configuration_logging_methods_spec.rb index 132d71c21..4ed82a129 100644 --- a/spec/lib/pact_broker/config/runtime_configuration_logging_methods_spec.rb +++ b/spec/lib/pact_broker/config/runtime_configuration_logging_methods_spec.rb @@ -17,6 +17,14 @@ module Config expect(subject).to include "database_password=*****" expect(subject).to include "database_url=protocol://username:*****@host/database" end + + context "with a database URL with no password" do + let(:initial_values) { { database_password: "foo", database_url: "sqlite:///pact_broker.sqlite3" } } + + it "maintians the specified value" do + expect(subject).to include "database_url=sqlite:///pact_broker.sqlite3" + end + end end end end