forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
|
||
/** | ||
* Tests for {@link Docker}. | ||
|
@@ -37,7 +38,7 @@ class DockerTests { | |
@Test | ||
void asDockerConfigurationWithDefaults() { | ||
Docker docker = new Docker(); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
assertThat(dockerConfiguration.getHost()).isNull(); | ||
assertThat(dockerConfiguration.getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())) | ||
|
@@ -53,14 +54,14 @@ void asDockerConfigurationWithHostConfiguration() { | |
docker.setHost("docker.example.com"); | ||
docker.setTlsVerify(true); | ||
docker.setCertPath("/tmp/ca-cert"); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
DockerHostConfiguration host = dockerConfiguration.getHost(); | ||
assertThat(host.getAddress()).isEqualTo("docker.example.com"); | ||
assertThat(host.isSecure()).isTrue(); | ||
assertThat(host.getCertificatePath()).isEqualTo("/tmp/ca-cert"); | ||
assertThat(host.getContext()).isNull(); | ||
assertThat(dockerConfiguration.isBindHostToBuilder()).isFalse(); | ||
assertThat(docker.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(createDockerConfiguration(docker).getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())) | ||
.contains("\"username\" : \"\"") | ||
.contains("\"password\" : \"\"") | ||
|
@@ -72,14 +73,14 @@ void asDockerConfigurationWithHostConfiguration() { | |
void asDockerConfigurationWithContextConfiguration() { | ||
Docker docker = new Docker(); | ||
docker.setContext("test-context"); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
DockerHostConfiguration host = dockerConfiguration.getHost(); | ||
assertThat(host.getContext()).isEqualTo("test-context"); | ||
assertThat(host.getAddress()).isNull(); | ||
assertThat(host.isSecure()).isFalse(); | ||
assertThat(host.getCertificatePath()).isNull(); | ||
assertThat(dockerConfiguration.isBindHostToBuilder()).isFalse(); | ||
assertThat(docker.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(createDockerConfiguration(docker).getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())) | ||
.contains("\"username\" : \"\"") | ||
.contains("\"password\" : \"\"") | ||
|
@@ -92,7 +93,7 @@ void asDockerConfigurationWithHostAndContextFails() { | |
Docker docker = new Docker(); | ||
docker.setContext("test-context"); | ||
docker.setHost("docker.example.com"); | ||
assertThatIllegalArgumentException().isThrownBy(docker::asDockerConfiguration) | ||
assertThatIllegalArgumentException().isThrownBy(() -> createDockerConfiguration(docker)) | ||
.withMessageContaining("Invalid Docker configuration"); | ||
} | ||
|
||
|
@@ -103,13 +104,13 @@ void asDockerConfigurationWithBindHostToBuilder() { | |
docker.setTlsVerify(true); | ||
docker.setCertPath("/tmp/ca-cert"); | ||
docker.setBindHostToBuilder(true); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
DockerHostConfiguration host = dockerConfiguration.getHost(); | ||
assertThat(host.getAddress()).isEqualTo("docker.example.com"); | ||
assertThat(host.isSecure()).isTrue(); | ||
assertThat(host.getCertificatePath()).isEqualTo("/tmp/ca-cert"); | ||
assertThat(dockerConfiguration.isBindHostToBuilder()).isTrue(); | ||
assertThat(docker.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(createDockerConfiguration(docker).getBuilderRegistryAuthentication()).isNull(); | ||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())) | ||
.contains("\"username\" : \"\"") | ||
.contains("\"password\" : \"\"") | ||
|
@@ -124,7 +125,7 @@ void asDockerConfigurationWithUserAuth() { | |
new Docker.DockerRegistry("user1", "secret1", "https://docker1.example.com", "[email protected]")); | ||
docker.setPublishRegistry( | ||
new Docker.DockerRegistry("user2", "secret2", "https://docker2.example.com", "[email protected]")); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())) | ||
.contains("\"username\" : \"user1\"") | ||
.contains("\"password\" : \"secret1\"") | ||
|
@@ -142,7 +143,7 @@ void asDockerConfigurationWithIncompleteBuilderUserAuthFails() { | |
Docker docker = new Docker(); | ||
docker.setBuilderRegistry( | ||
new Docker.DockerRegistry("user", null, "https://docker.example.com", "[email protected]")); | ||
assertThatIllegalArgumentException().isThrownBy(docker::asDockerConfiguration) | ||
assertThatIllegalArgumentException().isThrownBy(() -> createDockerConfiguration(docker)) | ||
.withMessageContaining("Invalid Docker builder registry configuration"); | ||
} | ||
|
||
|
@@ -151,7 +152,7 @@ void asDockerConfigurationWithIncompletePublishUserAuthFails() { | |
Docker docker = new Docker(); | ||
docker.setPublishRegistry( | ||
new Docker.DockerRegistry("user", null, "https://docker.example.com", "[email protected]")); | ||
assertThatIllegalArgumentException().isThrownBy(docker::asDockerConfiguration) | ||
assertThatIllegalArgumentException().isThrownBy(() -> createDockerConfiguration(docker)) | ||
.withMessageContaining("Invalid Docker publish registry configuration"); | ||
} | ||
|
||
|
@@ -160,7 +161,7 @@ void asDockerConfigurationWithTokenAuth() { | |
Docker docker = new Docker(); | ||
docker.setBuilderRegistry(new Docker.DockerRegistry("token1")); | ||
docker.setPublishRegistry(new Docker.DockerRegistry("token2")); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(); | ||
DockerConfiguration dockerConfiguration = createDockerConfiguration(docker); | ||
assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())) | ||
.contains("\"identitytoken\" : \"token1\""); | ||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())) | ||
|
@@ -175,10 +176,27 @@ void asDockerConfigurationWithUserAndTokenAuthFails() { | |
dockerRegistry.setToken("token"); | ||
Docker docker = new Docker(); | ||
docker.setBuilderRegistry(dockerRegistry); | ||
assertThatIllegalArgumentException().isThrownBy(docker::asDockerConfiguration) | ||
assertThatIllegalArgumentException().isThrownBy(() -> createDockerConfiguration(docker)) | ||
.withMessageContaining("Invalid Docker builder registry configuration"); | ||
} | ||
|
||
@Test | ||
void asDockerConfigurationWithUserAndTokenAuthDoesNotFailIfPublishingIsDisabled() { | ||
Docker.DockerRegistry dockerRegistry = new Docker.DockerRegistry(); | ||
dockerRegistry.setUsername("user"); | ||
dockerRegistry.setPassword("secret"); | ||
dockerRegistry.setToken("token"); | ||
Docker docker = new Docker(); | ||
docker.setPublishRegistry(dockerRegistry); | ||
DockerConfiguration dockerConfiguration = docker.asDockerConfiguration(false); | ||
assertThat(dockerConfiguration.getPublishRegistryAuthentication()).isNull(); | ||
} | ||
|
||
private DockerConfiguration createDockerConfiguration(Docker docker) { | ||
return docker.asDockerConfiguration(true); | ||
|
||
} | ||
|
||
String decoded(String value) { | ||
return new String(Base64.getDecoder().decode(value)); | ||
} | ||
|