From a06ffbdf9bf3bbd472ec9d6511cc3f714717e188 Mon Sep 17 00:00:00 2001 From: Erica Eaton Date: Wed, 28 Sep 2022 18:21:24 -0400 Subject: [PATCH 1/2] modify region parsing for endpoints in vpc --- .../java/com/amazonaws/util/AwsHostNameUtils.java | 14 +++++++++++++- .../com/amazonaws/util/AwsHostNameUtilsTest.java | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/aws-android-sdk-core/src/main/java/com/amazonaws/util/AwsHostNameUtils.java b/aws-android-sdk-core/src/main/java/com/amazonaws/util/AwsHostNameUtils.java index 99977713d1..1d40de5a6b 100644 --- a/aws-android-sdk-core/src/main/java/com/amazonaws/util/AwsHostNameUtils.java +++ b/aws-android-sdk-core/src/main/java/com/amazonaws/util/AwsHostNameUtils.java @@ -32,6 +32,8 @@ public class AwsHostNameUtils { private static final Pattern S3_ENDPOINT_PATTERN = Pattern.compile("^(?:.+\\.)?s3[.-]([a-z0-9-]+)$"); + + private static final String VPC_NAME = "vpce"; /** * @deprecated in favor of {@link #parseRegionName(String, String)}. @@ -117,8 +119,18 @@ private static String parseStandardRegionName(final String fragment) { return "us-east-1"; } - // host was 'service.[region].amazonaws.com'. + // host was 'service.[region].amazonaws.com'. or 'service.[region].vpce.amazonaws.com' String region = fragment.substring(index + 1); + if (region.equals(VPC_NAME)) { + String[] partsOfFragment = fragment.split("\\."); + if (partsOfFragment.length >= 2) { + // host was 'service.[region].vpce.amazonaws.com' + region = partsOfFragment[partsOfFragment.length - 2]; + } else { + // guess us-east-1 for lack of a better option + return "us-east-1"; + } + } // Special case for iam.us-gov.amazonaws.com, which is actually // us-gov-west-1. diff --git a/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java b/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java index c89f2edfa1..2782c8495c 100644 --- a/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java +++ b/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java @@ -94,6 +94,12 @@ public void testStandard() { "bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3")); } + @Test + public void testVpceEndpoint() { + assertEquals("eu-central-1", AwsHostNameUtils.parseRegionName( + "bucket.vpce-0415caba8c0-i1xu.s3.eu-central-1.vpce.amazonaws.com", "s3")); + } + @Test public void testBJS() { // Verify that BJS endpoints parse correctly even though they're From 44d541f25cfed1ee375481489b4610ad4adcdef5 Mon Sep 17 00:00:00 2001 From: Erica Eaton Date: Wed, 28 Sep 2022 18:24:13 -0400 Subject: [PATCH 2/2] modify vpc endpoint test --- .../test/java/com/amazonaws/util/AwsHostNameUtilsTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java b/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java index 2782c8495c..9fd963d396 100644 --- a/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java +++ b/aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java @@ -95,9 +95,9 @@ public void testStandard() { } @Test - public void testVpceEndpoint() { - assertEquals("eu-central-1", AwsHostNameUtils.parseRegionName( - "bucket.vpce-0415caba8c0-i1xu.s3.eu-central-1.vpce.amazonaws.com", "s3")); + public void testVpcEndpoint() { + assertEquals("us-west-2", AwsHostNameUtils.parseRegionName( + "bucket.vpce-1234.s3.us-west-2.vpce.amazonaws.com", "s3")); } @Test