mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(memorydb): return HTTP 400 for not-found faults (#8110)
MemoryDbService threw ClusterNotFoundFault, UserNotFoundFault and ACLNotFoundFault with HTTP 404. The MemoryDB API Reference lists 400 for each, and botocore has no status for them. AWS's Smithy model gives them httpError(404), but botocore calls MemoryDB over awsJson1_1, which ignores HTTP binding traits. Use 400 at all eleven places that throw them: the Describe, Update and Delete actions, CreateACL with an unknown user, CreateCluster with an unknown ACL, and the three tag operations.
This commit is contained in:
1 parent
6ace00acc7
commit
ca0d166a33
2 files changed
+36
-11
No files matched your search
@@ -175,7 +175,7 @@ public class MemoryDbService {
|
||||
throw new AwsException("InvalidParameterValueException", "ClusterName is required.", 400);
|
||||
}
|
||||
return resourceGet(clusters, name, region).orElseThrow(() ->
|
||||
new AwsException("ClusterNotFoundFault", "Cluster not found.", 404));
|
||||
new AwsException("ClusterNotFoundFault", "Cluster not found.", 400));
|
||||
}
|
||||
|
||||
public Collection<Cluster> describeClusters(String filterName) {
|
||||
@@ -570,7 +570,7 @@ public class MemoryDbService {
|
||||
.or(() -> DEFAULT_USER.equals(filterName)
|
||||
? Optional.of(List.of(builtinDefaultUser(region)))
|
||||
: Optional.empty())
|
||||
.orElseThrow(() -> new AwsException("UserNotFoundFault", "User not found.", 404));
|
||||
.orElseThrow(() -> new AwsException("UserNotFoundFault", "User not found.", 400));
|
||||
}
|
||||
migrateLegacyUsers(region);
|
||||
List<User> all = new ArrayList<>();
|
||||
@@ -589,7 +589,7 @@ public class MemoryDbService {
|
||||
"The default user cannot be deleted.", 400);
|
||||
}
|
||||
User user = resourceGet(users, name, region).orElseThrow(() ->
|
||||
new AwsException("UserNotFoundFault", "User not found.", 404));
|
||||
new AwsException("UserNotFoundFault", "User not found.", 400));
|
||||
users.delete(key(region, name));
|
||||
LOG.infov("MemoryDB user {0} deleted", name);
|
||||
return user;
|
||||
@@ -619,7 +619,7 @@ public class MemoryDbService {
|
||||
"Duplicate user name " + userName + " in ACL.", 400);
|
||||
}
|
||||
if (!userExists(userName, region)) {
|
||||
throw new AwsException("UserNotFoundFault", "User " + userName + " not found.", 404);
|
||||
throw new AwsException("UserNotFoundFault", "User " + userName + " not found.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,7 +646,7 @@ public class MemoryDbService {
|
||||
.or(() -> DEFAULT_ACL.equals(filterName)
|
||||
? Optional.of(List.of(builtinOpenAccessAcl(region)))
|
||||
: Optional.empty())
|
||||
.orElseThrow(() -> new AwsException("ACLNotFoundFault", "ACL not found.", 404));
|
||||
.orElseThrow(() -> new AwsException("ACLNotFoundFault", "ACL not found.", 400));
|
||||
}
|
||||
migrateLegacyAcls(region);
|
||||
List<Acl> all = new ArrayList<>();
|
||||
@@ -665,7 +665,7 @@ public class MemoryDbService {
|
||||
"The open-access ACL cannot be deleted.", 400);
|
||||
}
|
||||
Acl acl = resourceGet(acls, name, region).orElseThrow(() ->
|
||||
new AwsException("ACLNotFoundFault", "ACL not found.", 404));
|
||||
new AwsException("ACLNotFoundFault", "ACL not found.", 400));
|
||||
if (!clustersUsingAcl(name, region).isEmpty()) {
|
||||
throw new AwsException("InvalidACLStateFault",
|
||||
"ACL " + name + " is associated with one or more clusters.", 400);
|
||||
@@ -793,7 +793,7 @@ public class MemoryDbService {
|
||||
|
||||
private void requireAclExists(String aclName, String region) {
|
||||
if (!DEFAULT_ACL.equals(aclName) && resourceGet(acls, aclName, region).isEmpty()) {
|
||||
throw new AwsException("ACLNotFoundFault", "ACL " + aclName + " not found.", 404);
|
||||
throw new AwsException("ACLNotFoundFault", "ACL " + aclName + " not found.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -851,13 +851,13 @@ public class MemoryDbService {
|
||||
if (resource.startsWith("user/")) {
|
||||
User user = resourceGet(users, resource.substring("user/".length()), region)
|
||||
.filter(u -> resourceArn.equals(u.getArn()))
|
||||
.orElseThrow(() -> new AwsException("UserNotFoundFault", "User not found.", 404));
|
||||
.orElseThrow(() -> new AwsException("UserNotFoundFault", "User not found.", 400));
|
||||
return new TaggedResource(user.getTags(), () -> users.put(key(region, user.getName()), user));
|
||||
}
|
||||
if (resource.startsWith("acl/")) {
|
||||
Acl acl = resourceGet(acls, resource.substring("acl/".length()), region)
|
||||
.filter(a -> resourceArn.equals(a.getArn()))
|
||||
.orElseThrow(() -> new AwsException("ACLNotFoundFault", "ACL not found.", 404));
|
||||
.orElseThrow(() -> new AwsException("ACLNotFoundFault", "ACL not found.", 400));
|
||||
return new TaggedResource(acl.getTags(), () -> acls.put(key(region, acl.getName()), acl));
|
||||
}
|
||||
Cluster cluster = clusterByArn(resourceArn);
|
||||
@@ -876,13 +876,13 @@ public class MemoryDbService {
|
||||
throw new IllegalArgumentException("ARN owner mismatch");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("ClusterNotFoundFault", "Cluster not found.", 404);
|
||||
throw new AwsException("ClusterNotFoundFault", "Cluster not found.", 400);
|
||||
}
|
||||
migrateLegacyClusters(currentRegion());
|
||||
return clusters.scan(k -> k.startsWith(currentRegion() + ":")).stream()
|
||||
.filter(c -> resourceArn.equals(c.getArn()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("ClusterNotFoundFault", "Cluster not found.", 404));
|
||||
.orElseThrow(() -> new AwsException("ClusterNotFoundFault", "Cluster not found.", 400));
|
||||
}
|
||||
|
||||
private void startBackend(Cluster cluster, boolean authRequired) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.floci.aws.services.memorydb.model.User;
|
||||
import io.floci.aws.services.memorydb.proxy.MemoryDbProxyManager;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -206,6 +207,24 @@ class MemoryDbServiceTest {
|
||||
assertEquals("ACLNotFoundFault", acl.jsonType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void notFoundFaultsAnswer400() {
|
||||
String arn = "arn:aws:memorydb:us-east-1:000000000000:";
|
||||
assertNotFoundFault("ClusterNotFoundFault", () -> service.getCluster("missing", "us-east-1"));
|
||||
assertNotFoundFault("ClusterNotFoundFault", () -> service.listTags(arn + "cluster/missing"));
|
||||
assertNotFoundFault("ClusterNotFoundFault",
|
||||
() -> service.listTags("arn:aws:memorydb:eu-west-1:000000000000: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"));
|
||||
assertNotFoundFault("UserNotFoundFault", () -> service.listTags(arn + "user/missing"));
|
||||
assertNotFoundFault("ACLNotFoundFault", () -> service.describeAcls("missing", "us-east-1"));
|
||||
assertNotFoundFault("ACLNotFoundFault", () -> service.deleteAcl("missing", "us-east-1"));
|
||||
assertNotFoundFault("ACLNotFoundFault",
|
||||
() -> service.createCluster(cluster("a-cluster", "missing"), "us-east-1"));
|
||||
assertNotFoundFault("ACLNotFoundFault", () -> service.listTags(arn + "acl/missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccessClusterRequiresNoAuth() {
|
||||
Cluster spec = new Cluster();
|
||||
@@ -645,6 +664,12 @@ class MemoryDbServiceTest {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
private void assertNotFoundFault(String code, Executable call) {
|
||||
AwsException ex = assertThrows(AwsException.class, call);
|
||||
assertEquals(code, ex.jsonType());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithoutDockerDaemonStillReachesAvailable() {
|
||||
// tryStart() returns null when no Docker daemon is reachable. The cluster record is
|
||||
|
||||
Reference in new issue
Block a user