mirror of
https://github.com/floci-io/floci.git
synced 2026-12-05 19:18:01 -05:00
test(apigateway): cover HTTPS validation with VPC links (#5057)
* test(apigateway): cover private HTTPS certificate validation * test(apigateway): clarify TLS scope and verify deleted links --------- Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
1 parent
d53ea39be9
commit
39ac662165
1 file changed
+98
-1
+98
-1
@@ -20,10 +20,13 @@ import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -45,9 +48,13 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Covers the two REST integration transport settings AWS documents that Floci previously accepted
|
||||
@@ -56,6 +63,9 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
* <p>The TLS case matters because {@code HttpProxyInvoker} uses a default {@code HttpClient}: an
|
||||
* HTTPS backend presenting a self-signed certificate was unreachable with no way to opt out, which
|
||||
* is the common shape for an internal service behind a private CA.
|
||||
*
|
||||
* <p>The VPC link cases cover link validation and TLS settings on the integration URI.
|
||||
* Floci forwards to that URI directly; these fixtures do not test routing through a link target.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ApiGatewayIntegrationTransportOptionsTest {
|
||||
@@ -80,8 +90,10 @@ class ApiGatewayIntegrationTransportOptionsTest {
|
||||
private static int nameConstrainedRootTlsPort;
|
||||
private static int nameConstrainedIntermediateTlsPort;
|
||||
private static int permissiveIntermediateTlsPort;
|
||||
private static final AtomicInteger tlsBackendHits = new AtomicInteger();
|
||||
|
||||
private final List<String> createdApis = new ArrayList<>();
|
||||
private final List<String> createdLinks = new ArrayList<>();
|
||||
|
||||
@BeforeAll
|
||||
static void startBackends() throws Exception {
|
||||
@@ -92,7 +104,10 @@ class ApiGatewayIntegrationTransportOptionsTest {
|
||||
|
||||
tlsServer = HttpsServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
tlsServer.setHttpsConfigurator(new HttpsConfigurator(selfSignedContext()));
|
||||
tlsServer.createContext("/", exchange -> respond(exchange, 200, "{\"tls\":\"ok\"}"));
|
||||
tlsServer.createContext("/", exchange -> {
|
||||
tlsBackendHits.incrementAndGet();
|
||||
respond(exchange, 200, "{\"tls\":\"ok\"}");
|
||||
});
|
||||
tlsServer.start();
|
||||
tlsPort = tlsServer.getAddress().getPort();
|
||||
|
||||
@@ -391,6 +406,88 @@ class ApiGatewayIntegrationTransportOptionsTest {
|
||||
given().when().delete("/restapis/" + apiId).then().statusCode(202);
|
||||
}
|
||||
createdApis.clear();
|
||||
for (String linkId : createdLinks) {
|
||||
given().when().delete("/vpclinks/" + linkId).then().statusCode(202);
|
||||
}
|
||||
createdLinks.clear();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"selfSigned, false, 502",
|
||||
"selfSigned, true, 200",
|
||||
"privateCa, true, 200",
|
||||
"wrongHostname, true, 502",
|
||||
"expired, true, 502",
|
||||
"nonSigningRoot, true, 502",
|
||||
"keyUsagelessRoot, true, 502",
|
||||
"constrainedIntermediate, true, 502",
|
||||
"permissiveIntermediate, true, 200",
|
||||
"constrainedRoot, true, 502"
|
||||
})
|
||||
void httpsCertificateValidationWithAvailableVpcLink(String certificateCase,
|
||||
boolean skipIssuanceCheck, int expectedStatus) {
|
||||
int port = switch (certificateCase) {
|
||||
case "selfSigned" -> tlsPort;
|
||||
case "privateCa" -> privateCaTlsPort;
|
||||
case "wrongHostname" -> wrongHostTlsPort;
|
||||
case "expired" -> expiredTlsPort;
|
||||
case "nonSigningRoot" -> nonSigningRootTlsPort;
|
||||
case "keyUsagelessRoot" -> keyUsagelessRootTlsPort;
|
||||
case "constrainedIntermediate" -> nameConstrainedIntermediateTlsPort;
|
||||
case "permissiveIntermediate" -> permissiveIntermediateTlsPort;
|
||||
case "constrainedRoot" -> nameConstrainedRootTlsPort;
|
||||
default -> throw new IllegalArgumentException("Unknown certificate case: " + certificateCase);
|
||||
};
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String linkId = createVpcLink("tls-link-" + suffix);
|
||||
String extras = ",\"connectionType\":\"VPC_LINK\",\"connectionId\":\"" + linkId + "\"";
|
||||
if (skipIssuanceCheck) {
|
||||
extras += ",\"tlsConfig\":{\"insecureSkipVerification\":true}";
|
||||
}
|
||||
String apiId = createApi("private-tls-" + suffix,
|
||||
"https://localhost:" + port + "/{proxy}", extras);
|
||||
|
||||
ValidatableResponse response = given().when().get("/execute-api/" + apiId + "/test/thing")
|
||||
.then().statusCode(expectedStatus);
|
||||
if (expectedStatus == 200) {
|
||||
response.body("tls", equalTo("ok"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void httpsBackendIsNotCalledAfterVpcLinkIsDeleted() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String linkId = createVpcLink("tls-deleted-link-" + suffix);
|
||||
String apiId = createApi("tls-deleted-link-" + suffix,
|
||||
"https://localhost:" + tlsPort + "/{proxy}",
|
||||
",\"connectionType\":\"VPC_LINK\",\"connectionId\":\"" + linkId
|
||||
+ "\",\"tlsConfig\":{\"insecureSkipVerification\":true}");
|
||||
|
||||
given().when().get("/execute-api/" + apiId + "/test/thing")
|
||||
.then().statusCode(200).body("tls", equalTo("ok"));
|
||||
int hitsBeforeDeletion = tlsBackendHits.get();
|
||||
given().when().delete("/vpclinks/" + linkId).then().statusCode(202);
|
||||
createdLinks.remove(linkId);
|
||||
|
||||
given().when().get("/execute-api/" + apiId + "/test/thing")
|
||||
.then().statusCode(502)
|
||||
.body("message", equalTo("Invalid VPC link identifier specified: " + linkId));
|
||||
assertEquals(hitsBeforeDeletion, tlsBackendHits.get(),
|
||||
"A deleted VPC link must prevent the HTTPS backend call");
|
||||
}
|
||||
|
||||
private String createVpcLink(String name) {
|
||||
String linkId = given().contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"%s","targetArns":[
|
||||
"arn:aws:elasticloadbalancing:us-east-1:000000000000:loadbalancer/net/test/abc"
|
||||
]}
|
||||
""".formatted(name))
|
||||
.when().post("/vpclinks")
|
||||
.then().statusCode(202).extract().path("id");
|
||||
createdLinks.add(linkId);
|
||||
return linkId;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user