mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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 <jxnprice@amazon.com>, authored 2026-10-28; original source commit d094b6168031df46c708d4dce056580d7e631853 retained unchanged. Co-authored-by: Jackson Price <jxnprice@amazon.com> Signed-off-by: Andre Kurait <AndreKurait@gmail.com> * 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 <AndreKurait@gmail.com> Signed-off-by: Andre Kurait <akurait@amazon.com> --------- Signed-off-by: Andre Kurait <AndreKurait@gmail.com> Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
b987e822be
commit
1ccd6d3855
6 files changed
+96
-15
No files matched your search
@@ -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:<region>:<account>:autoScalingGroup:<uuid>:autoScalingGroupName/<name>`
|
||||
|
||||
@@ -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/";
|
||||
|
||||
+8
@@ -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();
|
||||
|
||||
+25
-12
@@ -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("<MinSize>0</MinSize>"))
|
||||
.body(containsString("<MaxSize>3</MaxSize>"))
|
||||
.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) {
|
||||
|
||||
+34
-2
@@ -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("<Code>ValidationError</Code>"));
|
||||
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("<LaunchTemplate>"));
|
||||
assertTrue(xml.contains("<LaunchTemplateId>lt-current</LaunchTemplateId>"));
|
||||
assertTrue(xml.contains("<Version>7</Version>"));
|
||||
assertModeledNamespace(xml);
|
||||
|
||||
MultivaluedHashMap<String, String> 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("<InstanceId>i-current</InstanceId>"));
|
||||
assertModeledNamespace(instancesXml);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+26
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user