Search in sources :

Example 1 with RegistryAuthSupplier

use of com.spotify.docker.client.auth.RegistryAuthSupplier in project docker-client by spotify.

the class DefaultDockerClientUnitTest method buildThrowsIfRegistryAuthandRegistryAuthSupplierAreBothSpecified.

@Test
@SuppressWarnings("deprecated")
public void buildThrowsIfRegistryAuthandRegistryAuthSupplierAreBothSpecified() throws DockerCertificateException {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("LOGIC ERROR");
    final RegistryAuthSupplier authSupplier = mock(RegistryAuthSupplier.class);
    // noinspection deprecation
    DefaultDockerClient.builder().registryAuth(RegistryAuth.builder().identityToken("hello").build()).registryAuthSupplier(authSupplier).build();
}
Also used : RegistryAuthSupplier(com.spotify.docker.client.auth.RegistryAuthSupplier) Test(org.junit.Test)

Example 2 with RegistryAuthSupplier

use of com.spotify.docker.client.auth.RegistryAuthSupplier in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testBuildPassesMultipleRegistryConfigs.

@Test
public void testBuildPassesMultipleRegistryConfigs() throws Exception {
    final RegistryConfigs registryConfigs = RegistryConfigs.create(ImmutableMap.of("server1", RegistryAuth.builder().serverAddress("server1").username("u1").password("p1").email("e1").build(), "server2", RegistryAuth.builder().serverAddress("server2").username("u2").password("p2").email("e2").build()));
    final RegistryAuthSupplier authSupplier = mock(RegistryAuthSupplier.class);
    when(authSupplier.authForBuild()).thenReturn(registryConfigs);
    final DefaultDockerClient client = builder.registryAuthSupplier(authSupplier).build();
    // build() calls /version to check what format of header to send
    enqueueServerApiVersion("1.20");
    // TODO (mbrown): what to return for build response?
    server.enqueue(new MockResponse().setResponseCode(200));
    final Path path = Paths.get(Resources.getResource("dockerDirectory").toURI());
    client.build(path);
    final RecordedRequest versionRequest = takeRequestImmediately();
    assertThat(versionRequest.getMethod(), is("GET"));
    assertThat(versionRequest.getPath(), is("/version"));
    final RecordedRequest buildRequest = takeRequestImmediately();
    assertThat(buildRequest.getMethod(), is("POST"));
    assertThat(buildRequest.getPath(), is("/build"));
    final String registryConfigHeader = buildRequest.getHeader("X-Registry-Config");
    assertThat(registryConfigHeader, is(not(nullValue())));
    // check that the JSON in the header is equivalent to what we mocked out above from
    // the registryAuthSupplier
    final JsonNode headerJsonNode = toJson(BaseEncoding.base64().decode(registryConfigHeader));
    assertThat(headerJsonNode, is(toJson(registryConfigs.configs())));
}
Also used : Path(java.nio.file.Path) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.containsString(org.hamcrest.Matchers.containsString) RegistryAuthSupplier(com.spotify.docker.client.auth.RegistryAuthSupplier) Test(org.junit.Test)

Aggregations

RegistryAuthSupplier (com.spotify.docker.client.auth.RegistryAuthSupplier)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 RegistryConfigs (com.spotify.docker.client.messages.RegistryConfigs)1 Path (java.nio.file.Path)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1