mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(codeartifact): add PutPackageOriginConfiguration (#5381)
Sets a package's publish/upstream origin-control restrictions, matching AWS's documented behavior that this operation can create the package (with no versions) when it doesn't exist yet, so a caller can lock a package down before anything is ever published to it. DescribePackage now reflects a stored configuration instead of the fixed ALLOW/BLOCK defaults it previously always returned, and PublishPackageVersion rejects a publish with ConflictException once a package's origin configuration sets publish to BLOCK, the one publish path this operation can actually gate since PublishPackageVersion only ever accepts the generic format. Maven/npm/pypi publish through their own native wire protocols and are not yet gated by this setting, documented as a known limitation. The format/namespace coordinate validation shared with DescribePackage is extracted into one helper instead of being duplicated a second time. clear() (the Resettable reset path) now also clears the new store; it previously left an origin-config-only package (no versions) visible to DescribePackage after a reset that wiped everything else. DescribePackage's existence check for an origin-config-only package now short-circuits before the sidecar/generic check runs at all: for a container-backed format that check would otherwise start the real Maven/npm/pypi sidecar container just to answer a describe for a package nothing was ever actually published to. DeletePackage now agrees with DescribePackage on all of this instead of drifting from it. Its deletedPackage.originConfiguration reports the restrictions that were actually stored, not a hard-coded ALLOW/BLOCK; it clears the stored configuration as part of the delete, so a deleted package cannot resurrect as a zero-version one on the next DescribePackage; and it now recognizes an origin-config-only package (no version ever published) as something it can delete, rather than 404ing on a package DescribePackage itself reports as existing. DeletePackage's own namespace/format validation, previously a second inline copy of the same rules, now goes through the shared helper too. A rejected PutPackageOriginConfiguration now also has a test asserting an invalid/missing upstream value alone is rejected (the prior tests only exercised publish) and that a rejection, on either a package that didn't exist yet or one with a prior configuration, changes nothing. deleteRepository now also removes any packageOriginConfigs entries under that repository: unlike sidecarContainerIds, which already gets a fresh id on every creation specifically so a repository recreated under the same name never inherits the previous one's sidecar content, packageOriginConfigs was keyed purely by name, so a recreated repository would otherwise inherit a prior package's restrictions, including a publish:BLOCK the new repository's owner never set.
This commit is contained in:
1 parent
44ee88b829
commit
3ff5529fad
8 files changed
+604
-55
No files matched your search
+28
-2
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.codeartifact.CodeArtifactService.Publ
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactDomain;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactPackageVersion;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactRepository;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.PackageOriginConfig;
|
||||
import io.github.hectorvent.floci.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -85,6 +86,28 @@ class CodeArtifactAssetPersistenceTest {
|
||||
assertEquals(published.packageVersion().getRevision(), result.packageVersionRevision());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code packageOriginConfigs} is wired through {@code StorageFactory} the same way
|
||||
* {@code domains}/{@code repositories}/{@code packageVersions} are, but that similarity had
|
||||
* never actually been exercised: this confirms a stored origin configuration, including one
|
||||
* set on a package with no versions at all, actually round-trips through disk rather than only
|
||||
* ever having been read back from the same in-memory instance that wrote it.
|
||||
*/
|
||||
@Test
|
||||
void packageOriginConfigurationSurvivesRestart(@TempDir Path dir) {
|
||||
CodeArtifactService first = newService(dir);
|
||||
first.createDomain(REGION, "dom", null, Map.of());
|
||||
first.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
first.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "never-published", "BLOCK",
|
||||
"ALLOW");
|
||||
|
||||
CodeArtifactService restarted = newService(dir);
|
||||
CodeArtifactService.PackageDescription described = restarted.describePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "never-published");
|
||||
assertEquals("BLOCK", described.publishRestriction());
|
||||
assertEquals("ALLOW", described.upstreamRestriction());
|
||||
}
|
||||
|
||||
/**
|
||||
* The in-memory {@code PackageAsset.content} field is {@code @JsonIgnore}, so a package
|
||||
* version reloaded from disk (a fresh {@code CodeArtifactService} instance here, standing in
|
||||
@@ -443,6 +466,8 @@ class CodeArtifactAssetPersistenceTest {
|
||||
"codeartifact-repositories.json", new TypeReference<Map<String, CodeArtifactRepository>>() {});
|
||||
AccountAwareStorageBackend<CodeArtifactPackageVersion> packageVersionStore = accountAware(dir,
|
||||
"codeartifact-package-versions.json", new TypeReference<Map<String, CodeArtifactPackageVersion>>() {});
|
||||
AccountAwareStorageBackend<PackageOriginConfig> packageOriginConfigStore = accountAware(dir,
|
||||
"codeartifact-package-origin-configs.json", new TypeReference<Map<String, PackageOriginConfig>>() {});
|
||||
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
|
||||
@@ -453,8 +478,9 @@ class CodeArtifactAssetPersistenceTest {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
|
||||
return new CodeArtifactService(domainStore, repoStore, packageVersionStore, regionResolver, config,
|
||||
false, dir.resolve("codeartifact-assets"), new CodeArtifactSidecarRegistry(List.of()));
|
||||
return new CodeArtifactService(domainStore, repoStore, packageVersionStore, packageOriginConfigStore,
|
||||
regionResolver, config, false, dir.resolve("codeartifact-assets"),
|
||||
new CodeArtifactSidecarRegistry(List.of()));
|
||||
}
|
||||
|
||||
private <V> AccountAwareStorageBackend<V> accountAware(Path dir, String fileName, TypeReference<Map<String, V>> type) {
|
||||
|
||||
+43
@@ -250,6 +250,49 @@ class CodeArtifactIntegrationTest {
|
||||
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putPackageOriginConfigurationCreatesAPackageAndItsRestrictionsSurviveDescribeAndDelete() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{}").post("/v1/domain?domain=origin-config-domain").then().statusCode(200);
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{}").post("/v1/repository?domain=origin-config-domain&repository=repo")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"restrictions\":{\"publish\":\"BLOCK\",\"upstream\":\"ALLOW\"}}")
|
||||
.post("/v1/package?domain=origin-config-domain&repository=repo&format=generic&namespace=ns"
|
||||
+ "&package=never-published")
|
||||
.then().statusCode(200)
|
||||
.body("originConfiguration.restrictions.publish", equalTo("BLOCK"))
|
||||
.body("originConfiguration.restrictions.upstream", equalTo("ALLOW"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package?domain=origin-config-domain&repository=repo&format=generic&namespace=ns"
|
||||
+ "&package=never-published")
|
||||
.then().statusCode(200)
|
||||
.body("package.originConfiguration.restrictions.publish", equalTo("BLOCK"))
|
||||
.body("package.originConfiguration.restrictions.upstream", equalTo("ALLOW"));
|
||||
|
||||
byte[] content = "blocked".getBytes(StandardCharsets.UTF_8);
|
||||
given().header("Authorization", AUTH).header("x-amz-content-sha256", sha256Hex(content))
|
||||
.contentType("application/octet-stream").body(content)
|
||||
.post("/v1/package/version/publish?domain=origin-config-domain&repository=repo&format=generic"
|
||||
+ "&namespace=ns&package=never-published&version=1.0.0&asset=a.txt")
|
||||
.then().statusCode(409).body("__type", equalTo("ConflictException"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.delete("/v1/package?domain=origin-config-domain&repository=repo&format=generic&namespace=ns"
|
||||
+ "&package=never-published")
|
||||
.then().statusCode(200)
|
||||
.body("deletedPackage.originConfiguration.restrictions.publish", equalTo("BLOCK"))
|
||||
.body("deletedPackage.originConfiguration.restrictions.upstream", equalTo("ALLOW"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package?domain=origin-config-domain&repository=repo&format=generic&namespace=ns"
|
||||
+ "&package=never-published")
|
||||
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unfinishedPublishKeepsVersionOpenForMoreAssets() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
|
||||
+281
-2
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.codeartifact.CodeArtifactService.Reso
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactDomain;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactPackageVersion;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactRepository;
|
||||
import io.github.hectorvent.floci.services.codeartifact.model.PackageOriginConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -63,6 +64,8 @@ class CodeArtifactServiceTest {
|
||||
repoStore = AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
AccountAwareStorageBackend<CodeArtifactPackageVersion> packageVersionStore =
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
AccountAwareStorageBackend<PackageOriginConfig> packageOriginConfigStore =
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
|
||||
regionResolver = mock(RegionResolver.class);
|
||||
when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
|
||||
@@ -79,8 +82,8 @@ class CodeArtifactServiceTest {
|
||||
when(reposiliteClient.format()).thenReturn("maven");
|
||||
pypiserverClient = mock(PypiserverSidecarClient.class);
|
||||
when(pypiserverClient.format()).thenReturn("pypi");
|
||||
service = new CodeArtifactService(domainStore, repoStore, packageVersionStore, regionResolver, config,
|
||||
true, null, new CodeArtifactSidecarRegistry(
|
||||
service = new CodeArtifactService(domainStore, repoStore, packageVersionStore, packageOriginConfigStore,
|
||||
regionResolver, config, true, null, new CodeArtifactSidecarRegistry(
|
||||
List.of(verdaccioClient, reposiliteClient, pypiserverClient)));
|
||||
}
|
||||
|
||||
@@ -421,6 +424,34 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* createRepository already guarantees this for container-backed sidecar content, by design
|
||||
* (a fresh sidecarContainerIds id on every creation, never derived from the repository's
|
||||
* name). packageOriginConfigs is keyed by name instead, so deleteRepository has to clean it
|
||||
* up explicitly, or a repository recreated under the same name would inherit a prior
|
||||
* package's restrictions, including a publish:BLOCK the new repository's owner never set and
|
||||
* has no way to discover.
|
||||
*/
|
||||
@Test
|
||||
void deleteRepositoryRemovesOriginConfigsSoARecreatedRepositoryDoesNotInheritThem() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "BLOCK",
|
||||
"BLOCK");
|
||||
|
||||
service.deleteRepository(REGION, "dom", null, "repo");
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException gone = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom", null,
|
||||
"repo", "generic", "ns", "my-pkg"));
|
||||
assertEquals("ResourceNotFoundException", gone.getErrorCode());
|
||||
|
||||
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
|
||||
PublishPackageVersionResult published = service.publishPackageVersion(REGION, "dom", null, "repo", "generic",
|
||||
"ns", "my-pkg", "1.0.0", "a.txt", sha256Hex(content), "false", content);
|
||||
assertEquals("Published", published.packageVersion().getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRepositoryAcceptsExistingUpstream() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
@@ -660,11 +691,22 @@ class CodeArtifactServiceTest {
|
||||
void clearRemovesAllPersistedState() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
// An origin-config-only package (no versions, see putPackageOriginConfiguration) is its
|
||||
// own persisted record distinct from a domain, repository, or package version; clear()
|
||||
// missing it would leave describePackage still finding a package that should be gone.
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "never-published",
|
||||
"BLOCK", "BLOCK");
|
||||
service.clear();
|
||||
assertTrue(service.listDomains(REGION, null, null).items().isEmpty());
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.describeRepository(REGION, "dom", null, "repo"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
AwsException packageGone = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom",
|
||||
null, "repo", "generic", "ns", "never-published"));
|
||||
assertEquals("ResourceNotFoundException", packageGone.getErrorCode());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- authorization tokens
|
||||
@@ -1104,6 +1146,156 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* The one package-level operation that works before the package exists at all: AWS documents
|
||||
* that calling it creates the package with no versions and applies the requested restrictions,
|
||||
* so a caller can lock a package down before anything is ever published to it.
|
||||
*/
|
||||
@Test
|
||||
void putPackageOriginConfigurationCreatesAPackageWithNoVersionsAndDescribePackageReflectsIt() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException notYetFound = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom",
|
||||
null, "repo", "generic", "ns", "never-published"));
|
||||
assertEquals("ResourceNotFoundException", notYetFound.getErrorCode());
|
||||
|
||||
CodeArtifactService.PackageDescription configured = service.putPackageOriginConfiguration(REGION, "dom",
|
||||
null, "repo", "generic", "ns", "never-published", "BLOCK", "BLOCK");
|
||||
assertEquals("BLOCK", configured.publishRestriction());
|
||||
assertEquals("BLOCK", configured.upstreamRestriction());
|
||||
|
||||
CodeArtifactService.PackageDescription described = service.describePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "never-published");
|
||||
assertEquals("BLOCK", described.publishRestriction());
|
||||
assertEquals("BLOCK", described.upstreamRestriction());
|
||||
}
|
||||
|
||||
/**
|
||||
* The same no-versions-needed existence proof applies uniformly to a container-backed format,
|
||||
* not just generic: the pypi sidecar never heard of this package (its mock answers false by
|
||||
* default, standing in for a real sidecar that was never asked to provision anything for it),
|
||||
* yet the stored origin configuration alone must still be enough for describePackage to find
|
||||
* the package rather than 404ing because the sidecar-exists check came back empty.
|
||||
*/
|
||||
@Test
|
||||
void putPackageOriginConfigurationCreatesAContainerBackedPackageWithNoVersionsToo() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "pypi", null, "never-published", "BLOCK",
|
||||
"ALLOW");
|
||||
|
||||
CodeArtifactService.PackageDescription described = service.describePackage(REGION, "dom", null, "repo",
|
||||
"pypi", null, "never-published");
|
||||
assertEquals("BLOCK", described.publishRestriction());
|
||||
assertEquals("ALLOW", described.upstreamRestriction());
|
||||
verify(pypiserverClient, never()).packageExists(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putPackageOriginConfigurationOverridesTheDirectPublishDefaultsOfAnExistingPackage() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
|
||||
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
|
||||
sha256Hex(content), "false", content);
|
||||
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "BLOCK",
|
||||
"ALLOW");
|
||||
|
||||
CodeArtifactService.PackageDescription described = service.describePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "my-pkg");
|
||||
assertEquals("BLOCK", described.publishRestriction());
|
||||
assertEquals("ALLOW", described.upstreamRestriction());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putPackageOriginConfigurationValidatesRestrictionsAndNamespaceShape() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException missingRestrictions = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", null, null));
|
||||
assertEquals("ValidationException", missingRestrictions.getErrorCode());
|
||||
|
||||
AwsException missingUpstreamOnly = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "ALLOW",
|
||||
null));
|
||||
assertEquals("ValidationException", missingUpstreamOnly.getErrorCode());
|
||||
|
||||
AwsException badRestrictionValue = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg",
|
||||
"ALLOW_SPECIFIC_REPOSITORIES", "BLOCK"));
|
||||
assertEquals("ValidationException", badRestrictionValue.getErrorCode());
|
||||
|
||||
AwsException badUpstreamValue = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "ALLOW",
|
||||
"ALLOW_SPECIFIC_REPOSITORIES"));
|
||||
assertEquals("ValidationException", badUpstreamValue.getErrorCode());
|
||||
|
||||
AwsException missingNamespaceForGeneric = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", null, "my-pkg", "ALLOW",
|
||||
"BLOCK"));
|
||||
assertEquals("ValidationException", missingNamespaceForGeneric.getErrorCode());
|
||||
|
||||
AwsException namespaceForPypi = assertThrows(AwsException.class, () -> service
|
||||
.putPackageOriginConfiguration(REGION, "dom", null, "repo", "pypi", "bogus-namespace", "my-pkg",
|
||||
"ALLOW", "BLOCK"));
|
||||
assertEquals("ValidationException", namespaceForPypi.getErrorCode());
|
||||
|
||||
// None of the rejections above may have created the package or changed anything about it:
|
||||
// every one of them must still 404 just like before any of these calls were attempted.
|
||||
AwsException stillAbsent = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom",
|
||||
null, "repo", "generic", "ns", "my-pkg"));
|
||||
assertEquals("ResourceNotFoundException", stillAbsent.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same rejections as above, but against a package that already carries a stored
|
||||
* configuration: a rejected update must leave that prior configuration exactly as it was,
|
||||
* not half-apply the new, invalid restrictions.
|
||||
*/
|
||||
@Test
|
||||
void putPackageOriginConfigurationLeavesAnExistingConfigurationUnchangedOnRejection() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "ALLOW",
|
||||
"BLOCK");
|
||||
|
||||
assertThrows(AwsException.class, () -> service.putPackageOriginConfiguration(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "my-pkg", "ALLOW", "ALLOW_SPECIFIC_REPOSITORIES"));
|
||||
|
||||
CodeArtifactService.PackageDescription unchanged = service.describePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "my-pkg");
|
||||
assertEquals("ALLOW", unchanged.publishRestriction());
|
||||
assertEquals("BLOCK", unchanged.upstreamRestriction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the AWS user guide's own worked example: once a package's origin configuration sets
|
||||
* Publish to Block, a direct PublishPackageVersion for that package must be rejected, even for
|
||||
* an otherwise brand-new version, and restoring Publish to Allow lifts the rejection again.
|
||||
*/
|
||||
@Test
|
||||
void publishPackageVersionIsRejectedOnceOriginConfigurationBlocksPublish() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "BLOCK",
|
||||
"ALLOW");
|
||||
|
||||
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
|
||||
AwsException blocked = assertThrows(AwsException.class, () -> service.publishPackageVersion(REGION, "dom",
|
||||
null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt", sha256Hex(content), "false", content));
|
||||
assertEquals("ConflictException", blocked.getErrorCode());
|
||||
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "ALLOW",
|
||||
"ALLOW");
|
||||
PublishPackageVersionResult published = service.publishPackageVersion(REGION, "dom", null, "repo", "generic",
|
||||
"ns", "my-pkg", "1.0.0", "a.txt", sha256Hex(content), "false", content);
|
||||
assertEquals("Published", published.packageVersion().getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePackageRemovesEveryVersionAndAssetButLeavesOtherPackagesAlone() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
@@ -1145,6 +1337,93 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("ResourceNotFoundException", unknown.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* The real DeletePackage response's deletedPackage.originConfiguration reports whatever
|
||||
* restrictions were actually in effect, not CodeArtifact's bare ALLOW/BLOCK defaults.
|
||||
*/
|
||||
@Test
|
||||
void deletePackageReportsTheOriginConfigurationThatWasActuallyInEffect() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
|
||||
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
|
||||
sha256Hex(content), "false", content);
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "ALLOW",
|
||||
"ALLOW");
|
||||
|
||||
CodeArtifactService.PackageDescription deleted = service.deletePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "my-pkg");
|
||||
assertEquals("ALLOW", deleted.publishRestriction());
|
||||
assertEquals("ALLOW", deleted.upstreamRestriction());
|
||||
}
|
||||
|
||||
/**
|
||||
* DeletePackage removes the package entity, origin configuration included (AWS's own doc:
|
||||
* "Deletes a package and all associated package versions"). A leftover origin-config record
|
||||
* must not resurrect the deleted package as a zero-version one on the next DescribePackage.
|
||||
*/
|
||||
@Test
|
||||
void deletePackageClearsTheOriginConfigurationSoDescribePackageStays404Afterward() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
|
||||
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
|
||||
sha256Hex(content), "false", content);
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "BLOCK",
|
||||
"BLOCK");
|
||||
|
||||
service.deletePackage(REGION, "dom", null, "repo", "generic", "ns", "my-pkg");
|
||||
|
||||
AwsException gone = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom", null,
|
||||
"repo", "generic", "ns", "my-pkg"));
|
||||
assertEquals("ResourceNotFoundException", gone.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* An origin-config-only package (no version ever published) is still a package
|
||||
* describePackage finds; deletePackage must agree rather than 404ing on the same coordinates
|
||||
* describePackage just reported as existing.
|
||||
*/
|
||||
@Test
|
||||
void deletePackageRemovesAnOriginConfigOnlyPackageThatWasNeverPublishedTo() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "generic", "ns", "never-published",
|
||||
"BLOCK", "BLOCK");
|
||||
|
||||
CodeArtifactService.PackageDescription deleted = service.deletePackage(REGION, "dom", null, "repo",
|
||||
"generic", "ns", "never-published");
|
||||
assertEquals("BLOCK", deleted.publishRestriction());
|
||||
assertEquals("BLOCK", deleted.upstreamRestriction());
|
||||
|
||||
AwsException gone = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom", null,
|
||||
"repo", "generic", "ns", "never-published"));
|
||||
assertEquals("ResourceNotFoundException", gone.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same case for a container-backed format: the sidecar still gets asked (unlike
|
||||
* describePackage's short-circuit, deletePackage cannot skip this: a package set up through
|
||||
* PutPackageOriginConfiguration could also have real content published to it directly through
|
||||
* the native protocol later, which deletePackage still has to find and remove), but it reports
|
||||
* nothing there, and the stored origin configuration alone must still let deletePackage
|
||||
* succeed rather than 404 on a package describePackage itself finds.
|
||||
*/
|
||||
@Test
|
||||
void deletePackageRemovesAnOriginConfigOnlyContainerBackedPackageThatTheSidecarNeverHeardOf() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "pypi", null, "never-published", "ALLOW",
|
||||
"BLOCK");
|
||||
when(pypiserverClient.packageExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("never-published")))
|
||||
.thenReturn(false);
|
||||
|
||||
CodeArtifactService.PackageDescription deleted = service.deletePackage(REGION, "dom", null, "repo", "pypi",
|
||||
null, "never-published");
|
||||
assertEquals("ALLOW", deleted.publishRestriction());
|
||||
verify(pypiserverClient, never()).deletePackage(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePackageBridgesToReposiliteForMavenAfterConfirmingItExists() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
|
||||
Reference in new issue
Block a user