|
35 | 35 | import static org.junit.Assert.assertEquals; |
36 | 36 | import static org.junit.Assert.assertNotNull; |
37 | 37 | import static org.junit.Assert.assertNull; |
38 | | -import static org.junit.Assert.assertThrows; |
39 | 38 | import static org.junit.Assert.assertTrue; |
40 | 39 | import static org.junit.Assert.fail; |
41 | 40 |
|
|
57 | 56 | import java.util.List; |
58 | 57 | import java.util.Map; |
59 | 58 | import org.junit.Test; |
60 | | -import org.junit.function.ThrowingRunnable; |
61 | 59 | import org.junit.runner.RunWith; |
62 | 60 | import org.junit.runners.JUnit4; |
63 | 61 |
|
@@ -106,28 +104,14 @@ public class AwsCredentialsTest extends BaseSerializationTest { |
106 | 104 | .build(); |
107 | 105 |
|
108 | 106 | @Test |
109 | | - public void test_awsCredentialSource_ipv6() { |
110 | | - // If no exception is thrown, it means the urls were valid. |
111 | | - new AwsCredentialSource(buildAwsIpv6CredentialSourceMap()); |
112 | | - } |
113 | | - |
114 | | - @Test |
115 | | - public void test_awsCredentialSource_invalid_urls() { |
| 107 | + public void test_awsCredentialSource() { |
116 | 108 | String keys[] = {"region_url", "url", "imdsv2_session_token_url"}; |
117 | 109 | for (String key : keys) { |
118 | 110 | Map<String, Object> credentialSourceWithInvalidUrl = buildAwsIpv6CredentialSourceMap(); |
119 | 111 | credentialSourceWithInvalidUrl.put(key, "https://badhost.com/fake"); |
120 | | - IllegalArgumentException e = |
121 | | - assertThrows( |
122 | | - IllegalArgumentException.class, |
123 | | - new ThrowingRunnable() { |
124 | | - @Override |
125 | | - public void run() throws Throwable { |
126 | | - new AwsCredentialSource(credentialSourceWithInvalidUrl); |
127 | | - } |
128 | | - }); |
129 | | - |
130 | | - assertEquals(String.format("Invalid host badhost.com for %s.", key), e.getMessage()); |
| 112 | + |
| 113 | + // Should succeed as no validation is done. |
| 114 | + new AwsCredentialSource(credentialSourceWithInvalidUrl); |
131 | 115 | } |
132 | 116 | } |
133 | 117 |
|
@@ -613,43 +597,6 @@ public void getAwsSecurityCredentials_fromEnvironmentVariables_noMetadataServerC |
613 | 597 | assertEquals("awsSessionToken", credentials.getToken()); |
614 | 598 | } |
615 | 599 |
|
616 | | - @Test |
617 | | - public void validateMetadataServerUrlIfAny_validOrEmptyUrls() { |
618 | | - String[] urls = { |
619 | | - "http://[fd00:ec2::254]/region", |
620 | | - "http://169.254.169.254", |
621 | | - "http://169.254.169.254/xyz", |
622 | | - " ", |
623 | | - "", |
624 | | - null |
625 | | - }; |
626 | | - for (String url : urls) { |
627 | | - AwsCredentialSource.validateMetadataServerUrlIfAny(url, "url"); |
628 | | - } |
629 | | - } |
630 | | - |
631 | | - @Test |
632 | | - public void validateMetadataServerUrlIfAny_invalidUrls() { |
633 | | - Map<String, String> urls = new HashMap<String, String>(); |
634 | | - urls.put("http://[fd00:ec2::255]/region", "[fd00:ec2::255]"); |
635 | | - urls.put("http://fake.com/region", "fake.com"); |
636 | | - urls.put("http://169.254.169.255", "169.254.169.255"); |
637 | | - |
638 | | - for (Map.Entry<String, String> entry : urls.entrySet()) { |
639 | | - IllegalArgumentException e = |
640 | | - assertThrows( |
641 | | - IllegalArgumentException.class, |
642 | | - new ThrowingRunnable() { |
643 | | - @Override |
644 | | - public void run() throws Throwable { |
645 | | - AwsCredentialSource.validateMetadataServerUrlIfAny(entry.getKey(), "url"); |
646 | | - } |
647 | | - }); |
648 | | - |
649 | | - assertEquals(String.format("Invalid host %s for url.", entry.getValue()), e.getMessage()); |
650 | | - } |
651 | | - } |
652 | | - |
653 | 600 | @Test |
654 | 601 | public void getAwsSecurityCredentials_fromMetadataServer() throws IOException { |
655 | 602 | MockExternalAccountCredentialsTransportFactory transportFactory = |
|
0 commit comments