mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
c99d8ee5ea
commit
63607e899d
5 files changed
+164
-22
No files matched your search
@@ -18,7 +18,7 @@ behind them yet.
|
||||
<!-- floci:actions:start -->
|
||||
| Action | Description |
|
||||
| --- | --- |
|
||||
| `CreateDomain` | Creates a domain (max 10 per account per Region), optionally with a KMS encryption key and initial tags. |
|
||||
| `CreateDomain` | Creates a domain (max 10 per account per Region), optionally with a KMS encryption key and initial tags, and its root package group `/*`, whose restrictions are all `ALLOW`. |
|
||||
| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories, and with `ResourceNotFoundException` for a missing domain (as AWS does, although the API reference does not list it). |
|
||||
| `DescribeDomain` | Returns a domain's full description, including its repository count and the total size of its assets (generic, Maven, npm, pypi, and NuGet; see Known limitations). |
|
||||
| `ListDomains` | Lists domain summaries for the account and Region, paginated. |
|
||||
@@ -52,8 +52,8 @@ behind them yet.
|
||||
| `UpdatePackageVersionsStatus` | Moves one or more versions of a package to `Published`, `Unlisted`, or `Archived`; all-or-nothing per call, with `versionRevisions`/`expectedStatus` as optional preconditions. |
|
||||
| `DisposePackageVersions` | Permanently deletes a package version's assets and sets its status to `Disposed`; irreversible, and shares `UpdatePackageVersionsStatus`'s all-or-nothing batch semantics. |
|
||||
| `DeletePackageVersions` | Permanently removes one or more versions of a package, real assets included; unlike `DisposePackageVersions`, leaves no trace, the freed coordinates can be freely republished, and it is the one action allowed on an already-`Disposed` version. |
|
||||
| `CreatePackageGroup` | Creates a package group from a pattern (its own identifier); every restriction type starts at `INHERIT`. |
|
||||
| `DeletePackageGroup` | Deletes a package group; its direct children reparent onto its own parent, recomputed from the remaining groups. |
|
||||
| `CreatePackageGroup` | Creates a package group from a pattern (its own identifier); every restriction type starts at `INHERIT`. The root group `/*` exists from the domain's creation, so it cannot be created again. |
|
||||
| `DeletePackageGroup` | Deletes a package group; its direct children reparent onto its own parent, recomputed from the remaining groups. The root group `/*` cannot be deleted (`ValidationException`). |
|
||||
| `DescribePackageGroup` | Returns a package group's pattern, origin configuration (stored and resolved effective mode per restriction type), and parent. |
|
||||
| `UpdatePackageGroup` | Updates a package group's `contactInfo`/`description`; the pattern and restrictions are unchanged. |
|
||||
| `UpdatePackageGroupOriginConfiguration` | Sets a package group's per-restriction-type mode and/or edits its `ALLOW_SPECIFIC_REPOSITORIES` allow-list. |
|
||||
@@ -61,7 +61,7 @@ behind them yet.
|
||||
| `ListSubPackageGroups` | Lists a package group's direct children only (not grandchildren), per the hierarchy computed from the domain's current groups. |
|
||||
| `ListAllowedRepositoriesForGroup` | Lists the repositories a package group's `ALLOW_SPECIFIC_REPOSITORIES` allow-list names for one restriction type. |
|
||||
| `ListAssociatedPackages` | Lists the packages (across every repository in the domain) for which this group is the most specific match; `preview` answers the same question for a pattern that doesn't exist yet. |
|
||||
| `GetAssociatedPackageGroup` | Returns the most specific package group matching a package's coordinate, and whether the match is `STRONG` or `WEAK`; `ResourceNotFoundException` if no group's pattern reaches it at all. |
|
||||
| `GetAssociatedPackageGroup` | Returns the most specific package group matching a package's coordinate, and whether the match is `STRONG` or `WEAK`; the root group `/*` when no other group's pattern reaches it. |
|
||||
| `TagResource` | Adds or updates tags on a domain, repository, or package group ARN. |
|
||||
| `UntagResource` | Removes tags by key from a domain, repository, or package group ARN. |
|
||||
| `ListTagsForResource` | Lists the tags on a domain, repository, or package group ARN. |
|
||||
|
||||
@@ -10,6 +10,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;
|
||||
@@ -120,6 +121,7 @@ public class EmulatorLifecycle {
|
||||
private final Instance<ContainerTeardown> containerTeardowns;
|
||||
private final PersistentPathValidator persistentPathValidator;
|
||||
private final EksService eksService;
|
||||
private final CodeArtifactService codeArtifactService;
|
||||
private final DynamoDbRuntime dynamoDbRuntime;
|
||||
private final RedshiftDynamoDbZeroEtlConsumer redshiftZeroEtlConsumer;
|
||||
// Set on the boot thread, read by the async HttpServerStart observer.
|
||||
@@ -166,7 +168,8 @@ public class EmulatorLifecycle {
|
||||
PersistentPathValidator persistentPathValidator,
|
||||
DynamoDbRuntime dynamoDbRuntime,
|
||||
RedshiftDynamoDbZeroEtlConsumer redshiftZeroEtlConsumer,
|
||||
EksService eksService) {
|
||||
EksService eksService,
|
||||
CodeArtifactService codeArtifactService) {
|
||||
this.storageFactory = storageFactory;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.config = config;
|
||||
@@ -207,6 +210,7 @@ public class EmulatorLifecycle {
|
||||
this.containerTeardowns = containerTeardowns;
|
||||
this.persistentPathValidator = persistentPathValidator;
|
||||
this.eksService = eksService;
|
||||
this.codeArtifactService = codeArtifactService;
|
||||
this.dynamoDbRuntime = dynamoDbRuntime;
|
||||
this.redshiftZeroEtlConsumer = redshiftZeroEtlConsumer;
|
||||
}
|
||||
@@ -294,6 +298,9 @@ public class EmulatorLifecycle {
|
||||
if (config.services().ecs().enabled()) {
|
||||
ecsService.restorePersistedRuntime();
|
||||
}
|
||||
if (config.services().codeartifact().enabled()) {
|
||||
codeArtifactService.seedRootPackageGroups();
|
||||
}
|
||||
|
||||
if (isMetadataServerNeeded()) {
|
||||
metadataServerStarted = ec2MetadataServer.start().exceptionally(ex -> {
|
||||
|
||||
@@ -122,6 +122,10 @@ public class CodeArtifactService implements Resettable {
|
||||
* restrictions map this service returns iterates them. */
|
||||
private static final List<String> PACKAGE_GROUP_RESTRICTION_TYPES =
|
||||
List.of("PUBLISH", "EXTERNAL_UPSTREAM", "INTERNAL_UPSTREAM");
|
||||
/** The pattern of the root package group every domain holds from its creation, which matches every package. */
|
||||
static final String ROOT_PACKAGE_GROUP = "/*";
|
||||
/** The description CodeArtifact gives the root package group, the same in every domain. */
|
||||
private static final String ROOT_PACKAGE_GROUP_DESCRIPTION = "Default root package group";
|
||||
/** The real {@code PackageGroupOriginRestrictionMode} wire enum. */
|
||||
private static final Set<String> PACKAGE_GROUP_MODES =
|
||||
Set.of("ALLOW", "ALLOW_SPECIFIC_REPOSITORIES", "BLOCK", "INHERIT");
|
||||
@@ -494,9 +498,50 @@ public class CodeArtifactService implements Resettable {
|
||||
d.setCreatedTime(Instant.now().getEpochSecond());
|
||||
d.setTags(validateTags(tags, Map.of(), domain, "domain"));
|
||||
domains.putForAccount(owner, key, d);
|
||||
try {
|
||||
packageGroups.putForAccount(owner, packageGroupKey(region, domain, ROOT_PACKAGE_GROUP),
|
||||
rootPackageGroup(owner, d));
|
||||
} catch (RuntimeException e) {
|
||||
// A domain left without its root would refuse the retry as a duplicate.
|
||||
domains.deleteForAccount(owner, key);
|
||||
throw e;
|
||||
}
|
||||
return new DomainView(d, 0, 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* The root package group a domain is created with. "Every domain in CodeArtifact automatically contains a root
|
||||
* package group", which "allows package versions to enter repositories in the domain from all origin types by
|
||||
* default": each of its restrictions is {@code ALLOW} rather than {@code INHERIT}, as it has no parent to inherit
|
||||
* from, and a group under it inherits from it. Its description is the one CodeArtifact gives it.
|
||||
*/
|
||||
private PackageGroup rootPackageGroup(String owner, CodeArtifactDomain d) {
|
||||
String arn = regionResolver.buildArn("codeartifact", d.getRegion(), owner,
|
||||
"package-group/" + d.getName() + ROOT_PACKAGE_GROUP);
|
||||
PackageGroup root = new PackageGroup(ROOT_PACKAGE_GROUP, arn, d.getName(), owner, d.getRegion(), null,
|
||||
ROOT_PACKAGE_GROUP_DESCRIPTION, d.getCreatedTime());
|
||||
Map<String, PackageGroupRestriction> restrictions = new LinkedHashMap<>();
|
||||
PACKAGE_GROUP_RESTRICTION_TYPES.forEach(type ->
|
||||
restrictions.put(type, new PackageGroupRestriction("ALLOW", new ArrayList<>())));
|
||||
root.setRestrictions(restrictions);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives every stored domain without one its root package group, for a domain stored by a release that did not
|
||||
* create the group with it. Run once storage is loaded.
|
||||
*/
|
||||
public synchronized void seedRootPackageGroups() {
|
||||
for (AccountAwareStorageBackend.AccountEntry<CodeArtifactDomain> entry
|
||||
: domains.scanAllAccountEntries(k -> true)) {
|
||||
CodeArtifactDomain d = entry.value();
|
||||
String key = packageGroupKey(d.getRegion(), d.getName(), ROOT_PACKAGE_GROUP);
|
||||
if (packageGroups.getForAccount(entry.accountId(), key).isEmpty()) {
|
||||
packageGroups.putForAccount(entry.accountId(), key, rootPackageGroup(entry.accountId(), d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A missing domain fails with {@code ResourceNotFoundException} (404), which is what AWS
|
||||
* returns even though the API reference leaves it out of DeleteDomain's error list.
|
||||
@@ -5334,7 +5379,7 @@ public class CodeArtifactService implements Resettable {
|
||||
String owner = effectiveOwner(domainOwner);
|
||||
String key = packageGroupKey(region, domain, pattern);
|
||||
requireDomain(owner, domainKey(region, domain), domain);
|
||||
if (packageGroups.getForAccount(owner, key).isPresent()) {
|
||||
if (ROOT_PACKAGE_GROUP.equals(pattern) || packageGroups.getForAccount(owner, key).isPresent()) {
|
||||
throw conflict("A package group with pattern '" + pattern + "' already exists.", pattern,
|
||||
"package-group");
|
||||
}
|
||||
@@ -5357,6 +5402,10 @@ public class CodeArtifactService implements Resettable {
|
||||
String owner = effectiveOwner(domainOwner);
|
||||
String key = packageGroupKey(region, domain, pattern);
|
||||
PackageGroup group = requirePackageGroup(owner, key, pattern);
|
||||
if (ROOT_PACKAGE_GROUP.equals(group.getPattern())) {
|
||||
// The service's own sentence, as recorded against AWS.
|
||||
throw validation("The root package group, '/*', cannot be deleted.");
|
||||
}
|
||||
List<PackageGroup> all = allPackageGroupsInDomain(owner, region, domain);
|
||||
// Computed before the delete removes it from storage: DeletePackageGroup's own documented
|
||||
// behavior ("the direct child package groups will become children of the package group's
|
||||
@@ -5611,11 +5660,9 @@ public class CodeArtifactService implements Resettable {
|
||||
/**
|
||||
* The single group a package is associated with: the most specific group in {@code all}
|
||||
* whose pattern matches {@code path} at all (strong or weak), per the User Guide's own
|
||||
* "a package is associated with exactly one package group" rule. {@link Optional#empty}
|
||||
* models a domain where no created group's pattern reaches this package at all — real
|
||||
* CodeArtifact has no implicit catch-all root group (confirmed by {@code
|
||||
* GetAssociatedPackageGroup}'s own documented {@code ResourceNotFoundException}), so callers
|
||||
* must treat that as "this package has no group," not fall back to a synthesized default.
|
||||
* "a package is associated with exactly one package group" rule. Every domain holds the root
|
||||
* group {@code /*}, which matches every package, so a package of a domain always has one;
|
||||
* {@link Optional#empty} is left for a list of groups that has no root.
|
||||
*/
|
||||
private Optional<AssociatedGroupMatch> findAssociatedGroup(List<PackageGroup> all,
|
||||
PackageGroupPatterns.PackagePath path) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user