mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(core): serve the shared /_floci control-plane contract (#8431)
Health at /_floci/health, /_localstack/health and /health gains status UP
and cloud aws from one shared body. GET /_floci/tls-cert serves the same
PEM as ca.pem, as application/x-pem-file, and answers the shared 404
{tlsEnabled, error, message} when TLS is off.
A path under /_floci or /_localstack that no route serves answers a JSON
404 from ControlPlaneNotFoundFilter instead of falling through to S3, and
S3VirtualHostFilter leaves those paths alone, so a virtual-hosted request
can no longer address a key under _floci/ or _localstack/. The endpoints
are documented on one page.
This commit is contained in:
1 parent
70924d4afc
commit
7e146f8180
11 files changed
+467
-13
No files matched your search
@@ -0,0 +1,75 @@
|
||||
# Control-Plane Endpoints
|
||||
|
||||
Floci serves its own endpoints for health, metadata, initialization hooks, state reset and the TLS certificate under `/_floci`. The four Floci emulators (AWS, Azure, GCP, OCI) serve the same contract at the same paths, so one probe or one script works against any of them; the `cloud` field says which emulator answered.
|
||||
|
||||
Every path below is also served under `/_localstack`, the LocalStack-compatible prefix, with the same body.
|
||||
|
||||
| Endpoint | Answers |
|
||||
|---|---|
|
||||
| `GET /_floci/health` | 200 JSON: `status`, `cloud`, `services`, `version`, plus `edition` and `original_edition` |
|
||||
| `GET /_floci/info` | 200 JSON: the emulator manifest of the [Console Contract](../ui/console-contract.md#the-manifest) |
|
||||
| `GET /_floci/init` | 200 JSON: the state of the [initialization hooks](initialization-hooks.md) |
|
||||
| `POST /_floci/state/reset` | 200 `{"status":"OK"}` after clearing every service's state |
|
||||
| `POST /_floci/state/nuke` | the same as `state/reset` |
|
||||
| `GET /_floci/tls-cert` | 200 `application/x-pem-file`: the certificate to trust for HTTPS; 404 JSON when TLS is off |
|
||||
| `GET /_floci/ca.pem` | 200 `text/plain`: the same PEM, served whether or not TLS is on |
|
||||
| any other path under `/_floci` | 404 JSON `{"error":"NotFound","path":"<path>"}` |
|
||||
|
||||
## Health
|
||||
|
||||
```bash
|
||||
curl -s http://localhost:4566/_floci/health
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "UP",
|
||||
"cloud": "aws",
|
||||
"services": {"s3": "running", "sqs": "running", "...": "..."},
|
||||
"edition": "community",
|
||||
"original_edition": "floci-always-free",
|
||||
"version": "2.4.0"
|
||||
}
|
||||
```
|
||||
|
||||
- `status`: `UP`. An emulator that can detect a failed service answers `DOWN` with a 503 and a `problems` object; Floci AWS has no such signal, so it always answers `UP`.
|
||||
- `cloud`: `aws`. The other emulators answer `azure`, `gcp` and `oci`.
|
||||
- `services`: each service name with `running` (enabled) or `available` (disabled).
|
||||
|
||||
`GET /health` serves the same body.
|
||||
|
||||
## Readiness
|
||||
|
||||
`GET /_floci/init` reports `completed.ready: true` once the ready hooks have run. Wait on it, rather than on health, when a test needs the resources those hooks create. The Docker image's `HEALTHCHECK` uses it.
|
||||
|
||||
## State reset
|
||||
|
||||
`POST /_floci/state/reset` clears every service's state, stops the containers Floci started, and runs each service's bootstrap again, so the emulator looks freshly started. It answers 409 and changes nothing when a service cannot be reset, such as DynamoDB with the DynamoDB Local backend.
|
||||
|
||||
## TLS certificate
|
||||
|
||||
```bash
|
||||
curl -s http://localhost:4566/_floci/tls-cert -o floci-ca.pem
|
||||
```
|
||||
|
||||
With `FLOCI_TLS_ENABLED=true` this is the PEM described in [TLS / HTTPS](tls.md): the local CA, or your certificate followed by the local CA when you provide one. With TLS off it answers 404:
|
||||
|
||||
```json
|
||||
{"tlsEnabled": false, "error": "TLS is not enabled", "message": "..."}
|
||||
```
|
||||
|
||||
`GET /_floci/ca.pem` keeps serving the local CA either way, because it also signs the certificates Floci issues (ACM, IoT).
|
||||
|
||||
## Unknown paths
|
||||
|
||||
A path under `/_floci` or `/_localstack` that Floci does not serve answers 404 JSON instead of reaching S3:
|
||||
|
||||
```json
|
||||
{"error": "NotFound", "path": "/_floci/helth"}
|
||||
```
|
||||
|
||||
No S3 bucket can be named `_floci`, so this shadows no bucket. A virtual-hosted request (`mybucket.s3.localhost.floci.io`) whose path starts with `/_floci/` or `/_localstack/` is also served by the control plane rather than read as an object key; address such a key path-style instead.
|
||||
|
||||
## Other endpoints under `/_floci`
|
||||
|
||||
These are specific to Floci AWS and are not part of the shared contract: the [web console](../ui/index.md) at `/_floci/ui`, `/_floci/ecr/gc`, the EKS cluster webhooks under `/_floci/eks/`, the AppSync resolver callback, and the AWS Sign-In consent page. `GET /_floci/diagnose` and `GET /_floci/config` return `{}` for LocalStack compatibility.
|
||||
@@ -8,7 +8,7 @@ Floci supports optional TLS, enabling `https://` for all REST/JSON/Query endpoin
|
||||
docker run -e FLOCI_TLS_ENABLED=true -p 4566:4566 floci/floci:latest
|
||||
```
|
||||
|
||||
Then point your SDK at `https://localhost:4566` and trust Floci's local CA in the processes that talk to it. Every certificate Floci issues (its HTTPS endpoint, every ACM certificate and every IoT device certificate) chains to that one CA:
|
||||
Then point your SDK at `https://localhost:4566` and trust Floci's local CA in the processes that talk to it. Every certificate Floci issues (its HTTPS endpoint, every ACM certificate and every IoT device certificate) chains to that one CA. With TLS on, `GET /_floci/tls-cert` serves the same PEM as `application/x-pem-file`, at the path every Floci emulator uses (see [Control-Plane Endpoints](endpoints.md)):
|
||||
|
||||
```bash
|
||||
curl -s http://localhost:4566/_floci/ca.pem -o floci-root-ca.pem
|
||||
|
||||
@@ -122,7 +122,7 @@ attributes. Access-token claims are exposed under `context.token`.
|
||||
|
||||
Policy stores and all child resources use Floci's configured storage backend. Keys include the
|
||||
resolved AWS Region and are wrapped by the normal account-aware storage layer, preserving
|
||||
account and Region isolation. `/_floci/reset` clears policy stores, policies, templates,
|
||||
account and Region isolation. `POST /_floci/state/reset` clears policy stores, policies, templates,
|
||||
aliases, identity sources, and idempotency records with other resettable service state.
|
||||
|
||||
A policy store's ARN carries no Region, `arn:aws:verifiedpermissions::<account>:policy-store/<id>`,
|
||||
|
||||
@@ -86,6 +86,7 @@ nav:
|
||||
- Docker Compose: configuration/docker-compose.md
|
||||
- Docker Configuration: configuration/docker.md
|
||||
- Ports Reference: configuration/ports.md
|
||||
- Control-Plane Endpoints: configuration/endpoints.md
|
||||
- Multi-Account Isolation: configuration/multi-account.md
|
||||
- AWS Partitions: configuration/partitions.md
|
||||
- Storage Modes: configuration/storage.md
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.floci.aws.lifecycle;
|
||||
|
||||
import io.floci.aws.core.common.RoutedResource;
|
||||
import jakarta.annotation.Priority;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Priorities;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.container.ResourceInfo;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Answers a path under the control-plane prefixes ({@code /_floci}, {@code /_localstack}) that no
|
||||
* control-plane resource serves with a JSON 404, the catch-all every Floci emulator shares. Without
|
||||
* it the request falls through to S3's path-style routes as an object in a bucket named
|
||||
* {@code _floci}, which no S3 bucket can be named, and a client probing a wrong path reads an S3 XML
|
||||
* error. A control-plane resource is one whose route is declared under the prefix: the lifecycle
|
||||
* endpoints, the console, and the ECR, EKS, AppSync and sign-in routes.
|
||||
* <p>
|
||||
* Runs after route matching, so {@link ResourceInfo} names the route, and before the protocol claim
|
||||
* and every signature or IAM check, which would otherwise judge the request as an S3 call.
|
||||
*/
|
||||
@Provider
|
||||
@Priority(Priorities.AUTHENTICATION - 300)
|
||||
public class ControlPlaneNotFoundFilter implements ContainerRequestFilter {
|
||||
|
||||
static final List<String> PREFIXES = List.of("_floci", "_localstack");
|
||||
private static final String PREFIX_TEMPLATE = "{prefix:(_floci|_localstack)}";
|
||||
|
||||
@Context
|
||||
ResourceInfo resourceInfo;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext ctx) {
|
||||
String path = ctx.getUriInfo().getPath();
|
||||
if (!isControlPlanePath(path)) {
|
||||
return;
|
||||
}
|
||||
Class<?> resourceClass = RoutedResource.resourceClass(resourceInfo);
|
||||
if (resourceClass != null && isControlPlaneRoute(resourceClass, resourceInfo.getResourceMethod())) {
|
||||
return;
|
||||
}
|
||||
ctx.abortWith(notFound(path));
|
||||
}
|
||||
|
||||
/** True for {@code /_floci}, {@code /_localstack} and any path under them, with or without the leading slash. */
|
||||
public static boolean isControlPlanePath(String path) {
|
||||
String relative = stripLeadingSlash(path);
|
||||
for (String prefix : PREFIXES) {
|
||||
if (relative.equals(prefix) || relative.startsWith(prefix + "/")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isControlPlaneRoute(Class<?> resourceClass, Method method) {
|
||||
String route = stripLeadingSlash(template(resourceClass.getAnnotation(Path.class)));
|
||||
if (route.isEmpty() && method != null) {
|
||||
route = stripLeadingSlash(template(method.getAnnotation(Path.class)));
|
||||
}
|
||||
return route.startsWith(PREFIX_TEMPLATE) || isControlPlanePath(route);
|
||||
}
|
||||
|
||||
static Response notFound(String path) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("error", "NotFound");
|
||||
body.put("path", path.startsWith("/") ? path : "/" + path);
|
||||
return Response.status(Response.Status.NOT_FOUND).type(MediaType.APPLICATION_JSON).entity(body).build();
|
||||
}
|
||||
|
||||
private static String template(Path path) {
|
||||
return path == null ? "" : path.value();
|
||||
}
|
||||
|
||||
private static String stripLeadingSlash(String path) {
|
||||
return path.startsWith("/") ? path.substring(1) : path;
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public class EmulatorInfoController {
|
||||
private static final Logger LOG = Logger.getLogger(EmulatorInfoController.class);
|
||||
static final int MANIFEST_VERSION = 1;
|
||||
static final int CONSOLE_CONTRACT = 2;
|
||||
private static final String PEM_FILE = "application/x-pem-file";
|
||||
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final InitLifecycleState initLifecycleState;
|
||||
@@ -73,11 +74,7 @@ public class EmulatorInfoController {
|
||||
@GET
|
||||
@Path("/health")
|
||||
public Response health() {
|
||||
return Response.ok(Map.of(
|
||||
"services", serviceRegistry.getServices(),
|
||||
"edition", "community",
|
||||
"original_edition", "floci-always-free",
|
||||
"version", version)).build();
|
||||
return Response.ok(HealthController.body(serviceRegistry.getServices(), version)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -113,7 +110,7 @@ public class EmulatorInfoController {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("manifest_version", MANIFEST_VERSION);
|
||||
body.put("console_contract", CONSOLE_CONTRACT);
|
||||
body.put("cloud", "aws");
|
||||
body.put("cloud", HealthController.CLOUD);
|
||||
body.put("emulator", "floci");
|
||||
body.put("version", version);
|
||||
body.put("edition", "community");
|
||||
@@ -171,6 +168,43 @@ public class EmulatorInfoController {
|
||||
@Path("/ca.pem")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String caPem() throws IOException, GeneralSecurityException {
|
||||
return trustBundle();
|
||||
}
|
||||
|
||||
/**
|
||||
* The certificate a client must trust for this emulator's HTTPS endpoint, at the path every Floci
|
||||
* emulator serves it under: the same PEM as {@code ca.pem}, as {@code application/x-pem-file}. With
|
||||
* TLS off there is no HTTPS endpoint to trust, so it answers the 404 the other emulators answer;
|
||||
* {@code ca.pem} keeps serving the local CA, which still signs the certificates Floci issues.
|
||||
*/
|
||||
@GET
|
||||
@Path("/tls-cert")
|
||||
@Produces({PEM_FILE, MediaType.APPLICATION_JSON})
|
||||
public Response tlsCert() {
|
||||
if (!config.tls().enabled()) {
|
||||
return tlsCertUnavailable(false, "TLS is not enabled",
|
||||
"Floci is serving plain HTTP only. Set FLOCI_TLS_ENABLED=true and restart to serve HTTPS "
|
||||
+ "on the same port. GET /_floci/ca.pem serves the local CA either way.");
|
||||
}
|
||||
try {
|
||||
return Response.ok(trustBundle()).type(PEM_FILE).build();
|
||||
} catch (IOException | GeneralSecurityException e) {
|
||||
LOG.warnv(e, "Cannot read the TLS certificate served at /_floci/tls-cert");
|
||||
return tlsCertUnavailable(true, "TLS certificate not available",
|
||||
"TLS is enabled but the certificate cannot be read. Check floci.tls.cert-path and the "
|
||||
+ "startup logs.");
|
||||
}
|
||||
}
|
||||
|
||||
private static Response tlsCertUnavailable(boolean tlsEnabled, String error, String message) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("tlsEnabled", tlsEnabled);
|
||||
body.put("error", error);
|
||||
body.put("message", message);
|
||||
return Response.status(Response.Status.NOT_FOUND).type(MediaType.APPLICATION_JSON).entity(body).build();
|
||||
}
|
||||
|
||||
private String trustBundle() throws IOException, GeneralSecurityException {
|
||||
String localCa = certificateAuthority.caPem();
|
||||
Optional<String> userCertificate = userCertificatePath();
|
||||
if (userCertificate.isEmpty()) {
|
||||
|
||||
@@ -9,12 +9,16 @@ import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Path("/health")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class HealthController {
|
||||
|
||||
/** The {@code cloud} this emulator names itself with in its health and info bodies. */
|
||||
static final String CLOUD = "aws";
|
||||
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final String version;
|
||||
|
||||
@@ -26,10 +30,24 @@ public class HealthController {
|
||||
|
||||
@GET
|
||||
public Response health() {
|
||||
return Response.ok(Map.of(
|
||||
"services", serviceRegistry.getServices(),
|
||||
"edition", "community",
|
||||
"original_edition", "floci-always-free",
|
||||
"version", version)).build();
|
||||
return Response.ok(body(serviceRegistry.getServices(), version)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The health body of the Floci control-plane contract, shared by bare {@code /health} and
|
||||
* {@code /_floci/health} so the two cannot drift. {@code status}, {@code cloud}, {@code services}
|
||||
* and {@code version} are the fields every Floci emulator serves; {@code edition} and
|
||||
* {@code original_edition} are this emulator's own and stay as they always were. Floci has no
|
||||
* failure signal of its own, so {@code status} is always {@code UP}.
|
||||
*/
|
||||
static Map<String, Object> body(Map<String, String> services, String version) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("status", "UP");
|
||||
body.put("cloud", CLOUD);
|
||||
body.put("services", services);
|
||||
body.put("edition", "community");
|
||||
body.put("original_edition", "floci-always-free");
|
||||
body.put("version", version);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.floci.aws.core.common.RequestUriRewrite;
|
||||
import io.floci.aws.core.common.ResteasyRequests;
|
||||
import io.floci.aws.core.common.dns.EmbeddedDnsServer;
|
||||
import io.floci.aws.core.common.docker.ContainerDetector;
|
||||
import io.floci.aws.lifecycle.ControlPlaneNotFoundFilter;
|
||||
import io.floci.aws.services.apigateway.ApiGatewayCustomDomainFilter;
|
||||
import io.floci.aws.services.cloudfront.CloudFrontDistributionFilter;
|
||||
import io.floci.aws.services.cognito.CognitoCustomDomainFilter;
|
||||
@@ -169,6 +170,13 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
// The Floci control plane is matched before any service routing, so a health probe sent with a
|
||||
// bucket-style Host still reaches it. The cost is that a virtual-hosted request cannot address
|
||||
// an object key under _floci/ or _localstack/; a path-style request still can.
|
||||
if (ControlPlaneNotFoundFilter.isControlPlanePath(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// A higher-priority Host filter (API Gateway custom domain, CloudFront, Cognito custom
|
||||
// domain) may have already routed this request. Use its server-side marker rather than
|
||||
// trusting a user-controlled path prefix.
|
||||
|
||||
@@ -88,6 +88,21 @@ class TlsUserCertIntegrationTest {
|
||||
"the local CA served is the one on disk");
|
||||
}
|
||||
|
||||
@Test
|
||||
void tlsCertServesTheSamePemAsCaPemAsAPemFile() {
|
||||
String caPem = given().when().get("/_floci/ca.pem").then().statusCode(200).extract().asString();
|
||||
|
||||
String tlsCert = given()
|
||||
.when()
|
||||
.get("/_floci/tls-cert")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(startsWith("application/x-pem-file"))
|
||||
.extract().asString();
|
||||
|
||||
assertEquals(caPem, tlsCert);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ssmPutParameterOverHttps() {
|
||||
given()
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package io.floci.aws.lifecycle;
|
||||
|
||||
import io.floci.aws.config.FlociVersion;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* The Floci control-plane contract every emulator serves under {@code /_floci} (floci-loft decision
|
||||
* 0022): the required fields, the legacy aliases, the JSON 404 catch-all and its precedence over S3.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ControlPlaneContractIntegrationTest {
|
||||
|
||||
private static final String NOT_FOUND_BODY = "\"error\":\"NotFound\"";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/_floci/health", "/_localstack/health", "/health"})
|
||||
void health_carriesTheRequiredFieldsOnEveryPath(String path) {
|
||||
given()
|
||||
.when().get(path)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("status", equalTo("UP"))
|
||||
.body("cloud", equalTo("aws"))
|
||||
.body("version", equalTo(FlociVersion.current()))
|
||||
.body("services.s3", equalTo("running"))
|
||||
.body("edition", equalTo("community"))
|
||||
.body("original_edition", equalTo("floci-always-free"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/_floci/info", "/_localstack/info"})
|
||||
void info_namesTheCloud(String path) {
|
||||
given()
|
||||
.when().get(path)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("cloud", equalTo("aws"))
|
||||
.body("version", equalTo(FlociVersion.current()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/_floci/tls-cert", "/_localstack/tls-cert"})
|
||||
void tlsCert_answersTheSharedNotFoundShapeWhenTlsIsOff(String path) {
|
||||
given()
|
||||
.when().get(path)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.contentType("application/json")
|
||||
.body("tlsEnabled", equalTo(false))
|
||||
.body("error", equalTo("TLS is not enabled"))
|
||||
.body("message", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void caPem_staysServedWhenTlsIsOff() {
|
||||
given()
|
||||
.when().get("/_floci/ca.pem")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(startsWith("text/plain"))
|
||||
.body(containsString("BEGIN CERTIFICATE"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/_floci/helth", "/_localstack/helth", "/_floci/state/nope", "/_floci/a/b/c", "/_floci"})
|
||||
void unknownGet_answersTheJsonNotFound(String path) {
|
||||
given()
|
||||
.when().get(path)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.contentType("application/json")
|
||||
.body("error", equalTo("NotFound"))
|
||||
.body("path", equalTo(path));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownPathWithAnyMethod_answersTheJsonNotFound() {
|
||||
given().body("x").when().put("/_floci/nope").then()
|
||||
.statusCode(404).body("error", equalTo("NotFound")).body("path", equalTo("/_floci/nope"));
|
||||
given().when().delete("/_floci/nope").then()
|
||||
.statusCode(404).body("error", equalTo("NotFound"));
|
||||
given().contentType("application/json").body("{}").when().post("/_localstack/nope").then()
|
||||
.statusCode(404).body("error", equalTo("NotFound")).body("path", equalTo("/_localstack/nope"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bucketStyleHost_doesNotCaptureTheControlPlane() {
|
||||
given()
|
||||
.header("Host", "mybucket.s3.localhost")
|
||||
.when().get("/_floci/health")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("status", equalTo("UP"))
|
||||
.body("cloud", equalTo("aws"));
|
||||
|
||||
given()
|
||||
.header("Host", "mybucket.s3.localhost")
|
||||
.when().get("/_floci/helth")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("error", equalTo("NotFound"))
|
||||
.body("path", equalTo("/_floci/helth"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherRoutesUnderTheControlPlanePrefix_stillAnswer() {
|
||||
given().when().get("/_floci/ui/status").then()
|
||||
.statusCode(200).body("ready", notNullValue());
|
||||
given().when().get("/_localstack/ui/status").then()
|
||||
.statusCode(200).body("ready", notNullValue());
|
||||
given().when().post("/_floci/ecr/gc").then()
|
||||
.body(not(containsString(NOT_FOUND_BODY)));
|
||||
given().when().get("/_floci/eks/clusters/no-such-cluster/oidc/.well-known/openid-configuration").then()
|
||||
.body(not(containsString(NOT_FOUND_BODY)));
|
||||
given().when().get("/_floci/signin/consent").then()
|
||||
.body(not(containsString(NOT_FOUND_BODY)));
|
||||
given().when().get("/_floci/signin/signin.css").then()
|
||||
.statusCode(200).contentType(startsWith("text/css"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stateReset_clearsAResourceCreatedBeforeIt() {
|
||||
String queue = "control-plane-reset-" + System.nanoTime();
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSQS.CreateQueue")
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.body("{\"QueueName\": \"" + queue + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().when().post("/_floci/state/reset").then()
|
||||
.statusCode(200).body("status", equalTo("OK"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSQS.GetQueueUrl")
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.body("{\"QueueName\": \"" + queue + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package io.floci.aws.lifecycle;
|
||||
|
||||
import io.floci.aws.services.ecr.registry.EcrGcController;
|
||||
import io.floci.aws.services.s3.S3Controller;
|
||||
import io.floci.aws.services.signin.SigninController;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ControlPlaneNotFoundFilterTest {
|
||||
|
||||
@Test
|
||||
void controlPlanePaths() {
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlanePath("/_floci"));
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlanePath("/_floci/health"));
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlanePath("_localstack/init"));
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlanePath("/_flocix/health"));
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlanePath("/_Floci/health"));
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlanePath("/mybucket/_floci/health"));
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlanePath("/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void routesDeclaredUnderThePrefixAreControlPlane() {
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlaneRoute(EmulatorInfoController.class, method(EmulatorInfoController.class, "health")));
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlaneRoute(UiController.class, null));
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlaneRoute(EcrGcController.class, null));
|
||||
assertTrue(ControlPlaneNotFoundFilter.isControlPlaneRoute(SigninController.class, method(SigninController.class, "consentPage")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3PathStyleRoutesAreNot() {
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlaneRoute(S3Controller.class, method(S3Controller.class, "getObject")));
|
||||
assertFalse(ControlPlaneNotFoundFilter.isControlPlaneRoute(SigninController.class, method(SigninController.class, "authorize")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void notFoundBodyNamesThePath() {
|
||||
Response response = ControlPlaneNotFoundFilter.notFound("/_floci/helth");
|
||||
assertEquals(404, response.getStatus());
|
||||
assertEquals(Map.of("error", "NotFound", "path", "/_floci/helth"), response.getEntity());
|
||||
}
|
||||
|
||||
private static Method method(Class<?> type, String name) {
|
||||
return Arrays.stream(type.getDeclaredMethods())
|
||||
.filter(m -> m.getName().equals(name))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user