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);
}
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));
}
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();
}
};
}
Aggregations