From 1ccd6d38550b8d7321a93b91cda1c5124ab377b6 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Sun, 1 Nov 2026 07:06:38 -0600 Subject: [PATCH] fix(autoscaling): use the modeled XML namespace (#7180) * fix(autoscaling): use the modeled XML namespace Promote the complete retained fork #269 namespace correction and exact Query success/error/catalog assertions. Original feature by Jackson Price , authored 2026-10-28; original source commit d094b6168031df46c708d4dce056580d7e631853 retained unchanged. Co-authored-by: Jackson Price Signed-off-by: Andre Kurait * test(autoscaling): share modeled namespace assertions Share the package namespace assertion across the Query handler and integration tests. Preserve root and all-descendant checks, the returned Element, and all existing populated, empty and error response assertions. Signed-off-by: Andre Kurait Signed-off-by: Andre Kurait --------- Signed-off-by: Andre Kurait Signed-off-by: Andre Kurait --- docs/services/autoscaling.md | 2 + .../floci/core/common/AwsNamespaces.java | 2 +- .../ServiceCatalogRoutingIntegrationTest.java | 8 ++++ .../AutoScalingIntegrationTest.java | 37 +++++++++++++------ .../AutoScalingQueryHandlerTest.java | 36 +++++++++++++++++- .../autoscaling/AutoScalingXmlAssertions.java | 26 +++++++++++++ 6 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingXmlAssertions.java diff --git a/docs/services/autoscaling.md b/docs/services/autoscaling.md index c918ed3ec9..005c98e29a 100644 --- a/docs/services/autoscaling.md +++ b/docs/services/autoscaling.md @@ -4,6 +4,8 @@ Floci implements the EC2 Auto Scaling API — stored-state management for launch **Protocol:** Query — `POST /` with `Action=` form parameter, credential scope `autoscaling` +**XML namespace:** `http://autoscaling.amazonaws.com/doc/2011-01-01/`, as declared by the AWS service model. + **ARN formats:** - `arn:aws:autoscaling:::autoScalingGroup::autoScalingGroupName/` diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsNamespaces.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsNamespaces.java index c7118c8612..7d9c05a4c1 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsNamespaces.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsNamespaces.java @@ -22,7 +22,7 @@ public final class AwsNamespaces { * in this namespace, never in the 2015-12-01 one. */ public static final String ELB_CLASSIC = "http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/"; public static final String ELB_V2 = "https://elasticloadbalancing.amazonaws.com/doc/2015-12-01/"; - public static final String AUTOSCALING = "https://autoscaling.amazonaws.com/doc/2011-01-01/"; + public static final String AUTOSCALING = "http://autoscaling.amazonaws.com/doc/2011-01-01/"; public static final String ELASTIC_BEANSTALK = "https://elasticbeanstalk.amazonaws.com/docs/2010-12-01/"; public static final String ROUTE53 = "https://route53.amazonaws.com/doc/2013-04-01/"; public static final String CLOUDFRONT = "http://cloudfront.amazonaws.com/doc/2020-05-31/"; diff --git a/src/test/java/io/github/hectorvent/floci/core/common/ServiceCatalogRoutingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/ServiceCatalogRoutingIntegrationTest.java index f07b0fedd4..39595a4d71 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/ServiceCatalogRoutingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/ServiceCatalogRoutingIntegrationTest.java @@ -80,6 +80,14 @@ class ServiceCatalogRoutingIntegrationTest { assertTrue(catalog.byCredentialScope("cognito-idp").orElseThrow().supportsProtocol(ServiceProtocol.QUERY)); } + @Test + void autoScalingUsesModeledQueryNamespace() { + ServiceDescriptor descriptor = catalog.byCredentialScope("autoscaling").orElseThrow(); + + assertEquals(ServiceProtocol.QUERY, descriptor.defaultProtocol()); + assertEquals("http://autoscaling.amazonaws.com/doc/2011-01-01/", descriptor.xmlNamespace()); + } + @Test void rdsDataResolvesAsRestJsonByCredentialScope() { ServiceDescriptor descriptor = catalog.byCredentialScope("rds-data").orElseThrow(); diff --git a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingIntegrationTest.java index b5f6a1392a..b4dd2781a8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingIntegrationTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import static io.github.hectorvent.floci.services.autoscaling.AutoScalingXmlAssertions.assertModeledNamespace; import static io.restassured.RestAssured.given; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -32,8 +33,8 @@ class AutoScalingIntegrationTest { @Test @Order(1) - void createLaunchConfiguration() { - given() + void createLaunchConfiguration() throws Exception { + String xml = given() .formParam("Action", "CreateLaunchConfiguration") .formParam("LaunchConfigurationName", "my-lc") .formParam("ImageId", "ami-12345678") @@ -44,7 +45,10 @@ class AutoScalingIntegrationTest { .post("/") .then() .statusCode(200) - .body(containsString("CreateLaunchConfigurationResponse")); + .body(containsString("CreateLaunchConfigurationResponse")) + .extract().asString(); + + assertModeledNamespace(xml); } @Test @@ -134,8 +138,8 @@ class AutoScalingIntegrationTest { @Test @Order(44) - void launchConfigurationRejectsInvalidInstanceMonitoringBoolean() { - given() + void launchConfigurationRejectsInvalidInstanceMonitoringBoolean() throws Exception { + String xml = given() .formParam("Action", "CreateLaunchConfiguration") .formParam("LaunchConfigurationName", "my-lc-invalid-monitoring") .formParam("ImageId", "ami-12345678") @@ -146,7 +150,10 @@ class AutoScalingIntegrationTest { .post("/") .then() .statusCode(400) - .body(containsString("ValidationError")); + .body(containsString("ValidationError")) + .extract().asString(); + + assertModeledNamespace(xml); } @Test @@ -192,8 +199,8 @@ class AutoScalingIntegrationTest { @Test @Order(4) - void describeAutoScalingGroups() { - given() + void describeAutoScalingGroups() throws Exception { + String xml = given() .formParam("Action", "DescribeAutoScalingGroups") .formParam("AutoScalingGroupNames.member.1", "my-asg") .header("Authorization", AUTH) @@ -208,7 +215,10 @@ class AutoScalingIntegrationTest { .body(containsString("0")) .body(containsString("3")) .body(containsString("env")) - .body(containsString("test")); + .body(containsString("test")) + .extract().asString(); + + assertModeledNamespace(xml); } @Test @@ -1201,8 +1211,8 @@ class AutoScalingIntegrationTest { @Test @Order(40) - void describeAutoScalingGroupsEmpty() { - given() + void describeAutoScalingGroupsEmpty() throws Exception { + String xml = given() .formParam("Action", "DescribeAutoScalingGroups") .formParam("AutoScalingGroupNames.member.1", "my-asg") .header("Authorization", AUTH) @@ -1210,7 +1220,10 @@ class AutoScalingIntegrationTest { .post("/") .then() .statusCode(200) - .body(not(containsString("my-asg"))); + .body(not(containsString("my-asg"))) + .extract().asString(); + + assertModeledNamespace(xml); } private static String createLaunchTemplate(String name) { diff --git a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandlerTest.java index 875bcb7bc0..09faae56fe 100644 --- a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandlerTest.java @@ -6,10 +6,14 @@ import io.github.hectorvent.floci.services.autoscaling.model.AsgOptionalFields; import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.Test; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import java.util.List; import java.util.Map; +import static io.github.hectorvent.floci.services.autoscaling.AutoScalingXmlAssertions.XML_NAMESPACE; +import static io.github.hectorvent.floci.services.autoscaling.AutoScalingXmlAssertions.assertModeledNamespace; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,6 +22,23 @@ class AutoScalingQueryHandlerTest { private static final String REGION = "us-east-1"; + @Test + void describeAutoScalingInstancesEmptyUsesModeledNamespace() throws Exception { + AutoScalingService service = new AutoScalingService(); + service.regionResolver = new RegionResolver(REGION, "000000000000"); + AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service); + + Response response = handler.handle("DescribeAutoScalingInstances", new MultivaluedHashMap<>(), REGION); + + assertEquals(200, response.getStatus()); + String xml = (String) response.getEntity(); + Element root = assertModeledNamespace(xml); + NodeList collections = root.getElementsByTagNameNS(XML_NAMESPACE, "AutoScalingInstances"); + assertEquals(1, collections.getLength()); + Element instances = (Element) collections.item(0); + assertEquals(0, instances.getElementsByTagName("*").getLength()); + } + @Test void startAndDescribeInstanceRefreshUseAwsQueryXmlShape() { AutoScalingService service = new AutoScalingService(); @@ -84,7 +105,7 @@ class AutoScalingQueryHandlerTest { } @Test - void updateAutoScalingGroupRejectsDesiredConfigurationChangeDuringActiveInstanceRefresh() { + void updateAutoScalingGroupRejectsDesiredConfigurationChangeDuringActiveInstanceRefresh() throws Exception { AutoScalingService service = new AutoScalingService(); service.regionResolver = new RegionResolver(REGION, "000000000000"); service.createAutoScalingGroup(REGION, @@ -137,10 +158,11 @@ class AutoScalingQueryHandlerTest { String xml = (String) response.getEntity(); assertTrue(xml.contains("ValidationError")); assertTrue(xml.contains(AutoScalingService.ACTIVE_INSTANCE_REFRESH_DESIRED_CONFIGURATION_MESSAGE)); + assertModeledNamespace(xml); } @Test - void describeAutoScalingGroupsIncludesInstanceLaunchTemplateMetadata() { + void describeAutoScalingGroupsIncludesInstanceLaunchTemplateMetadata() throws Exception { AutoScalingService service = new AutoScalingService(); service.regionResolver = new RegionResolver(REGION, "000000000000"); service.createAutoScalingGroup(REGION, @@ -186,6 +208,16 @@ class AutoScalingQueryHandlerTest { assertTrue(xml.contains("")); assertTrue(xml.contains("lt-current")); assertTrue(xml.contains("7")); + assertModeledNamespace(xml); + + MultivaluedHashMap instanceParams = new MultivaluedHashMap<>(); + instanceParams.add("InstanceIds.member.1", "i-current"); + Response instancesResponse = handler.handle("DescribeAutoScalingInstances", instanceParams, REGION); + + assertEquals(200, instancesResponse.getStatus()); + String instancesXml = (String) instancesResponse.getEntity(); + assertTrue(instancesXml.contains("i-current")); + assertModeledNamespace(instancesXml); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingXmlAssertions.java b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingXmlAssertions.java new file mode 100644 index 0000000000..6ca9bc05a3 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingXmlAssertions.java @@ -0,0 +1,26 @@ +package io.github.hectorvent.floci.services.autoscaling; + +import io.github.hectorvent.floci.core.common.XmlParser; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +final class AutoScalingXmlAssertions { + + static final String XML_NAMESPACE = "http://autoscaling.amazonaws.com/doc/2011-01-01/"; + + private AutoScalingXmlAssertions() { + } + + static Element assertModeledNamespace(String xml) throws Exception { + Element root = XmlParser.parseDocument(xml).getDocumentElement(); + assertEquals(XML_NAMESPACE, root.getNamespaceURI()); + NodeList descendants = root.getElementsByTagName("*"); + for (int i = 0; i < descendants.getLength(); i++) { + assertEquals(XML_NAMESPACE, descendants.item(i).getNamespaceURI(), + descendants.item(i).getNodeName()); + } + return root; + } +}