Remove all newlines in PKCS7 from EC2MetaData.

Closes gh-571.
This commit is contained in:
Mark Paluch
2020-08-31 14:13:25 +02:00
parent 75f6800f9c
commit 06eb31857f
2 changed files with 14 additions and 2 deletions

View File

@@ -110,7 +110,7 @@ public class AwsEc2Authentication implements ClientAuthentication, Authenticatio
return AuthenticationSteps
.fromHttpRequest(HttpRequestBuilder.get(options.getIdentityDocumentUri().toString()).as(String.class)) //
.map(pkcs7 -> pkcs7.replaceAll("\\r", "")) //
.map(pkcs7 -> pkcs7.replace("\\n", "")) //
.map(pkcs7 -> pkcs7.replaceAll("\\n", "")) //
.map(pkcs7 -> {
Map<String, String> login = new HashMap<>();
@@ -189,7 +189,7 @@ public class AwsEc2Authentication implements ClientAuthentication, Authenticatio
String pkcs7 = this.awsMetadataRestOperations.getForObject(this.options.getIdentityDocumentUri(),
String.class);
if (StringUtils.hasText(pkcs7)) {
login.put("pkcs7", pkcs7.replaceAll("\\r", "").replace("\\n", ""));
login.put("pkcs7", pkcs7.replaceAll("\\r", "").replaceAll("\\n", ""));
}
return login;

View File

@@ -73,6 +73,18 @@ class AwsEc2AuthenticationUnitTests {
assertThat(authentication.getEc2Login()).containsEntry("pkcs7", "Hello, world").containsKey("nonce").hasSize(2);
}
@Test
void shouldCleanUpIdentityResponse() {
this.mockRest.expect(requestTo("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")) //
.andExpect(method(HttpMethod.GET)) //
.andRespond(withSuccess().body("Hello, \r\r\n\nworld"));
AwsEc2Authentication authentication = new AwsEc2Authentication(this.restTemplate);
assertThat(authentication.getEc2Login()).containsEntry("pkcs7", "Hello, world");
}
@Test
void shouldContainRole() {