Skip to content

Commit b09d820

Browse files
rnorthbsideup
andauthored
Replace AuthConfig toString implementation (docker-java#1506)
* Obfuscate sensitive values in AuthConfig toString * Update AuthConfig.java Co-authored-by: Sergei Egorov <segorov@vmware.com>
1 parent c9c64cd commit b09d820

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

docker-java-api/src/main/java/com/github/dockerjava/api/model/AuthConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.io.Serializable;
99

1010
@EqualsAndHashCode
11-
@ToString
11+
@ToString(onlyExplicitlyIncluded = true)
1212
public class AuthConfig implements Serializable {
1313
private static final long serialVersionUID = 1L;
1414

@@ -20,15 +20,18 @@ public class AuthConfig implements Serializable {
2020
public static final String DEFAULT_SERVER_ADDRESS = "https://index.docker.io/v1/";
2121

2222
@JsonProperty("username")
23+
@ToString.Include
2324
private String username;
2425

2526
@JsonProperty("password")
2627
private String password;
2728

2829
@JsonProperty("email")
30+
@ToString.Include
2931
private String email;
3032

3133
@JsonProperty("serveraddress")
34+
@ToString.Include
3235
private String registryAddress = DEFAULT_SERVER_ADDRESS;
3336

3437
@JsonProperty("auth")
@@ -50,6 +53,7 @@ public class AuthConfig implements Serializable {
5053
* @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_25}
5154
*/
5255
@JsonProperty("stackOrchestrator")
56+
@ToString.Include
5357
private String stackOrchestrator;
5458

5559
public String getUsername() {

docker-java/src/test/java/com/github/dockerjava/api/model/AuthConfigTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import java.io.IOException;
99

1010
import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip;
11-
import static org.hamcrest.CoreMatchers.equalTo;
12-
import static org.hamcrest.CoreMatchers.is;
13-
import static org.hamcrest.CoreMatchers.nullValue;
11+
import static org.hamcrest.CoreMatchers.*;
1412
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.hamcrest.Matchers.not;
1514
import static org.hamcrest.Matchers.notNullValue;
1615
import static org.junit.Assert.assertEquals;
1716

@@ -89,4 +88,23 @@ public void shouldNotFailWithStackOrchestratorInConfig() throws IOException {
8988
assertThat(authConfig.getStackOrchestrator(), is("kubernetes"));
9089
}
9190

91+
@Test
92+
public void toStringDoesNotContainSensitiveStrings() {
93+
AuthConfig authConfig = new AuthConfig()
94+
.withAuth("authValue")
95+
.withEmail("emailValue")
96+
.withPassword("passwordValue")
97+
.withIdentityToken("identityTokenValue")
98+
.withRegistrytoken("registryTokenValue")
99+
.withRegistryAddress("registryAddressValue");
100+
String toStringValue = authConfig.toString();
101+
102+
assertThat(toStringValue, not(containsString("authValue")));
103+
assertThat(toStringValue, not(containsString("passwordValue")));
104+
assertThat(toStringValue, not(containsString("identityTokenValue")));
105+
assertThat(toStringValue, not(containsString("registryTokenValue")));
106+
107+
assertThat(toStringValue, containsString("emailValue"));
108+
assertThat(toStringValue, containsString("registryAddressValue"));
109+
}
92110
}

0 commit comments

Comments
 (0)