mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(apigateway): keep execute-api independent of IoT enablement (#7076)
Resolve the shared signing scope to API Gateway when no explicit service route owns the request. Preserve IoT route ownership and custom-domain authentication across existing invocation paths. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
7f785fdc4c
commit
3d0fbad532
3 files changed
+39
No files matched your search
@@ -829,6 +829,11 @@ public class ResolvedServiceCatalog {
|
||||
}
|
||||
|
||||
public Optional<ServiceDescriptor> byCredentialScope(String credentialScope) {
|
||||
// IoT also accepts execute-api signatures, but its explicit REST routes identify IoT.
|
||||
// Without a matched service route, this signing scope belongs to API Gateway.
|
||||
if ("execute-api".equals(credentialScope)) {
|
||||
return catalog.byExternalKey("apigateway");
|
||||
}
|
||||
return catalog.byCredentialScope(credentialScope);
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.services.apigateway.ApiGatewayController;
|
||||
import io.github.hectorvent.floci.services.iot.IotController;
|
||||
import io.github.hectorvent.floci.services.s3.S3Controller;
|
||||
import io.github.hectorvent.floci.services.securityadmin.SecurityAdminController;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
@@ -16,6 +17,14 @@ class ServiceCatalogRoutingIntegrationTest {
|
||||
@Inject
|
||||
ResolvedServiceCatalog catalog;
|
||||
|
||||
@Test
|
||||
void executeApiScopeDefaultsToApiGatewayWhileIotRetainsItsRouteOwnership() {
|
||||
assertEquals("apigateway", catalog.byCredentialScope("execute-api").orElseThrow().externalKey());
|
||||
ServiceDescriptor iot = catalog.byResourceClass(IotController.class).orElseThrow();
|
||||
assertEquals("iot", iot.externalKey());
|
||||
assertTrue(iot.credentialScopes().contains("execute-api"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetResolutionExtractsMatchingPrefixAndAction() {
|
||||
ServiceCatalog.TargetMatch match = catalog.matchTarget("AWSEvents.PutEvents").orElseThrow();
|
||||
|
||||
+25
@@ -2,11 +2,15 @@ package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.github.hectorvent.floci.testutil.ExecuteApiRequestSigner;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
@@ -22,9 +26,17 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
* against the signed form, so the rewritten path must not leak into the canonical request.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(ApiGatewayCustomDomainIamAuthIntegrationTest.IotDisabled.class)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayCustomDomainIamAuthIntegrationTest {
|
||||
|
||||
public static class IotDisabled implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.services.iot.enabled", "false");
|
||||
}
|
||||
}
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCESS_KEY = "test";
|
||||
private static final String SECRET_KEY = "test";
|
||||
@@ -48,6 +60,7 @@ class ApiGatewayCustomDomainIamAuthIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.extract().path("item[0].id");
|
||||
createMockMethod(rootId, "iam", "AWS_IAM");
|
||||
createMockMethod(rootId, "public", "NONE");
|
||||
|
||||
String deploymentId = given().contentType(ContentType.JSON)
|
||||
.body("{\"description\":\"v1\"}")
|
||||
@@ -150,6 +163,18 @@ class ApiGatewayCustomDomainIamAuthIntegrationTest {
|
||||
.header("x-amzn-ErrorType", "InvalidSignatureException");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/execute-api/%s/prod/", "/_aws/execute-api/%s/prod/",
|
||||
"/restapis/%s/prod/_user_request_/"})
|
||||
@Order(15)
|
||||
void invocationControllersHonorMethodAuthenticationWithIotDisabled(String template) throws Exception {
|
||||
String path = template.formatted(apiId);
|
||||
given().header("Host", "localhost").headers(signedHeaders(path + "iam", "localhost"))
|
||||
.get(path + "iam").then().statusCode(200).body("reached", equalTo("integration"));
|
||||
given().get(path + "iam").then().statusCode(403);
|
||||
given().get(path + "public").then().statusCode(200).body("reached", equalTo("integration"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(999)
|
||||
void cleanup() {
|
||||
|
||||
Reference in new issue
Block a user