fix(elasticache): honor SecurityGroupIds on ModifyReplicationGroup (#6467)

* fix(elasticache): honor SecurityGroupIds on ModifyReplicationGroup

A modify that names SecurityGroupIds now replaces the whole stored list
on the replication group, so DescribeCacheClusters reports the new
groups on every member with Status=active; a modify that names none
leaves the memberships untouched, which the Query protocol cannot
distinguish from an empty list anyway.

Closes #6463

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

* fix(elasticache): read the modify security groups through the shared parse

optionalSecurityGroupIds walked the two Query spellings a second time;
it now reuses parseSecurityGroupIds with the same isEmpty-to-null check
the user group lists use, and the new compatibility test declares its
responses with explicit types.

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

---------

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-25 16:55:00 -04:00
1 parent 796f203b76
commit f4cd3110e7
7 files changed
+154 -13

No files matched your search

@@ -111,6 +111,69 @@ class ElastiCacheMemberSecurityGroupsIntegrationTest {
}
}
@ParameterizedTest
@ValueSource(booleans = {false, true})
void sdkModifyReplacesSecurityGroupsOnEveryMember(boolean clusterEnabled) {
String groupId = groupId();
try (ElastiCacheClient client = client()) {
try {
client.createReplicationGroup(createRequest(groupId, clusterEnabled)
.securityGroupIds(SECURITY_GROUP_IDS).build());
client.modifyReplicationGroup(request -> request.replicationGroupId(groupId)
.securityGroupIds(List.of("sg-modified")));
assertMemberSecurityGroups(client, groupId, clusterEnabled ? 4 : 1, List.of("sg-modified"));
} finally {
deleteGroup(client, groupId);
}
}
}
@ParameterizedTest
@ValueSource(booleans = {false, true})
void modifyThatNamesNoSecurityGroupsKeepsTheMemberships(boolean clusterEnabled) {
String groupId = groupId();
try (ElastiCacheClient client = client()) {
try {
client.createReplicationGroup(createRequest(groupId, clusterEnabled)
.securityGroupIds(SECURITY_GROUP_IDS).build());
client.modifyReplicationGroup(request -> request.replicationGroupId(groupId));
assertMemberSecurityGroups(client, groupId, clusterEnabled ? 4 : 1, SECURITY_GROUP_IDS);
} finally {
deleteGroup(client, groupId);
}
}
}
@ParameterizedTest
@ValueSource(strings = {"SecurityGroupIds.SecurityGroupId", "SecurityGroupIds.member"})
void queryModifyReplacesTheWholeListOnEveryMember(String prefix) {
String groupId = groupId();
try (ElastiCacheClient client = client()) {
try {
client.createReplicationGroup(createRequest(groupId, false)
.securityGroupIds(SECURITY_GROUP_IDS).build());
given()
.port(endpoint.getPort())
.header("Authorization", AUTH_HEADER)
.formParam("Action", "ModifyReplicationGroup")
.formParam("Version", "2015-02-02")
.formParam("ReplicationGroupId", groupId)
.formParam(prefix + ".1", "sg-replaced")
.when().post("/")
.then().statusCode(200);
assertMemberSecurityGroups(client, groupId, 1, List.of("sg-replaced"));
} finally {
deleteGroup(client, groupId);
}
}
}
private ElastiCacheClient client() {
return ElastiCacheClient.builder().endpointOverride(endpoint).region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
@@ -455,7 +455,7 @@ class ElastiCacheQueryHandlerTest {
@Test
void modifyReplicationGroup_passesSnapshotSettingsOnly() {
when(service.modifyReplicationGroup(eq("g1"), isNull(), isNull(), eq(false), eq(false), any()))
when(service.modifyReplicationGroup(eq("g1"), isNull(), isNull(), eq(false), eq(false), any(), isNull()))
.thenReturn(group("g1"));
MultivaluedMap<String, String> p = params();
p.add("ReplicationGroupId", "g1");
@@ -466,12 +466,12 @@ class ElastiCacheQueryHandlerTest {
assertEquals(200, handler.handle("ModifyReplicationGroup", p, "us-east-1").getStatus());
verify(service).modifyReplicationGroup("g1", null, null, false, false,
new ReplicationGroupSettings(null, null, 3, "01:00-02:00"));
new ReplicationGroupSettings(null, null, 3, "01:00-02:00"), null);
}
@Test
void modifyReplicationGroup_passesRemoveUserGroupsAndAuthTokenDelete() {
when(service.modifyReplicationGroup(eq("g1"), any(), isNull(), eq(true), eq(true), any()))
when(service.modifyReplicationGroup(eq("g1"), any(), isNull(), eq(true), eq(true), any(), isNull()))
.thenReturn(group("g1"));
MultivaluedMap<String, String> p = params();
p.add("ReplicationGroupId", "g1");
@@ -481,7 +481,21 @@ class ElastiCacheQueryHandlerTest {
assertEquals(200, handler.handle("ModifyReplicationGroup", p, "us-east-1").getStatus());
verify(service).modifyReplicationGroup("g1", List.of("new-users"), null, true, true,
new ReplicationGroupSettings(null, null, null, null));
new ReplicationGroupSettings(null, null, null, null), null);
}
@Test
void modifyReplicationGroup_passesNamedSecurityGroupIdsAndUnchangedOtherwise() {
when(service.modifyReplicationGroup(eq("g1"), isNull(), isNull(), eq(false), eq(false), any(), any()))
.thenReturn(group("g1"));
MultivaluedMap<String, String> p = params();
p.add("ReplicationGroupId", "g1");
p.add("SecurityGroupIds.SecurityGroupId.1", "sg-1");
p.add("SecurityGroupIds.SecurityGroupId.2", "sg-2");
assertEquals(200, handler.handle("ModifyReplicationGroup", p, "us-east-1").getStatus());
verify(service).modifyReplicationGroup("g1", null, null, false, false,
new ReplicationGroupSettings(null, null, null, null), List.of("sg-1", "sg-2"));
}
@Test
@@ -502,12 +502,12 @@ class ElastiCacheServiceTest {
service.createUserGroup("redis-users", "redis", List.of("default-user-id"), "us-east-1");
AwsException refused = assertThrows(AwsException.class, () -> service.modifyReplicationGroup(
"grp", null, null, false, true, ReplicationGroupSettings.unchanged()));
"grp", null, null, false, true, ReplicationGroupSettings.unchanged(), null));
assertEquals("InvalidParameterCombination", refused.getErrorCode());
assertEquals("group-token", service.getReplicationGroup("grp").getAuthToken());
service.modifyReplicationGroup("grp", List.of("redis-users"), null, false, true,
ReplicationGroupSettings.unchanged());
ReplicationGroupSettings.unchanged(), null);
assertNull(service.getReplicationGroup("grp").getAuthToken());
service.modifyReplicationGroup("grp", null, List.of("redis-users"));
@@ -528,7 +528,7 @@ class ElastiCacheServiceTest {
service.createUserGroup("second-users", "redis", List.of("default-user-id"), "us-east-1");
service.modifyReplicationGroup("grp", List.of("first-users", "second-users"), null);
service.modifyReplicationGroup("grp", null, null, true, false, ReplicationGroupSettings.unchanged());
service.modifyReplicationGroup("grp", null, null, true, false, ReplicationGroupSettings.unchanged(), null);
ReplicationGroup group = service.getReplicationGroup("grp");
assertTrue(group.getUserGroupIds().isEmpty());
@@ -537,6 +537,23 @@ class ElastiCacheServiceTest {
assertFalse(service.hasMembers("grp"));
}
@Test
void modifyReplicationGroupReplacesSecurityGroupsOnlyWhenNamed() {
service.createReplicationGroup("grp", "test", AuthMode.NO_AUTH, null, "us-east-1");
service.modifyReplicationGroup("grp", null, null, false, false,
ReplicationGroupSettings.unchanged(), List.of("sg-1", "sg-2"));
assertEquals(List.of("sg-1", "sg-2"), service.getReplicationGroup("grp").getSecurityGroupIds());
service.modifyReplicationGroup("grp", null, null, false, false,
ReplicationGroupSettings.unchanged(), null);
assertEquals(List.of("sg-1", "sg-2"), service.getReplicationGroup("grp").getSecurityGroupIds());
service.modifyReplicationGroup("grp", null, null, false, false,
ReplicationGroupSettings.unchanged(), List.of("sg-3"));
assertEquals(List.of("sg-3"), service.getReplicationGroup("grp").getSecurityGroupIds());
}
@Test
void aTokenKeptThroughUserGroupsAppliesAgainOnceTheyAreRemoved() {
service.createReplicationGroup("grp", "test", AuthMode.PASSWORD, "group-token", "us-east-1");
@@ -1353,7 +1370,7 @@ class ElastiCacheServiceTest {
"on ~* +@all", null);
svc.createUserGroup("redis-users", "redis", List.of("default-user-id"), "us-east-1");
svc.modifyReplicationGroup("grp", List.of("redis-users"), null, false, true,
ReplicationGroupSettings.unchanged());
ReplicationGroupSettings.unchanged(), null);
svc.modifyReplicationGroup("grp", null, List.of("redis-users"));
ArgumentCaptor<ElastiCacheAuthProxy.PasswordValidator> validator =
ArgumentCaptor.forClass(ElastiCacheAuthProxy.PasswordValidator.class);