fix(memorydb): keep user and ACL tags and let them be tagged (#8082)

CreateUser and CreateACL never read their Tags member, and ListTags,
TagResource and UntagResource resolved every ARN as a cluster, so a
user or ACL ARN answered ClusterNotFoundFault and neither resource
could be tagged at all.

User and Acl now keep a tag map, set from Tags on create as
CreateCluster already does. The three tag operations pick the
resource from the ARN: user/ and acl/ look the name up in the current
Region and require the stored ARN to match, answering
UserNotFoundFault or ACLNotFoundFault, and any other ARN goes through
clusterByArn as before. The built-in default user and open-access ACL
are not stored, so they still answer the not-found fault. Users and
ACLs saved before this change have no tags field and load with an
empty map.

Fixes #7956
This commit is contained in:
soreavis authored and GitHub committed 2026-11-12 07:40:35 -04:00
1 parent f6b95fda16
commit 33968bca39
7 files changed
+111 -12

No files matched your search

@@ -15,6 +15,7 @@ import org.mockito.ArgumentCaptor;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@@ -89,6 +90,26 @@ class MemoryDbHandlerTest {
assertEquals(List.of("app-user"), captor.getValue().getUserNames());
}
@Test
void createUserAndAclReadTags() throws Exception {
when(service.createUser(any(), any())).thenAnswer(inv -> inv.getArgument(0));
when(service.createAcl(any(), any())).thenAnswer(inv -> inv.getArgument(0));
String tags = "\"Tags\":[{\"Key\":\"team\",\"Value\":\"red\"}]";
handler.handle("CreateUser", objectMapper.readTree(
"{\"UserName\":\"tag-user\",\"AccessString\":\"on ~* +@all\","
+ "\"AuthenticationMode\":{\"Type\":\"iam\"}," + tags + "}"), "us-east-1");
handler.handle("CreateACL", objectMapper.readTree(
"{\"ACLName\":\"tag-acl\",\"UserNames\":[\"default\"]," + tags + "}"), "us-east-1");
ArgumentCaptor<User> user = ArgumentCaptor.forClass(User.class);
verify(service).createUser(user.capture(), eq("us-east-1"));
assertEquals(Map.of("team", "red"), user.getValue().getTags());
ArgumentCaptor<Acl> acl = ArgumentCaptor.forClass(Acl.class);
verify(service).createAcl(acl.capture(), eq("us-east-1"));
assertEquals(Map.of("team", "red"), acl.getValue().getTags());
}
@Test
void unknownOperationReturns400() throws Exception {
JsonNode request = objectMapper.readTree("{}");
@@ -18,6 +18,7 @@ import io.floci.aws.services.memorydb.proxy.MemoryDbProxyManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -170,6 +171,41 @@ class MemoryDbServiceTest {
assertFalse(service.listTags(arn).containsKey("env"));
}
@Test
void usersAndAclsKeepCreateTagsAndCanBeTagged() {
User userSpec = new User();
userSpec.setName("tag-user");
userSpec.setAuthMode(AuthMode.PASSWORD);
userSpec.setPasswords(List.of("passwordpassword1"));
userSpec.setAccessString("on ~* +@all");
userSpec.setTags(new LinkedHashMap<>(Map.of("team", "red")));
String userArn = service.createUser(userSpec, "us-east-1").getArn();
Acl aclSpec = new Acl();
aclSpec.setName("tag-acl");
aclSpec.setUserNames(List.of("default", "tag-user"));
aclSpec.setTags(new LinkedHashMap<>(Map.of("team", "red")));
String aclArn = service.createAcl(aclSpec, "us-east-1").getArn();
assertEquals(Map.of("team", "red"), service.listTags(userArn));
assertEquals(Map.of("team", "red"), service.listTags(aclArn));
service.tagResource(userArn, Map.of("env", "dev"));
service.untagResource(aclArn, List.of("team"));
assertEquals(Map.of("team", "red", "env", "dev"), service.listTags(userArn));
assertEquals(Map.of(), service.listTags(aclArn));
}
@Test
void unknownUserOrAclArnRaisesItsNotFoundFault() {
AwsException user = assertThrows(AwsException.class,
() -> service.listTags("arn:aws:memorydb:us-east-1:000000000000:user/missing"));
assertEquals("UserNotFoundFault", user.jsonType());
AwsException acl = assertThrows(AwsException.class,
() -> service.tagResource("arn:aws:memorydb:us-east-1:000000000000:acl/missing", Map.of("env", "dev")));
assertEquals("ACLNotFoundFault", acl.jsonType());
}
@Test
void openAccessClusterRequiresNoAuth() {
Cluster spec = new Cluster();