Search in sources :

Example 16 with AuthConfig

use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.

the class AuthConfigFactoryTest method testGetAuthConfigFromOpenShiftConfig.

@Test
public void testGetAuthConfigFromOpenShiftConfig() {
    // Given
    new SystemMock().put("jkube.docker.useOpenShiftAuth", "true");
    Map<String, Object> authConfigMap = new HashMap<>();
    new MockUp<KubernetesConfigAuthUtil>() {

        @Mock
        AuthConfig readKubeConfigAuth() {
            return AuthConfig.builder().username("test").password("sometoken").build();
        }
    };
    // When
    AuthConfig authConfig = AuthConfigFactory.getAuthConfigFromOpenShiftConfig(AuthConfigFactory.LookupMode.DEFAULT, authConfigMap);
    // Then
    assertAuthConfig(authConfig, "test", "sometoken");
}
Also used : HashMap(java.util.HashMap) SystemMock(org.eclipse.jkube.kit.common.SystemMock) JsonObject(com.google.gson.JsonObject) MockUp(mockit.MockUp) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) Test(org.junit.Test)

Example 17 with AuthConfig

use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.

the class AuthConfigFactoryTest method testGetAuthConfigFromDockerConfig.

@Test
public void testGetAuthConfigFromDockerConfig(@Mocked KitLogger logger) throws IOException {
    // Given
    new MockUp<DockerFileUtil>() {

        @Mock
        JsonObject readDockerConfig() {
            JsonObject dockerConfig = new JsonObject();
            JsonObject auths = new JsonObject();
            JsonObject creds = new JsonObject();
            creds.addProperty("auth", "dGVzdHVzZXI6dGVzdHBhc3M=");
            auths.add("https://index.docker.io/v1/", creds);
            dockerConfig.add("auths", auths);
            return dockerConfig;
        }
    };
    // When
    AuthConfig authConfig = AuthConfigFactory.getAuthConfigFromDockerConfig("https://index.docker.io/v1/", logger);
    // Then
    assertAuthConfig(authConfig, "testuser", "testpass");
}
Also used : JsonObject(com.google.gson.JsonObject) MockUp(mockit.MockUp) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) Test(org.junit.Test)

Example 18 with AuthConfig

use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.

the class AuthConfigFactoryTest method awsStaticCredentialsArePickedUpFromEnvironment.

@Test
public void awsStaticCredentialsArePickedUpFromEnvironment() throws IOException {
    givenAwsSdkIsDisabled();
    String accessKeyId = randomUUID().toString();
    String secretAccessKey = randomUUID().toString();
    new Expectations() {

        {
            awsSdkHelper.getAwsAccessKeyIdEnvVar();
            result = accessKeyId;
            awsSdkHelper.getAwsSecretAccessKeyEnvVar();
            result = secretAccessKey;
        }
    };
    AuthConfig authConfig = factory.createAuthConfig(false, true, null, Collections.emptyList(), "user", ECR_NAME, s -> s);
    verifyAuthConfig(authConfig, accessKeyId, secretAccessKey, null, null);
}
Also used : Expectations(mockit.Expectations) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) Test(org.junit.Test)

Example 19 with AuthConfig

use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.

the class AuthConfigFactoryTest method testGetStandardAuthConfigFromMavenSettings.

@Test
public void testGetStandardAuthConfigFromMavenSettings(@Mocked KitLogger logger) throws IOException {
    // Given
    List<RegistryServerConfiguration> settings = new ArrayList<>();
    settings.add(RegistryServerConfiguration.builder().id("testregistry.io").username("testuser").password("testpass").build());
    // When
    AuthConfigFactory authConfigFactory = new AuthConfigFactory(logger);
    AuthConfig authConfig = authConfigFactory.createAuthConfig(true, true, Collections.emptyMap(), settings, "testuser", "testregistry.io", s -> s);
    // Then
    assertAuthConfig(authConfig, "testuser", "testpass");
}
Also used : ArrayList(java.util.ArrayList) AwsSdkAuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.ecr.AwsSdkAuthConfigFactory) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration) Test(org.junit.Test)

Example 20 with AuthConfig

use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.

the class AuthConfigFactoryTest method getAuthConfigViaAwsSdk.

@Test
public void getAuthConfigViaAwsSdk() throws IOException {
    new Expectations() {

        {
            awsSdkHelper.isDefaultAWSCredentialsProviderChainPresentInClassPath();
            result = true;
        }
    };
    String accessKeyId = randomUUID().toString();
    String secretAccessKey = randomUUID().toString();
    new MockedAwsSdkAuthConfigFactory(accessKeyId, secretAccessKey);
    AuthConfig authConfig = factory.createAuthConfig(false, true, null, Collections.emptyList(), "user", ECR_NAME, s -> s);
    verifyAuthConfig(authConfig, accessKeyId, secretAccessKey, null, null);
}
Also used : Expectations(mockit.Expectations) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) Test(org.junit.Test)

Aggregations

AuthConfig (org.eclipse.jkube.kit.build.api.auth.AuthConfig)42 Test (org.junit.Test)34 RegistryAuthConfig (org.eclipse.jkube.kit.build.api.auth.RegistryAuthConfig)10 JsonObject (com.google.gson.JsonObject)6 Expectations (mockit.Expectations)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Date (java.util.Date)3 MockUp (mockit.MockUp)3 ImageName (org.eclipse.jkube.kit.config.image.ImageName)3 ArrayList (java.util.ArrayList)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 AuthConfigFactory (org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory)2 RegistryServerConfiguration (org.eclipse.jkube.kit.common.RegistryServerConfiguration)2 SystemMock (org.eclipse.jkube.kit.common.SystemMock)2 Credential (com.google.cloud.tools.jib.api.Credential)1 Gson (com.google.gson.Gson)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1