File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed
spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config
spring-cloud-consul-discovery/src
main/java/org/springframework/cloud/consul/discovery
test/java/org/springframework/cloud/consul/discovery/reactive Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2013-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .cloud .consul .config ;
18+
19+ import org .junit .jupiter .api .Test ;
20+
21+ import static org .assertj .core .api .Assertions .assertThat ;
22+
23+ public class ConsulConfigPropertiesTests {
24+
25+ @ Test
26+ public void aclTokenToStringMasked () {
27+ ConsulConfigProperties properties = new ConsulConfigProperties ();
28+ properties .setAclToken ("myAclToken" );
29+ assertThat (properties .toString ()).doesNotContain ("myAclToken" ).contains ("******" );
30+ }
31+
32+ }
Original file line number Diff line number Diff line change @@ -619,7 +619,7 @@ public void setManagementEnableTagOverride(Boolean managementEnableTagOverride)
619619
620620 @ Override
621621 public String toString () {
622- return new ToStringCreator (this ).append ("aclToken" , this .aclToken )
622+ return new ToStringCreator (this ).append ("aclToken" , this .aclToken != null ? "******" : null )
623623 .append ("catalogServicesWatchDelay" , this .catalogServicesWatchDelay )
624624 .append ("catalogServicesWatchTimeout" , this .catalogServicesWatchTimeout )
625625 .append ("consistencyMode" , this .consistencyMode )
Original file line number Diff line number Diff line change 3333import reactor .test .StepVerifier ;
3434
3535import org .springframework .cloud .client .ServiceInstance ;
36+ import org .springframework .cloud .commons .util .InetUtils ;
3637import org .springframework .cloud .consul .discovery .ConsulDiscoveryProperties ;
3738
3839import static java .util .Collections .emptyList ;
@@ -88,9 +89,18 @@ public void shouldReturnFluxOfServices() {
8889 verify (consulClient ).getCatalogServices (any (CatalogServicesRequest .class ));
8990 }
9091
92+ @ Test
93+ public void aclTokenToStringMasked () {
94+ InetUtils inetUtils = mock (InetUtils .class );
95+ when (inetUtils .findFirstNonLoopbackHostInfo ()).thenReturn (mock (InetUtils .HostInfo .class ));
96+ ConsulDiscoveryProperties consulDiscoveryProperties = new ConsulDiscoveryProperties (inetUtils );
97+ consulDiscoveryProperties .setAclToken ("myAclToken" );
98+ assertThat (consulDiscoveryProperties .toString ()).doesNotContain ("myAclToken" ).contains ("******" );
99+ }
100+
91101 @ Test
92102 public void shouldReturnFluxOfServicesWithAclToken () {
93- when (properties .getAclToken ()).thenReturn ("aclToken " );
103+ when (properties .getAclToken ()).thenReturn ("myAclToken " );
94104 when (consulClient .getCatalogServices (any (CatalogServicesRequest .class ))).thenReturn (consulServicesResponse ());
95105 Flux <String > services = client .getServices ();
96106 StepVerifier .create (services ).expectNext ("my-service" ).expectComplete ().verify ();
You can’t perform that action at this time.
0 commit comments