Search in sources :

Example 6 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class UserSpecificDockerRegistryCredentialsProviderTest method shouldReturnConfigsWithEmptyMapIfNoCredentialsDataInUserPreferences.

@Test
public void shouldReturnConfigsWithEmptyMapIfNoCredentialsDataInUserPreferences() throws ServerException {
    String base64encodedCredentials = "e30=";
    setCredentialsIntoPreferences(base64encodedCredentials);
    AuthConfigs parsedAuthConfigs = dockerCredentials.getCredentials();
    assertEquals(parsedAuthConfigs.getConfigs().size(), 0);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) Test(org.testng.annotations.Test)

Example 7 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToBuildImage.

@Test
public void shouldBeAbleToBuildImage() throws IOException, InterruptedException {
    AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
    AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
    Map<String, AuthConfig> auth = new HashMap<>();
    auth.put("auth", authConfig);
    authConfigs.setConfigs(auth);
    final String imageId = "37a7da3b7edc";
    BuildImageParams buildImageParams = BuildImageParams.create(dockerfile).withAuthConfigs(authConfigs);
    doReturn(new ByteArrayInputStream(("{\"stream\":\"Successfully built " + imageId + "\"}").getBytes())).when(dockerResponse).getInputStream();
    String returnedImageId = dockerConnector.buildImage(buildImageParams, progressMonitor);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/build");
    verify(dockerConnection).header("Content-Type", "application/x-compressed-tar");
    verify(dockerConnection).header(eq("Content-Length"), anyInt());
    verify(dockerConnection).entity(any(InputStream.class));
    verify(dockerConnection, never()).header(eq("remote"), anyString());
    verify(dockerConnection).header(eq("X-Registry-Config"), any(byte[].class));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
    assertEquals(returnedImageId, imageId);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) InputStream(java.io.InputStream) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Matchers.anyString(org.mockito.Matchers.anyString) BuildImageParams(org.eclipse.che.plugin.docker.client.params.BuildImageParams) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 8 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToBuildImageWithRemoteContext.

@Test
public void shouldBeAbleToBuildImageWithRemoteContext() throws IOException, InterruptedException {
    AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
    AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
    Map<String, AuthConfig> auth = new HashMap<>();
    auth.put("auth", authConfig);
    authConfigs.setConfigs(auth);
    final String imageId = "37a7da3b7edc";
    final String remote = "https://some.host.com/path/tarball.tar";
    BuildImageParams buildImageParams = BuildImageParams.create(remote).withAuthConfigs(authConfigs);
    doReturn(new ByteArrayInputStream(("{\"stream\":\"Successfully built " + imageId + "\"}").getBytes())).when(dockerResponse).getInputStream();
    String returnedImageId = dockerConnector.buildImage(buildImageParams, progressMonitor);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/build");
    verify(dockerConnection).query(eq("remote"), eq(remote));
    verify(dockerConnection, never()).header("Content-Type", "application/x-compressed-tar");
    verify(dockerConnection, never()).header(eq("Content-Length"), anyInt());
    verify(dockerConnection, never()).entity(any(InputStream.class));
    verify(dockerConnection).header(eq("X-Registry-Config"), any(byte[].class));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
    assertEquals(returnedImageId, imageId);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) InputStream(java.io.InputStream) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Matchers.anyString(org.mockito.Matchers.anyString) BuildImageParams(org.eclipse.che.plugin.docker.client.params.BuildImageParams) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 9 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class DockerConnectorTest method shouldThrowDockerExceptionWhileBuildingImageIfResponseCodeIsNotSuccess.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhileBuildingImageIfResponseCodeIsNotSuccess() throws IOException, InterruptedException {
    AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
    AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
    Map<String, AuthConfig> auth = new HashMap<>();
    auth.put("auth", authConfig);
    authConfigs.setConfigs(auth);
    BuildImageParams getExecInfoParams = BuildImageParams.create(dockerfile).withAuthConfigs(authConfigs);
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
    dockerConnector.buildImage(getExecInfoParams, progressMonitor);
    verify(dockerResponse).getStatus();
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) HashMap(java.util.HashMap) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Matchers.anyString(org.mockito.Matchers.anyString) BuildImageParams(org.eclipse.che.plugin.docker.client.params.BuildImageParams) Test(org.testng.annotations.Test)

Aggregations

AuthConfigs (org.eclipse.che.plugin.docker.client.dto.AuthConfigs)9 Test (org.testng.annotations.Test)9 AuthConfig (org.eclipse.che.plugin.docker.client.dto.AuthConfig)6 HashMap (java.util.HashMap)5 BuildImageParams (org.eclipse.che.plugin.docker.client.params.BuildImageParams)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)3 URI (java.net.URI)3 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)3