diff --git a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java index e3ab611d4c..e9dd12a45f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java +++ b/src/main/java/io/github/hectorvent/floci/services/opensearch/OpenSearchService.java @@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper; import io.github.hectorvent.floci.core.common.AwsArnUtils; import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.AwsRegions; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend; import io.github.hectorvent.floci.core.storage.StorageBackend; @@ -149,10 +150,12 @@ public class OpenSearchService implements ResourceProvider { if (config.services().opensearch().mock()) { domain.setProcessing(false); + domain.setEndpoint(synthesizedEndpoint(domainName, region)); } else { domain.setProcessing(true); if (!domainManager.tryStartDomain(domain)) { domain.setProcessing(false); + domain.setEndpoint(synthesizedEndpoint(domainName, region)); } } @@ -161,6 +164,24 @@ public class OpenSearchService implements ResourceProvider { return domain; } + /** + * The endpoint reported for a domain with no container behind it. Two cases reach this: the + * service is mocked, and no Docker daemon is reachable, which is the only condition under which + * {@link OpenSearchDomainManager#tryStartDomain} returns false rather than rethrowing. + * + *
It reports an AWS-shaped endpoint in place of a blank one,
+ * {@code search- Covers the two cases with no container behind the domain: the service is mocked, and no Docker
+ * daemon is reachable. Both once reported {@code Processing false} alongside {@code Endpoint ""},
+ * which AWS never returns, leaving a client that reads the endpoint with an empty string to address.
+ */
+@QuarkusTest
+class OpenSearchDomainEndpointIntegrationTest {
+
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/es/aws4_request";
+ private static final String DOMAIN = "endpoint-probe";
+
+ @AfterEach
+ void cleanup() {
+ given().header("Authorization", AUTH_HEADER)
+ .when().delete("/2021-01-01/opensearch/domain/" + DOMAIN);
+ }
+
+ /** The DNS suffix comes from the region's partition, so a China region must not report .com. */
+ @Test
+ void theEndpointTakesItsDnsSuffixFromThePartition() {
+ String domain = "endpoint-cn-probe";
+ try {
+ given()
+ .header("Authorization",
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/cn-north-1/es/aws4_request")
+ .contentType("application/json")
+ .body("{\"DomainName\":\"" + domain + "\",\"EngineVersion\":\"OpenSearch_2.11\"}")
+ .when()
+ .post("/2021-01-01/opensearch/domain")
+ .then()
+ .statusCode(200)
+ .body("DomainStatus.Endpoint", endsWith(".cn-north-1.es.amazonaws.com.cn"));
+ } finally {
+ given().header("Authorization",
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/cn-north-1/es/aws4_request")
+ .when().delete("/2021-01-01/opensearch/domain/" + domain);
+ }
+ }
+
+ @Test
+ void createAndDescribeReportAnEndpointBesideProcessingFalse() {
+ given()
+ .header("Authorization", AUTH_HEADER)
+ .contentType("application/json")
+ .body("{\"DomainName\":\"" + DOMAIN + "\",\"EngineVersion\":\"OpenSearch_2.11\"}")
+ .when()
+ .post("/2021-01-01/opensearch/domain")
+ .then()
+ .statusCode(200)
+ .body("DomainStatus.Processing", is(false))
+ .body("DomainStatus.Endpoint", not(emptyString()))
+ .body("DomainStatus.Endpoint", startsWith("search-" + DOMAIN + "-"))
+ .body("DomainStatus.Endpoint", endsWith(".us-east-1.es.amazonaws.com"));
+
+ String first = given()
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .get("/2021-01-01/opensearch/domain/" + DOMAIN)
+ .then()
+ .statusCode(200)
+ .body("DomainStatus.Processing", is(false))
+ .body("DomainStatus.Endpoint", not(emptyString()))
+ .extract().path("DomainStatus.Endpoint");
+
+ // The waiter polls, so the value has to be the same every time.
+ given()
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .get("/2021-01-01/opensearch/domain/" + DOMAIN)
+ .then()
+ .statusCode(200)
+ .body("DomainStatus.Endpoint", is(first));
+ }
+}