fix(codeartifact): give every domain its root package group /* (#8355)

The User Guide: "Every domain in CodeArtifact automatically contains a
root package group", /*, which "can be modified, but cannot be deleted".
CreateDomain created no group, so on a fresh domain ListPackageGroups was
empty, DescribePackageGroup and GetAssociatedPackageGroup answered
ResourceNotFoundException for /*, a package no group reached had no group
at all, and DeletePackageGroup /* succeeded on a group a caller had made.

CreateDomain creates the root with the domain now. Its description is
"Default root package group" and each of its restrictions is ALLOW, as
recorded against AWS, so a group under it inherits from it rather than
from nothing. CreatePackageGroup /* is refused as the group it is, and
DeletePackageGroup /* with ValidationException "The root package group,
'/*', cannot be deleted.", AWS's own sentence. A domain stored before
this gets its root once storage is loaded at startup.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 15:20:00 -04:00
1 parent c99d8ee5ea
commit 63607e899d
5 files changed
+164 -22

No files matched your search

@@ -9,6 +9,7 @@ import io.floci.aws.lifecycle.inithook.InitializationHook;
import io.floci.aws.lifecycle.inithook.InitializationHooksRunner;
import io.floci.aws.services.amazonmq.container.RabbitMqManager;
import io.floci.aws.services.appsync.graphql.SchemaCreationWorker;
import io.floci.aws.services.codeartifact.CodeArtifactService;
import io.floci.aws.services.docdb.container.DocDbContainerManager;
import io.floci.aws.services.dynamodb.DynamoDbRuntime;
import io.floci.aws.services.ec2.Ec2MetadataServer;
@@ -92,6 +93,7 @@ class EmulatorLifecycleTest {
@Mock private EmulatorConfig.EcsServiceConfig ecsServiceConfig;
@Mock private EmulatorConfig.EcsTaskRoleCredentialsConfig ecsTaskRoleCredentialsConfig;
@Mock private EmulatorConfig.EksServiceConfig eksServiceConfig;
@Mock private EmulatorConfig.CodeArtifactServiceConfig codeArtifactServiceConfig;
@Mock private EmulatorConfig.ElbV2ServiceConfig elbv2ServiceConfig;
@Mock private EmulatorConfig.ElbServiceConfig elbServiceConfig;
@Mock private IamService iamService;
@@ -119,6 +121,7 @@ class EmulatorLifecycleTest {
@Mock private ElbClassicService elbClassicService;
@Mock private EcsService ecsService;
@Mock private EksService eksService;
@Mock private CodeArtifactService codeArtifactService;
@Mock private InitializationHooksRunner initializationHooksRunner;
@Mock private SqsEventSourcePoller sqsPoller;
@Mock private KinesisEventSourcePoller kinesisPoller;
@@ -161,6 +164,8 @@ class EmulatorLifecycleTest {
Mockito.lenient().when(lambdaServiceConfig.enabled()).thenReturn(false);
Mockito.lenient().when(servicesConfig.eks()).thenReturn(eksServiceConfig);
Mockito.lenient().when(eksServiceConfig.enabled()).thenReturn(false);
Mockito.lenient().when(servicesConfig.codeartifact()).thenReturn(codeArtifactServiceConfig);
Mockito.lenient().when(codeArtifactServiceConfig.enabled()).thenReturn(true);
Mockito.lenient().when(servicesConfig.timestreamInfluxdb()).thenReturn(timestreamInfluxDbServiceConfig);
Mockito.lenient().when(timestreamInfluxDbServiceConfig.enabled()).thenReturn(true);
Mockito.lenient().when(servicesConfig.iam()).thenReturn(iamServiceConfig);
@@ -182,7 +187,7 @@ class EmulatorLifecycleTest {
pipesService, ec2MetadataServer, ecsTaskRoleCredentialsServer, ecrRegistryManager, flociUiManager, initLifecycleState,
schemaCreationWorker, stepFunctionsService, durableExecutionService, containerTeardowns,
persistentPathValidator,
dynamoDbRuntime, redshiftZeroEtlConsumer, eksService);
dynamoDbRuntime, redshiftZeroEtlConsumer, eksService, codeArtifactService);
Mockito.lenient().when(containerTeardowns.iterator())
.thenReturn(Collections.emptyIterator());
}
@@ -212,6 +217,19 @@ class EmulatorLifecycleTest {
inOrder.verify(rdsService).restorePersistedRuntime();
}
@Test
void givesStoredCodeArtifactDomainsTheirRootPackageGroupOnceStorageIsLoaded() {
stubStorageConfig();
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(false);
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
emulatorLifecycle.onStart(Mockito.mock(StartupEvent.class));
InOrder inOrder = Mockito.inOrder(storageFactory, codeArtifactService);
inOrder.verify(storageFactory).loadAll();
inOrder.verify(codeArtifactService).seedRootPackageGroups();
}
@Test
void startsTheDynamoDbBackendAfterStorageLoadAndBeforeItsStreamConsumers() {
stubStorageConfig();
@@ -79,8 +79,10 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -101,6 +103,7 @@ class CodeArtifactServiceTest {
private RegionResolver regionResolver;
private AccountAwareStorageBackend<CodeArtifactRepository> repoStore;
private AccountAwareStorageBackend<PackageOriginConfig> packageOriginConfigStore;
private AccountAwareStorageBackend<PackageGroup> packageGroupStore;
private VerdaccioSidecarClient verdaccioClient;
private ReposiliteSidecarClient reposiliteClient;
private PypiserverSidecarClient pypiserverClient;
@@ -113,7 +116,7 @@ class CodeArtifactServiceTest {
AccountAwareStorageBackend<CodeArtifactPackageVersion> packageVersionStore =
AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
packageOriginConfigStore = AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
AccountAwareStorageBackend<PackageGroup> packageGroupStore = AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
packageGroupStore = spy(AccountAwareStorageBackend.<PackageGroup>inMemory(ACCOUNT_ID));
regionResolver = mock(RegionResolver.class);
when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
@@ -8120,10 +8123,10 @@ class CodeArtifactServiceTest {
assertEquals("dom", view.domainName());
assertEquals("contact", view.contactInfo());
assertEquals("desc", view.description());
assertNull(view.parentPattern());
assertEquals("/*", view.parentPattern());
assertEquals("INHERIT", view.restrictions().get("PUBLISH").mode());
assertEquals("ALLOW", view.restrictions().get("PUBLISH").effectiveMode());
assertNull(view.restrictions().get("PUBLISH").inheritedFromPattern());
assertEquals("/*", view.restrictions().get("PUBLISH").inheritedFromPattern());
}
@Test
@@ -8133,8 +8136,9 @@ class CodeArtifactServiceTest {
service.createPackageGroup(REGION, "dom", null, "/npm/space/*", null, null, Map.of());
PackageGroupDescriptionView child = service.describePackageGroup(REGION, "dom", null, "/npm/space/*");
assertEquals("/npm/*", child.parentPattern());
PackageGroupDescriptionView root = service.describePackageGroup(REGION, "dom", null, "/npm/*");
assertNull(root.parentPattern());
PackageGroupDescriptionView npm = service.describePackageGroup(REGION, "dom", null, "/npm/*");
assertEquals("/*", npm.parentPattern());
assertNull(service.describePackageGroup(REGION, "dom", null, "/*").parentPattern());
}
@Test
@@ -8185,7 +8189,8 @@ class CodeArtifactServiceTest {
service.createPackageGroup(REGION, "dom", null, "/pypi/*", null, null, Map.of());
PackageGroupListResult all = service.listPackageGroups(REGION, "dom", null, null, null, null);
assertEquals(2, all.packageGroups().size());
assertEquals(List.of("/*", "/npm/*", "/pypi/*"),
all.packageGroups().stream().map(PackageGroupDescriptionView::pattern).toList());
PackageGroupListResult npmOnly = service.listPackageGroups(REGION, "dom", null, "/npm", null, null);
assertEquals(1, npmOnly.packageGroups().size());
@@ -8262,11 +8267,76 @@ class CodeArtifactServiceTest {
}
@Test
void getAssociatedPackageGroupThrowsResourceNotFoundWhenNoGroupMatches() {
void getAssociatedPackageGroupIsTheRootGroupWhenNoOtherGroupMatches() {
service.createDomain(REGION, "dom", null, Map.of());
AwsException e = assertThrows(AwsException.class,
() -> service.getAssociatedPackageGroup(REGION, "dom", null, "npm", null, "react"));
assertEquals("ResourceNotFoundException", e.getErrorCode());
GetAssociatedPackageGroupResult result =
service.getAssociatedPackageGroup(REGION, "dom", null, "npm", null, "react");
assertEquals("/*", result.packageGroup().pattern());
assertEquals("STRONG", result.associationType());
}
@Test
void aDomainIsCreatedWithItsRootPackageGroupAllowingEveryOrigin() {
service.createDomain(REGION, "dom", null, Map.of());
PackageGroupDescriptionView root = service.describePackageGroup(REGION, "dom", null, "/*");
assertEquals("Default root package group", root.description());
assertNull(root.contactInfo());
assertNull(root.parentPattern());
for (String type : List.of("PUBLISH", "EXTERNAL_UPSTREAM", "INTERNAL_UPSTREAM")) {
assertEquals("ALLOW", root.restrictions().get(type).mode(), type);
assertEquals("ALLOW", root.restrictions().get(type).effectiveMode(), type);
assertNull(root.restrictions().get(type).inheritedFromPattern(), type);
}
assertEquals(List.of("/*"), service.listPackageGroups(REGION, "dom", null, null, null, null)
.packageGroups().stream().map(PackageGroupDescriptionView::pattern).toList());
}
@Test
void theRootPackageGroupCanBeChangedButNotCreatedAgainOrDeleted() {
service.createDomain(REGION, "dom", null, Map.of());
AwsException created = assertThrows(AwsException.class,
() -> service.createPackageGroup(REGION, "dom", null, "/*", null, null, Map.of()));
assertEquals("ConflictException", created.getErrorCode());
AwsException deleted = assertThrows(AwsException.class,
() -> service.deletePackageGroup(REGION, "dom", null, "/*"));
assertEquals("ValidationException", deleted.getErrorCode());
assertEquals("The root package group, '/*', cannot be deleted.", deleted.getMessage());
service.updatePackageGroup(REGION, "dom", null, "/*", "team@example.com", "everything");
service.updatePackageGroupOriginConfiguration(REGION, "dom", null, "/*", Map.of("PUBLISH", "BLOCK"),
List.of(), List.of());
service.createPackageGroup(REGION, "dom", null, "/npm/*", null, null, Map.of());
PackageGroupDescriptionView npm = service.describePackageGroup(REGION, "dom", null, "/npm/*");
assertEquals("BLOCK", npm.restrictions().get("PUBLISH").effectiveMode());
assertEquals("/*", npm.restrictions().get("PUBLISH").inheritedFromPattern());
assertEquals("everything", service.describePackageGroup(REGION, "dom", null, "/*").description());
}
@Test
void aDomainWhoseRootCannotBeStoredIsNotLeftBehindToRefuseTheRetry() {
doThrow(new IllegalStateException("storage unavailable")).when(packageGroupStore)
.putForAccount(anyString(), startsWith(REGION + "::dom::"), any());
assertThrows(IllegalStateException.class, () -> service.createDomain(REGION, "dom", null, Map.of()));
doCallRealMethod().when(packageGroupStore).putForAccount(anyString(), anyString(), any());
service.createDomain(REGION, "dom", null, Map.of());
assertEquals("Default root package group",
service.describePackageGroup(REGION, "dom", null, "/*").description());
}
@Test
void aStoredDomainWithoutARootPackageGroupGetsOneWhenSeeded() {
service.createDomain(REGION, "dom", null, Map.of());
List.copyOf(packageGroupStore.keysForAccount(ACCOUNT_ID))
.forEach(key -> packageGroupStore.deleteForAccount(ACCOUNT_ID, key));
assertThrows(AwsException.class, () -> service.describePackageGroup(REGION, "dom", null, "/*"));
service.seedRootPackageGroups();
service.seedRootPackageGroups();
assertEquals("Default root package group",
service.describePackageGroup(REGION, "dom", null, "/*").description());
assertEquals(1, service.listPackageGroups(REGION, "dom", null, null, null, null).packageGroups().size());
}
@Test