Search in sources :

Example 1 with RegistryConfigs

use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.

the class DockerConfigReaderTest method testFromDockerConfig_CredsStore.

@Test
public void testFromDockerConfig_CredsStore() throws Exception {
    assumeTrue("Need to have a credential store.", getAuthCredentialsExist());
    String domain1 = "https://test.fakedomain.com";
    String domain2 = "https://test.fakedomain2.com";
    String testAuth1 = "{\n" + "\t\"ServerURL\": \"" + domain1 + "\",\n" + "\t\"Username\": \"david\",\n" + "\t\"Secret\": \"passw0rd1\"\n" + "}";
    String testAuth2 = "{\n" + "\t\"ServerURL\": \"" + domain2 + "\",\n" + "\t\"Username\": \"carl\",\n" + "\t\"Secret\": \"myPassword\"\n" + "}";
    storeAuthCredential(testAuth1);
    storeAuthCredential(testAuth2);
    final Path path = getTestFilePath("dockerConfig/" + getCredsStoreFileName());
    final RegistryConfigs configs = reader.fromConfig(path);
    for (RegistryAuth authConfigs : configs.configs().values()) {
        if (domain1.equals(authConfigs.serverAddress())) {
            assertThat(authConfigs.username(), equalTo("david"));
            assertThat(authConfigs.password(), equalTo("passw0rd1"));
        } else if (domain2.equals(authConfigs.serverAddress())) {
            assertThat(authConfigs.username(), equalTo("carl"));
            assertThat(authConfigs.password(), equalTo("myPassword"));
        }
    }
    eraseAuthCredential(domain1);
    eraseAuthCredential(domain2);
}
Also used : Path(java.nio.file.Path) RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 2 with RegistryConfigs

use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.

the class DockerConfigReaderTest method testParseRegistryConfigs.

@Test
public void testParseRegistryConfigs() throws Exception {
    final Path path = getTestFilePath("dockerConfig/multiConfig.json");
    final RegistryConfigs configs = reader.fromConfig(path);
    assertThat(configs.configs(), allOf(hasEntry("https://index.docker.io/v1/", DOCKER_AUTH_CONFIG), hasEntry("https://narnia.mydock.io/v1/", MY_AUTH_CONFIG)));
}
Also used : Path(java.nio.file.Path) RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) Test(org.junit.Test)

Example 3 with RegistryConfigs

use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.

the class ConfigFileRegistryAuthSupplierTest method testAuthForBuild_Success.

@Test
public void testAuthForBuild_Success() throws Exception {
    final RegistryConfigs configs = RegistryConfigs.create(ImmutableMap.of("server1", RegistryAuth.builder().serverAddress("server1").username("user1").password("pass1").build()));
    when(reader.fromConfig(configFile.toPath())).thenReturn(configs);
    assertThat(supplier.authForBuild(), is(equalTo(configs)));
}
Also used : RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) Test(org.junit.Test)

Example 4 with RegistryConfigs

use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.

the class ContainerRegistryAuthSupplierTest method testAuthForBuild_TokenWithoutExpirationDoesNotCauseRefresh.

@Test
public void testAuthForBuild_TokenWithoutExpirationDoesNotCauseRefresh() throws Exception {
    final AccessToken accessToken = new AccessToken(tokenValue, null);
    final GoogleCredentials credentials = new GoogleCredentials(accessToken);
    final ContainerRegistryAuthSupplier supplier = new ContainerRegistryAuthSupplier(credentials, clock, TimeUnit.SECONDS.toMillis(minimumExpirationSecs), refresher);
    final RegistryConfigs configs = supplier.authForBuild();
    assertThat(configs.configs().values(), is(not(empty())));
    assertThat(configs.configs().values(), everyItem(matchesAccessToken(accessToken)));
    verify(refresher, never()).refresh(credentials);
}
Also used : RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) AccessToken(com.google.auth.oauth2.AccessToken) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Test(org.junit.Test)

Example 5 with RegistryConfigs

use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.

the class ContainerRegistryAuthSupplierTest method testAuthForBuild_NoRefresh.

@Test
public void testAuthForBuild_NoRefresh() throws Exception {
    when(clock.currentTimeMillis()).thenReturn(expiration.minusSeconds(minimumExpirationSecs + 1).getMillis());
    final RegistryConfigs configs = supplier.authForBuild();
    assertThat(configs.configs().values(), is(not(empty())));
    assertThat(configs.configs().values(), everyItem(matchesAccessToken(accessToken)));
    verify(refresher, never()).refresh(credentials);
}
Also used : RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) Test(org.junit.Test)

Aggregations

RegistryConfigs (com.spotify.docker.client.messages.RegistryConfigs)10 Test (org.junit.Test)9 Path (java.nio.file.Path)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 AccessToken (com.google.auth.oauth2.AccessToken)1 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 RegistryAuthSupplier (com.spotify.docker.client.auth.RegistryAuthSupplier)1 ProgressMessage (com.spotify.docker.client.messages.ProgressMessage)1 RegistryAuth (com.spotify.docker.client.messages.RegistryAuth)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WebTarget (javax.ws.rs.client.WebTarget)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1