From 470ea54fffbbf0c1a222f534e4a98c57a5158579 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 23 Nov 2017 11:59:31 +0100 Subject: [PATCH] Ensuring that we don't print any credentials --- .../contract/stubrunner/StubRunnerOptions.java | 8 ++++++-- .../stubrunner/StubRunnerOptionsBuilderSpec.groovy | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java index 124967343c..392e5cb2d0 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java @@ -244,10 +244,14 @@ public class StubRunnerOptions { + this.maxPortValue + ", stubRepositoryRoot='" + this.stubRepositoryRoot + '\'' + ", workOffline=" + this.workOffline + ", stubsClassifier='" + this.stubsClassifier + '\'' + ", dependencies=" + this.dependencies + ", stubIdsToPortMapping=" - + this.stubIdsToPortMapping + ", username='" + this.username + '\'' + ", password='" - + this.password + '\'' + ", stubRunnerProxyOptions='" + this.stubRunnerProxyOptions + "', stubsPerConsumer='" + + this.stubIdsToPortMapping + ", username='" + obfuscate(this.username) + '\'' + ", password='" + + obfuscate(this.password) + '\'' + ", stubRunnerProxyOptions='" + this.stubRunnerProxyOptions + "', stubsPerConsumer='" + this.stubsPerConsumer + '\'' + ", stubsPerConsumer='" + this.stubsPerConsumer + '\'' + '}'; } + + private String obfuscate(String string) { + return StringUtils.hasText(string) ? "****" : ""; + } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy index aa13265231..60b0fedae6 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy @@ -162,6 +162,20 @@ class StubRunnerOptionsBuilderSpec extends Specification { options.mappingsOutputFolder == "folder" } + def shouldNotPrintUsernameAndPassword() { + given: + StubRunnerOptionsBuilder builder = builder.withOptions(new StubRunnerOptions(1, 2, "root", true, "classifier", + [new StubConfiguration("a:b:c")], [(new StubConfiguration("a:b:c")): 3], "username123", "password123", + new StubRunnerOptions.StubRunnerProxyOptions("host", 4), true, "consumer", "folder")) + builder.withStubs("foo:bar:baz") + when: + String options = builder.build().toString() + then: + !options.contains("username123") + !options.contains("password123") + options.contains("****") + } + @Issue("#462") @RestoreSystemProperties def shouldSetAllPropsFromSystemProps() {