forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthConfigTest.java
More file actions
110 lines (89 loc) · 4.3 KB
/
Copy pathAuthConfigTest.java
File metadata and controls
110 lines (89 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.github.dockerjava.api.model;
import com.fasterxml.jackson.databind.JavaType;
import com.github.dockerjava.core.RemoteApiVersion;
import com.github.dockerjava.test.serdes.JSONTestHelper;
import org.junit.Test;
import java.io.IOException;
import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
public class AuthConfigTest {
@Test
public void defaultServerAddress() throws Exception {
assertEquals(new AuthConfig().getRegistryAddress(), "https://index.docker.io/v1/");
}
@Test
public void serderDocs1() throws IOException {
final JavaType type = JSONTestHelper.getMapper().getTypeFactory().constructType(AuthConfig.class);
final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_22,
"/other/AuthConfig/docs1.json",
type
);
assertThat(authConfig, notNullValue());
assertThat(authConfig.getUsername(), is("jdoe"));
assertThat(authConfig.getPassword(), is("secret"));
assertThat(authConfig.getEmail(), is("jdoe@acme.com"));
final AuthConfig authConfig1 = new AuthConfig().withUsername("jdoe")
.withPassword("secret")
.withEmail("jdoe@acme.com");
assertThat(authConfig1, equalTo(authConfig));
}
@Test
public void serderDocs2() throws IOException {
final JavaType type = JSONTestHelper.getMapper().getTypeFactory().constructType(AuthConfig.class);
final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_22,
"/other/AuthConfig/docs2.json",
type
);
assertThat(authConfig, notNullValue());
assertThat(authConfig.getRegistrytoken(), is("9cbaf023786cd7..."));
final AuthConfig authConfig1 = new AuthConfig().withRegistrytoken("9cbaf023786cd7...");
assertThat(authConfig1, equalTo(authConfig));
}
@Test
public void compatibleWithIdentitytoken() throws IOException {
final JavaType type = JSONTestHelper.getMapper().getTypeFactory().constructType(AuthConfig.class);
final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_23,
"/other/AuthConfig/docs1.json",
type
);
String auth = "YWRtaW46";
String identitytoken = "1cba468e-8cbe-4c55-9098-2c2ed769e885";
assertThat(authConfig, notNullValue());
assertThat(authConfig.getAuth(), is(auth));
assertThat(authConfig.getIdentitytoken(), is(identitytoken));
final AuthConfig authConfig1 = new AuthConfig().withAuth(auth).withIdentityToken(identitytoken);
assertThat(authConfig1, equalTo(authConfig));
}
@Test
public void shouldNotFailWithStackOrchestratorInConfig() throws IOException {
final JavaType type = JSONTestHelper.getMapper().getTypeFactory().constructType(AuthConfig.class);
final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_25,
"/other/AuthConfig/orchestrators.json",
type
);
assertThat(authConfig, notNullValue());
assertThat(authConfig.getAuth(), is(nullValue()));
assertThat(authConfig.getStackOrchestrator(), is("kubernetes"));
}
@Test
public void toStringDoesNotContainSensitiveStrings() {
AuthConfig authConfig = new AuthConfig()
.withAuth("authValue")
.withEmail("emailValue")
.withPassword("passwordValue")
.withIdentityToken("identityTokenValue")
.withRegistrytoken("registryTokenValue")
.withRegistryAddress("registryAddressValue");
String toStringValue = authConfig.toString();
assertThat(toStringValue, not(containsString("authValue")));
assertThat(toStringValue, not(containsString("passwordValue")));
assertThat(toStringValue, not(containsString("identityTokenValue")));
assertThat(toStringValue, not(containsString("registryTokenValue")));
assertThat(toStringValue, containsString("emailValue"));
assertThat(toStringValue, containsString("registryAddressValue"));
}
}