mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(memorydb): return InvalidARNFault when ResourceArn is not a MemoryDB ARN (#8163)
ListTags, TagResource and UntagResource answered ClusterNotFoundFault
for a ResourceArn that is not a MemoryDB ARN at all: one that does not
parse, or one that names another service. botocore lists
InvalidARNFault on all three operations ("The specified Amazon
Resource Name (ARN) is not valid."), and the MemoryDB API Reference
gives it HTTP 400.
clusterByArn now answers InvalidARNFault unless the value is an ARN
naming memorydb. A MemoryDB ARN of another Region or account still
answers ClusterNotFoundFault.
This commit is contained in:
1 parent
1820d6470d
commit
355c180db3
2 files changed
+21
-7
No files matched your search
@@ -869,13 +869,11 @@ public class MemoryDbService {
|
||||
if (resourceArn == null) {
|
||||
throw new AwsException("InvalidParameterValueException", "ResourceArn is required.", 400);
|
||||
}
|
||||
try {
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(resourceArn);
|
||||
if (!"memorydb".equals(arn.service()) || !currentRegion().equals(arn.region())
|
||||
|| !regionResolver.getAccountId().equals(arn.accountId())) {
|
||||
throw new IllegalArgumentException("ARN owner mismatch");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (!AwsArnUtils.isArnFor(resourceArn, "memorydb")) {
|
||||
throw new AwsException("InvalidARNFault", "The specified ARN is not valid.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(resourceArn);
|
||||
if (!currentRegion().equals(arn.region()) || !regionResolver.getAccountId().equals(arn.accountId())) {
|
||||
throw new AwsException("ClusterNotFoundFault", "Cluster not found.", 400);
|
||||
}
|
||||
migrateLegacyClusters(currentRegion());
|
||||
|
||||
@@ -214,6 +214,8 @@ class MemoryDbServiceTest {
|
||||
assertNotFoundFault("ClusterNotFoundFault", () -> service.listTags(arn + "cluster/missing"));
|
||||
assertNotFoundFault("ClusterNotFoundFault",
|
||||
() -> service.listTags("arn:aws:memorydb:eu-west-1:000000000000:cluster/missing"));
|
||||
assertNotFoundFault("ClusterNotFoundFault",
|
||||
() -> service.listTags("arn:aws:memorydb:us-east-1:111111111111:cluster/missing"));
|
||||
assertNotFoundFault("UserNotFoundFault", () -> service.describeUsers("missing", "us-east-1"));
|
||||
assertNotFoundFault("UserNotFoundFault", () -> service.deleteUser("missing", "us-east-1"));
|
||||
assertNotFoundFault("UserNotFoundFault", () -> service.createAcl(acl("an-acl", "missing"), "us-east-1"));
|
||||
@@ -225,6 +227,20 @@ class MemoryDbServiceTest {
|
||||
assertNotFoundFault("ACLNotFoundFault", () -> service.listTags(arn + "acl/missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedOrOtherServiceArnRaisesInvalidArnFault() {
|
||||
for (String arn : List.of("not-an-arn", "arn:aws:s3:::bucket")) {
|
||||
for (Executable call : List.<Executable>of(
|
||||
() -> service.listTags(arn),
|
||||
() -> service.tagResource(arn, Map.of("env", "dev")),
|
||||
() -> service.untagResource(arn, List.of("env")))) {
|
||||
AwsException ex = assertThrows(AwsException.class, call);
|
||||
assertEquals("InvalidARNFault", ex.jsonType(), arn);
|
||||
assertEquals(400, ex.getHttpStatus(), arn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccessClusterRequiresNoAuth() {
|
||||
Cluster spec = new Cluster();
|
||||
|
||||
Reference in new issue
Block a user