From 86b19047f3fbd72d64543b0c619facdd89871240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C5=A9=20Th=E1=BA=BF=20Huy?= <31652864+vuthehuyht@users.noreply.github.com> Date: Wed, 14 Oct 2026 07:56:08 +0700 Subject: [PATCH] fix(elasticache): return modeled wire error codes for replication group and user name faults (#5571) CreateReplicationGroup threw ReplicationGroupAlreadyExistsFault, whose modeled wire code is ReplicationGroupAlreadyExists at HTTP 400. ModifyReplicationGroup's duplicate user name check threw DuplicateUserNameFault, whose modeled wire code is DuplicateUserName, matching the user group create path. --- .../services/elasticache/ElastiCacheService.java | 6 +++--- .../elasticache/ElastiCacheServiceTest.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java index 35a7c75bae..a2d38b6ea7 100644 --- a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java +++ b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java @@ -264,13 +264,13 @@ public class ElastiCacheService implements ResourceProvider { // provisioningIds, and cacheClusterIdTaken for the same test the other way round. if (groups.get(groupId).isPresent() || cacheClusters.get(groupId).isPresent() || memcachedClusters.get(groupId).isPresent()) { - throw new AwsException("ReplicationGroupAlreadyExistsFault", + throw new AwsException("ReplicationGroupAlreadyExists", "Replication group " + groupId + " already exists.", 400); } // Claim the id for the whole provisioning attempt so a concurrent create can't race // ahead and be stopped by this request's handle-less rollback fallback. if (!provisioningIds.claim(groupId)) { - throw new AwsException("ReplicationGroupAlreadyExistsFault", + throw new AwsException("ReplicationGroupAlreadyExists", "Replication group " + groupId + " is already being created.", 400); } @@ -1748,7 +1748,7 @@ public class ElastiCacheService implements ResourceProvider { for (String userId : nextUserIds) { ElastiCacheUser u = users.get(userId).orElse(null); if (u != null && !seenUserNames.add(u.getUserName())) { - throw new AwsException("DuplicateUserNameFault", + throw new AwsException("DuplicateUserName", "Duplicate user name " + u.getUserName() + " in user group.", 400); } } diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java index c3c933090c..bbd2d0003d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java @@ -570,10 +570,10 @@ class ElastiCacheServiceTest { service.createUser("uid-1", "same-name", AuthMode.PASSWORD, List.of("pass1"), "on ~* +@all", null); service.createUser("uid-2", "same-name", AuthMode.NO_AUTH, List.of(), "on ~* +@all", null); - // Attempting to associate both users in the same call must fail with DuplicateUserNameFault + // Attempting to associate both users in the same call must fail with DuplicateUserName AwsException ex = assertThrows(AwsException.class, () -> service.modifyReplicationGroup("grp-dup", List.of("uid-1", "uid-2"), null)); - assertEquals("DuplicateUserNameFault", ex.getErrorCode()); + assertEquals("DuplicateUserName", ex.getErrorCode()); assertEquals(400, ex.getHttpStatus()); // Associate uid-1 first @@ -583,7 +583,7 @@ class ElastiCacheServiceTest { // Attempting to add uid-2 with the same username must also fail AwsException ex2 = assertThrows(AwsException.class, () -> service.modifyReplicationGroup("grp-dup", List.of("uid-2"), null)); - assertEquals("DuplicateUserNameFault", ex2.getErrorCode()); + assertEquals("DuplicateUserName", ex2.getErrorCode()); assertEquals(400, ex2.getHttpStatus()); // Validate password must not allow bypassing password check @@ -1182,7 +1182,7 @@ class ElastiCacheServiceTest { AwsException ex = assertThrows(AwsException.class, () -> service.createReplicationGroup("grp", "test", AuthMode.PASSWORD, null, "us-east-1")); - assertEquals("ReplicationGroupAlreadyExistsFault", ex.jsonType()); + assertEquals("ReplicationGroupAlreadyExists", ex.jsonType()); verify(containerManager, never()).stop(any()); verify(containerManager, never()).stopByGroupId(anyString()); @@ -1546,7 +1546,7 @@ class ElastiCacheServiceTest { AwsException ex = assertThrows(AwsException.class, () -> service.createReplicationGroup(requestWithParameterGroup("grp", "custom-pg"))); - assertEquals("ReplicationGroupAlreadyExistsFault", ex.jsonType()); + assertEquals("ReplicationGroupAlreadyExists", ex.jsonType()); service.deleteCacheParameterGroup("custom-pg"); assertTrue(service.findParameterGroup("custom-pg").isEmpty()); @@ -1692,7 +1692,7 @@ class ElastiCacheServiceTest { AwsException ex = assertThrows(AwsException.class, () -> service.createReplicationGroup("shared", "d", AuthMode.NO_AUTH, null, "us-east-1")); - assertEquals("ReplicationGroupAlreadyExistsFault", ex.getErrorCode()); + assertEquals("ReplicationGroupAlreadyExists", ex.getErrorCode()); verify(containerManager, times(1)).tryStart(eq("shared"), anyString(), any()); verify(containerManager, never()).stopByGroupId("shared"); assertEquals("shared", service.findCacheClusters("shared").getFirst().getCacheClusterId()); @@ -1741,7 +1741,7 @@ class ElastiCacheServiceTest { cacheCluster.start(); assertTrue(startedLatch.await(5, TimeUnit.SECONDS), "create never reached container start"); - assertEquals("ReplicationGroupAlreadyExistsFault", + assertEquals("ReplicationGroupAlreadyExists", assertThrows(AwsException.class, () -> service.createReplicationGroup( "raced", "d", AuthMode.NO_AUTH, null, "us-east-1")).getErrorCode()); verify(containerManager, never()).stopByGroupId("raced"); @@ -2061,7 +2061,7 @@ class ElastiCacheServiceTest { AwsException ex = assertThrows(AwsException.class, () -> service.createReplicationGroup( "shared-id", "d", AuthMode.NO_AUTH, null, "us-east-1")); - assertEquals("ReplicationGroupAlreadyExistsFault", ex.getErrorCode()); + assertEquals("ReplicationGroupAlreadyExists", ex.getErrorCode()); verify(containerManager, never()).tryStart(eq("shared-id"), anyString(), any()); }