Remove all newlines in PKCS7 from EC2MetaData.
Closes gh-571.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user