mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(swf): accept legacy JSON target headers (#5728)
* fix(swf): accept legacy JSON target headers Signed-off-by: Andre Kurait <akurait@amazon.com> * fix(swf): reject unsupported CBOR and clarify missing targets Signed-off-by: Andre Kurait <akurait@amazon.com> * refactor(protocol): declare targeted plain JSON in the service catalog Signed-off-by: Andre Kurait <akurait@amazon.com> --------- Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
eca2199de6
commit
209ecd799b
12 files changed
+265
-5
No files matched your search
+24
@@ -122,6 +122,30 @@ class ProtocolClaimerIntegrationTest {
|
||||
null, "AmazonSSM.DescribeParameters", null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void botoSwfJsonClaimsOnlyTheDocumentedRootTarget() {
|
||||
String target = "com.amazonaws.swf.service.model.SimpleWorkflowService.RegisterActivityType";
|
||||
ProtocolClaim legacy = claim("POST", "/", "Application/JSON; charset=UTF-8",
|
||||
null, target, null).orElseThrow();
|
||||
assertEquals(WireProtocol.AWS_JSON_1_0, legacy.protocol());
|
||||
assertEquals("swf", legacy.service().externalKey());
|
||||
assertEquals("RegisterActivityType", legacy.operation());
|
||||
assertEquals(target, legacy.target());
|
||||
|
||||
assertTrue(claim("POST", "/", "text/plain", null, target, null).isEmpty());
|
||||
assertTrue(claim("POST", "/", "application/json", "rpc-v2-json", target, null).isEmpty());
|
||||
assertEquals("swf", claim("POST", "/", "application/json", null,
|
||||
"SimpleWorkflowService.RegisterActivityType", null).orElseThrow().service().externalKey());
|
||||
assertTrue(claim("POST", "/", "application/json", null,
|
||||
"com.amazonaws.swf.service.model.SimpleWorkflowServiceOther.RegisterActivityType", null).isEmpty());
|
||||
assertTrue(claim("POST", "/", "application/json", null,
|
||||
"AmazonSSM.DescribeParameters", null).isEmpty());
|
||||
assertEquals(WireProtocol.REST, claim("GET", "/", "application/json",
|
||||
null, target, null).orElseThrow().protocol());
|
||||
assertEquals(WireProtocol.REST, claim("POST", "/other", "application/json",
|
||||
null, target, null).orElseThrow().protocol());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownTargetStillClaimsProtocolWithoutService() {
|
||||
ProtocolClaim claim = claim("POST", "/", "application/x-amz-json-1.1",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ServiceCatalogTest {
|
||||
|
||||
@Test
|
||||
void plainJsonFormatIsDeclaredByTheDescriptor() {
|
||||
ServiceDescriptor legacy = descriptor("example", Set.of("Example.", "LegacyExample."),
|
||||
Set.of(ServiceProtocol.JSON, ServiceProtocol.PLAIN_JSON));
|
||||
ServiceDescriptor modern = descriptor("modern", Set.of("Modern."), Set.of(ServiceProtocol.JSON));
|
||||
ServiceCatalog catalog = new ServiceCatalog(List.of(legacy, modern));
|
||||
|
||||
assertEquals(legacy, catalog.matchPlainJsonTarget("Example.Read").orElseThrow().descriptor());
|
||||
assertEquals(legacy, catalog.matchPlainJsonTarget("LegacyExample.Read").orElseThrow().descriptor());
|
||||
assertTrue(catalog.matchPlainJsonTarget("Modern.Read").isEmpty());
|
||||
assertTrue(catalog.matchPlainJsonTarget("Unknown.Read").isEmpty());
|
||||
assertTrue(catalog.matchPlainJsonTarget(null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void moreSpecificTargetOwnsItsAcceptedFormats() {
|
||||
ServiceDescriptor legacy = descriptor("example", Set.of("Example."),
|
||||
Set.of(ServiceProtocol.JSON, ServiceProtocol.PLAIN_JSON));
|
||||
ServiceDescriptor modern = descriptor("specific", Set.of("Example.Specific."), Set.of(ServiceProtocol.JSON));
|
||||
ServiceCatalog catalog = new ServiceCatalog(List.of(legacy, modern));
|
||||
|
||||
assertEquals(modern, catalog.matchTarget("Example.Specific.Read").orElseThrow().descriptor());
|
||||
assertTrue(catalog.matchPlainJsonTarget("Example.Specific.Read").isEmpty());
|
||||
}
|
||||
|
||||
private static ServiceDescriptor descriptor(String name, Set<String> prefixes, Set<ServiceProtocol> protocols) {
|
||||
return new ServiceDescriptor(name, name, true, true, null, null, 0L, null,
|
||||
ServiceProtocol.JSON, protocols, prefixes, Set.of(name), Set.of(), Set.of());
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -58,6 +58,20 @@ class ServiceEnablementIntegrationTest {
|
||||
.body("message", equalTo("Service ecs is not enabled."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacySwfJsonRequestsAreRejectedWhenServiceDisabled() {
|
||||
given()
|
||||
.contentType("application/json; charset=UTF-8")
|
||||
.header("X-Amz-Target", "com.amazonaws.swf.service.model.SimpleWorkflowService.ListDomains")
|
||||
.body("{\"registrationStatus\":\"REGISTERED\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ServiceNotAvailableException"))
|
||||
.body("message", equalTo("Service swf is not enabled."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sqsQueueUrlJsonRequestsAreRejectedWhenServiceDisabled() {
|
||||
given()
|
||||
@@ -253,7 +267,8 @@ class ServiceEnablementIntegrationTest {
|
||||
"floci.services.lambda.enabled", "false",
|
||||
"floci.services.opensearch.enabled", "false",
|
||||
"floci.services.rds-data.enabled", "false",
|
||||
"floci.services.sqs.enabled", "false"
|
||||
"floci.services.sqs.enabled", "false",
|
||||
"floci.services.swf.enabled", "false"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
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 org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(StrictProtocolClaimingIntegrationTest.StrictClaimingProfile.class)
|
||||
class SwfLegacyProtocolIntegrationTest {
|
||||
|
||||
private static final String LEGACY_PREFIX = "com.amazonaws.swf.service.model.SimpleWorkflowService.";
|
||||
private static final String MODERN_PREFIX = "SimpleWorkflowService.";
|
||||
private static final String LEGACY_JSON = "application/json; charset=UTF-8";
|
||||
private static final String MODERN_JSON = "application/x-amz-json-1.0";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"application/json", LEGACY_JSON})
|
||||
void legacyRegistrationsShareStateWithModernClients(String mediaType) {
|
||||
String domain = "legacy-swf-" + UUID.randomUUID();
|
||||
call(mediaType, LEGACY_PREFIX, "RegisterDomain", """
|
||||
{"name":"%s","workflowExecutionRetentionPeriodInDays":"7"}
|
||||
""".formatted(domain)).then().statusCode(200).contentType("application/json");
|
||||
call(MODERN_JSON, MODERN_PREFIX, "DescribeDomain", "{\"name\":\"" + domain + "\"}")
|
||||
.then().statusCode(200).body("domainInfo.name", equalTo(domain));
|
||||
|
||||
call(mediaType, LEGACY_PREFIX, "RegisterActivityType", """
|
||||
{"domain":"%s","name":"work","version":"1"}
|
||||
""".formatted(domain)).then().statusCode(200);
|
||||
call(MODERN_JSON, MODERN_PREFIX, "DescribeActivityType", """
|
||||
{"domain":"%s","activityType":{"name":"work","version":"1"}}
|
||||
""".formatted(domain)).then().statusCode(200).body("typeInfo.status", equalTo("REGISTERED"));
|
||||
|
||||
call(MODERN_JSON, MODERN_PREFIX, "RegisterWorkflowType", """
|
||||
{"domain":"%s","name":"flow","version":"1"}
|
||||
""".formatted(domain)).then().statusCode(200);
|
||||
call(mediaType, LEGACY_PREFIX, "DescribeWorkflowType", """
|
||||
{"domain":"%s","workflowType":{"name":"flow","version":"1"}}
|
||||
""".formatted(domain)).then().statusCode(200).body("typeInfo.status", equalTo("REGISTERED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyDuplicateActivityRegistrationPreservesTypedBotoFaults() {
|
||||
String domain = "legacy-duplicate-" + UUID.randomUUID();
|
||||
String domainBody = """
|
||||
{"name":"%s","workflowExecutionRetentionPeriodInDays":"7"}
|
||||
""".formatted(domain);
|
||||
call(MODERN_JSON, MODERN_PREFIX, "RegisterDomain", domainBody).then().statusCode(200);
|
||||
String activity = "{\"domain\":\"" + domain + "\",\"name\":\"work\",\"version\":\"1\"}";
|
||||
call(MODERN_JSON, MODERN_PREFIX, "RegisterActivityType", activity).then().statusCode(200);
|
||||
call(LEGACY_JSON, LEGACY_PREFIX, "RegisterActivityType", activity).then().statusCode(400)
|
||||
.body("__type", equalTo("com.amazonaws.swf.base.model#TypeAlreadyExistsFault"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(textBlock = """
|
||||
SimpleWorkflowService., application/json
|
||||
SimpleWorkflowService., application/json; charset=UTF-8
|
||||
SimpleWorkflowService., application/x-amz-json-1.0
|
||||
com.amazonaws.swf.service.model.SimpleWorkflowService., application/json
|
||||
com.amazonaws.swf.service.model.SimpleWorkflowService., application/json; charset=UTF-8
|
||||
com.amazonaws.swf.service.model.SimpleWorkflowService., application/x-amz-json-1.0
|
||||
""")
|
||||
void acceptedWireFormatsShareDomainStateAndTypedFaults(String prefix, String mediaType) {
|
||||
String domain = "wire-swf-" + UUID.randomUUID();
|
||||
String registration = """
|
||||
{"name":"%s","workflowExecutionRetentionPeriodInDays":"7"}
|
||||
""".formatted(domain);
|
||||
call(MODERN_JSON, MODERN_PREFIX, "RegisterDomain", registration).then().statusCode(200);
|
||||
call(mediaType, prefix, "DescribeDomain", "{\"name\":\"" + domain + "\"}")
|
||||
.then().statusCode(200).body("domainInfo.name", equalTo(domain));
|
||||
call(mediaType, prefix, "RegisterDomain", registration).then().statusCode(400)
|
||||
.body("__type", equalTo("com.amazonaws.swf.base.model#DomainAlreadyExistsFault"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {LEGACY_PREFIX, MODERN_PREFIX})
|
||||
void cborDoesNotClaimSwfTargets(String prefix) throws Exception {
|
||||
byte[] response = given().contentType("application/x-amz-cbor-1.1")
|
||||
.header("X-Amz-Target", prefix + "ListDomains")
|
||||
.body(new byte[]{(byte) 0xbf, (byte) 0xff})
|
||||
.post("/").then().statusCode(404).contentType("application/x-amz-cbor-1.1")
|
||||
.extract().asByteArray();
|
||||
|
||||
assertEquals("UnknownOperationException",
|
||||
new ObjectMapper(new CBORFactory()).readTree(response).path("__type").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void plainJsonWithoutTargetReportsTheMissingHeader() {
|
||||
given().contentType(LEGACY_JSON).body("{}").post("/")
|
||||
.then().statusCode(404).body("message", equalTo("Missing X-Amz-Target header."));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"com.amazonaws.swf.service.model.SimpleWorkflowServiceOther.ListDomains",
|
||||
"AmazonSSM.DescribeParameters"
|
||||
})
|
||||
void plainJsonDoesNotClaimOtherTargets(String target) {
|
||||
call(LEGACY_JSON, "", target, "{}").then().statusCode(404);
|
||||
}
|
||||
|
||||
private static Response call(String mediaType, String prefix, String action, String body) {
|
||||
return given().contentType(mediaType)
|
||||
.header("X-Amz-Target", prefix + action)
|
||||
.header("Content-Encoding", "amz-1.0")
|
||||
.body(body).post("/");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user