mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): list a service-managed stack set's targets and tags in DescribeStackSet (#7242)
AWS returns a stack set's tags and the recorded root and OU deployment targets of a service-managed stack set. Read the same saved targets that ListStackSetAutoDeploymentTargets reports. Replace the tag map on UpdateStackSet instead of clearing and refilling a map that a concurrent DescribeStackSet may be reading. Copy the request's tags so the published map is independent of later request changes. Cover both response members, an update interleaved with tag iteration, and request-map isolation with regression tests. Use the shared account-scoped InMemoryStorageFactory for the added regression tests instead of a private factory copy.
This commit is contained in:
1 parent
5bcb83b932
commit
918ce95b53
5 files changed
+136
-3
No files matched your search
+46
@@ -433,6 +433,52 @@ class CloudFormationServiceManagedStackSetsIntegrationTest {
|
||||
.body(containsString("all features"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServiceManagedStackSetListsTargetedOrganizationalUnitsAndTags() {
|
||||
String management = "616161616161";
|
||||
organizations(management, "CreateOrganization", "{\"FeatureSet\":\"ALL\"}")
|
||||
.post("/").then().statusCode(200);
|
||||
String rootId = organizations(management, "ListRoots", "{}")
|
||||
.post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("Roots[0].Id");
|
||||
String targetOu = organizations(management, "CreateOrganizationalUnit",
|
||||
"{\"ParentId\":\"" + rootId + "\",\"Name\":\"DescribeTarget\"}")
|
||||
.post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("OrganizationalUnit.Id");
|
||||
cloudFormation(management, "ActivateOrganizationsAccess")
|
||||
.post("/").then().statusCode(200);
|
||||
|
||||
String stackSet = "describe-targets-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
cloudFormation(management, "CreateStackSet")
|
||||
.formParam("StackSetName", stackSet)
|
||||
.formParam("TemplateBody", queueTemplate("unused"))
|
||||
.formParam("PermissionModel", "SERVICE_MANAGED")
|
||||
.formParam("AutoDeployment.Enabled", "true")
|
||||
.formParam("Tags.member.1.Key", "DeploymentVersion")
|
||||
.formParam("Tags.member.1.Value", "20261101-abcdef12")
|
||||
.post("/").then().statusCode(200);
|
||||
cloudFormation(management, "DescribeStackSet")
|
||||
.formParam("StackSetName", stackSet)
|
||||
.post("/").then().statusCode(200)
|
||||
.body(containsString("<Tags>"))
|
||||
.body(containsString("<Key>DeploymentVersion</Key>"))
|
||||
.body(containsString("<Value>20261101-abcdef12</Value>"))
|
||||
.body(not(containsString("<OrganizationalUnitIds>")));
|
||||
|
||||
cloudFormation(management, "CreateStackInstances")
|
||||
.formParam("StackSetName", stackSet)
|
||||
.formParam("DeploymentTargets.OrganizationalUnitIds.member.1", rootId)
|
||||
.formParam("DeploymentTargets.OrganizationalUnitIds.member.2", targetOu)
|
||||
.formParam("Regions.member.1", REGION)
|
||||
.post("/").then().statusCode(200);
|
||||
cloudFormation(management, "DescribeStackSet")
|
||||
.formParam("StackSetName", stackSet)
|
||||
.post("/").then().statusCode(200)
|
||||
.body(containsString("<OrganizationalUnitIds>"))
|
||||
.body(containsString("<member>" + rootId + "</member>"))
|
||||
.body(containsString("<member>" + targetOu + "</member>"));
|
||||
}
|
||||
|
||||
private String createAccount(String email, String name) {
|
||||
JsonPath response = organizations("CreateAccount",
|
||||
"{\"Email\":\"" + email + "\",\"AccountName\":\"" + name + "\"}")
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.testing.InMemoryStorageFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class StackSetTagReadTest {
|
||||
private static final String SET = "tag-snapshot";
|
||||
private StackSetService service;
|
||||
private Map<String, String> initialTags;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new StackSetService(mock(CloudFormationService.class), new InMemoryStorageFactory("000000000000"));
|
||||
initialTags = new LinkedHashMap<>();
|
||||
initialTags.put("team", "red");
|
||||
initialTags.put("owner", "original");
|
||||
service.createStackSet(SET, "{\"Resources\":{}}", null, null, initialTags, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingTagsLeavesAnActiveReadOnItsOriginalMap() {
|
||||
Map<String, String> tagsBeingRead = service.describeStackSet(SET).getTags();
|
||||
Iterator<Map.Entry<String, String>> iterator = tagsBeingRead.entrySet().iterator();
|
||||
assertEquals("team", iterator.next().getKey());
|
||||
Map<String, String> updated = Map.of("team", "blue", "owner", "updated");
|
||||
|
||||
service.updateStackSet(SET, null, null, null, updated, null);
|
||||
|
||||
Map.Entry<String, String> remaining = assertDoesNotThrow(iterator::next);
|
||||
assertEquals("owner", remaining.getKey());
|
||||
assertEquals("original", remaining.getValue());
|
||||
assertEquals(initialTags, tagsBeingRead);
|
||||
assertEquals(updated, service.describeStackSet(SET).getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingTagsCopiesTheRequestMap() {
|
||||
Map<String, String> updated = new LinkedHashMap<>();
|
||||
updated.put("team", "blue");
|
||||
service.updateStackSet(SET, null, null, null, updated, null);
|
||||
|
||||
updated.put("team", "green");
|
||||
|
||||
assertEquals(Map.of("team", "blue"), service.describeStackSet(SET).getTags());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user