Search in sources :

Example 21 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AwsSigner4RequestTest method includesAuthTokenAsAwsSecurityToken.

@Test
public void includesAuthTokenAsAwsSecurityToken() {
    HttpUriRequest request = RequestUtil.newGet("https://someService.us-east-1.amazonaws.com/");
    request.setHeader("host", request.getURI().getHost());
    String awsSecurityToken = "securityToken";
    AuthConfig credentials = new AuthConfig("awsAccessKeyId", "awsSecretAccessKey", null, awsSecurityToken);
    AwsSigner4 signer = new AwsSigner4("us-east-1", "someService");
    signer.sign(request, credentials, new Date());
    Assert.assertEquals(request.getFirstHeader("X-Amz-Security-Token").getValue(), awsSecurityToken);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Date(java.util.Date) Test(org.junit.Test)

Example 22 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AwsSigner4RequestTest method testSign.

@Test
public void testSign() throws Exception {
    HttpPost request = new HttpPost("https://ecr.us-east-1.amazonaws.com/");
    request.setHeader("host", "ecr.us-east-1.amazonaws.com");
    request.setHeader("Content-Type", "application/x-amz-json-1.1");
    request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken");
    request.setEntity(new StringEntity("{\"registryIds\":[\"012345678901\"]}", StandardCharsets.UTF_8));
    AwsSigner4 signer = new AwsSigner4("us-east-1", "ecr");
    Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20150830T123600Z");
    AwsSigner4Request sr = new AwsSigner4Request("us-east-1", "service", request, signingTime);
    AuthConfig credentials = new AuthConfig("AKIDEXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", null, null);
    Assert.assertEquals(TASK1, signer.task1(sr));
    Assert.assertEquals(TASK2, signer.task2(sr));
    StringBuilder dst = new StringBuilder();
    AwsSigner4.hexEncode(dst, signer.task3(sr, credentials));
    Assert.assertEquals(TASK3, dst.toString());
    Assert.assertEquals(TASK4, signer.task4(sr, credentials));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Date(java.util.Date) Test(org.junit.Test)

Example 23 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class EcrExtendedAuthTest method testClientClosedAndCredentialsDecoded.

@Test
public void testClientClosedAndCredentialsDecoded(@Mocked final CloseableHttpClient closeableHttpClient, @Mocked final CloseableHttpResponse closeableHttpResponse, @Mocked final StatusLine statusLine) throws IOException, MojoExecutionException {
    final HttpEntity entity = new StringEntity("{\"authorizationData\": [{" + "\"authorizationToken\": \"QVdTOnBhc3N3b3Jk\"," + "\"expiresAt\": 1448878779.809," + "\"proxyEndpoint\": \"https://012345678910.dkr.ecr.eu-west-1.amazonaws.com\"}]}");
    new Expectations() {

        {
            statusLine.getStatusCode();
            result = 200;
            closeableHttpResponse.getEntity();
            result = entity;
        }
    };
    EcrExtendedAuth eea = new EcrExtendedAuth(logger, "123456789012.dkr.ecr.eu-west-1.amazonaws.com") {

        CloseableHttpClient createClient() {
            return closeableHttpClient;
        }
    };
    AuthConfig localCredentials = new AuthConfig("username", "password", null, null);
    AuthConfig awsCredentials = eea.extendedAuth(localCredentials);
    assertEquals("AWS", awsCredentials.getUsername());
    assertEquals("password", awsCredentials.getPassword());
    new Verifications() {

        {
            closeableHttpClient.close();
        }
    };
}
Also used : Expectations(mockit.Expectations) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Verifications(mockit.Verifications) Test(org.junit.Test)

Aggregations

AuthConfig (io.fabric8.maven.docker.access.AuthConfig)22 Test (org.junit.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Date (java.util.Date)3 Collections.singletonMap (java.util.Collections.singletonMap)2 Properties (java.util.Properties)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 JSONObject (org.json.JSONObject)2 AuthConfig (io.fabric8.docker.api.model.AuthConfig)1 AuthConfigBuilder (io.fabric8.docker.api.model.AuthConfigBuilder)1 Config (io.fabric8.docker.client.Config)1 ConfigBuilder (io.fabric8.docker.client.ConfigBuilder)1 DefaultDockerClient (io.fabric8.docker.client.DefaultDockerClient)1 DockerClient (io.fabric8.docker.client.DockerClient)1 EventListener (io.fabric8.docker.dsl.EventListener)1 OutputHandle (io.fabric8.docker.dsl.OutputHandle)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1