mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: preserve legacy CodeArtifact package origin records (#7469)
This commit is contained in:
1 parent
8b756a3467
commit
a98380b387
3 files changed
+447
-18
No files matched your search
+57
-1
@@ -623,6 +623,54 @@ class CodeArtifactAssetPersistenceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyNugetOriginConfigurationMigratesAndStaysDeletedAfterRestart(@TempDir Path dir) {
|
||||
legacyOriginConfigurationMigratesAndStaysDeleted(dir, "nuget", "Newtonsoft.Json", "newtonsoft.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyPypiOriginConfigurationMigratesAndStaysDeletedAfterRestart(@TempDir Path dir) {
|
||||
legacyOriginConfigurationMigratesAndStaysDeleted(dir, "pypi", "My_Proj", "my-proj");
|
||||
}
|
||||
|
||||
private void legacyOriginConfigurationMigratesAndStaysDeleted(Path dir, String format,
|
||||
String original, String normalized) {
|
||||
CodeArtifactService first = newService(dir);
|
||||
first.createDomain(REGION, "dom", null, Map.of());
|
||||
first.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String file = "codeartifact-package-origin-configs.json";
|
||||
String prefix = REGION + "::dom::repo::" + format + "::::";
|
||||
AccountAwareStorageBackend<PackageOriginConfig> oldStore = accountAware(dir, file,
|
||||
new TypeReference<Map<String, PackageOriginConfig>>() {});
|
||||
oldStore.putForAccount(ACCOUNT_ID, prefix + original,
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", null, null, null));
|
||||
|
||||
CodeArtifactService upgraded = newService(dir);
|
||||
CodeArtifactService.ListPackagesResult listed = upgraded.listPackages(REGION, "dom", null, "repo",
|
||||
format, null, null, null, null, "BLOCK", "BLOCK");
|
||||
assertEquals(List.of(normalized), listed.packages().stream()
|
||||
.map(CodeArtifactService.PackageSummaryEntry::packageName).toList());
|
||||
assertTrue(upgraded.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, normalized));
|
||||
AccountAwareStorageBackend<PackageOriginConfig> migrated = accountAware(dir, file,
|
||||
new TypeReference<Map<String, PackageOriginConfig>>() {});
|
||||
assertTrue(migrated.getForAccount(ACCOUNT_ID, prefix + original).isEmpty());
|
||||
assertTrue(migrated.getForAccount(ACCOUNT_ID, prefix + normalized).isPresent());
|
||||
|
||||
CodeArtifactService restarted = newService(dir);
|
||||
CodeArtifactService.PackageDescription described = restarted.describePackage(REGION, "dom", null,
|
||||
"repo", format, null, original);
|
||||
assertEquals("BLOCK", described.publishRestriction());
|
||||
assertEquals("BLOCK", described.upstreamRestriction());
|
||||
restarted.deletePackage(REGION, "dom", null, "repo", format, null, normalized);
|
||||
|
||||
CodeArtifactService afterDelete = newService(dir);
|
||||
assertThrows(AwsException.class, () -> afterDelete.describePackage(REGION, "dom", null,
|
||||
"repo", format, null, original));
|
||||
AccountAwareStorageBackend<PackageOriginConfig> deleted = accountAware(dir, file,
|
||||
new TypeReference<Map<String, PackageOriginConfig>>() {});
|
||||
assertTrue(deleted.keysForAccount(ACCOUNT_ID).isEmpty());
|
||||
}
|
||||
|
||||
private CodeArtifactService newService(Path dir) {
|
||||
AccountAwareStorageBackend<CodeArtifactDomain> domainStore = accountAware(dir, "codeartifact-domains.json",
|
||||
new TypeReference<Map<String, CodeArtifactDomain>>() {});
|
||||
@@ -644,7 +692,15 @@ class CodeArtifactAssetPersistenceTest {
|
||||
|
||||
return new CodeArtifactService(domainStore, repoStore, packageVersionStore, packageOriginConfigStore,
|
||||
regionResolver, config, false, dir.resolve("codeartifact-assets"),
|
||||
new CodeArtifactSidecarRegistry(List.of()));
|
||||
persistenceSidecars());
|
||||
}
|
||||
|
||||
private CodeArtifactSidecarRegistry persistenceSidecars() {
|
||||
BagetterSidecarClient nuget = mock(BagetterSidecarClient.class);
|
||||
when(nuget.format()).thenReturn("nuget");
|
||||
PypiserverSidecarClient pypi = mock(PypiserverSidecarClient.class);
|
||||
when(pypi.format()).thenReturn("pypi");
|
||||
return new CodeArtifactSidecarRegistry(List.of(nuget, pypi));
|
||||
}
|
||||
|
||||
private <V> AccountAwareStorageBackend<V> accountAware(Path dir, String fileName, TypeReference<Map<String, V>> type) {
|
||||
|
||||
+300
@@ -20,6 +20,8 @@ import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -67,6 +69,7 @@ import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -6511,6 +6514,36 @@ class CodeArtifactServiceTest {
|
||||
assertEquals(3, result.packages().stream().filter(p -> "my-pkg".equals(p.packageName())).count());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"nuget", "pypi"})
|
||||
void listPackagesDoesNotRescanOriginKeysForUnconfiguredPackages(String format) {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService listingService = new CodeArtifactService(AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID), AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
origins, regionResolver, mock(EmulatorConfig.class), true, null,
|
||||
new CodeArtifactSidecarRegistry(List.of(pypiserverClient, bagetterClient)));
|
||||
listingService.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository repository = listingService.createRepository(REGION, "dom", null, "repo",
|
||||
null, null, Map.of());
|
||||
origins.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::" + format + "::::configured",
|
||||
new PackageOriginConfig("BLOCK", "ALLOW", format, null, "configured"));
|
||||
RepositorySidecarManager manager = "nuget".equals(format) ? bagetterClient : pypiserverClient;
|
||||
when(manager.listPackages(eq(repository.getSidecarContainerIds().get(format)), eq("dom"), eq("repo")))
|
||||
.thenReturn(List.of(new RepositorySidecarManager.PackageIdentifier(null, "first"),
|
||||
new RepositorySidecarManager.PackageIdentifier(null, "second")));
|
||||
clearInvocations(origins);
|
||||
|
||||
CodeArtifactService.ListPackagesResult result = listingService.listPackages(REGION, "dom", null, "repo",
|
||||
format, null, null, null, null, null, null);
|
||||
|
||||
assertEquals(3, result.packages().size());
|
||||
assertEquals(2, result.packages().stream().filter(entry -> "ALLOW".equals(entry.publishRestriction())
|
||||
&& "BLOCK".equals(entry.upstreamRestriction())).count());
|
||||
assertTrue(result.packages().stream().anyMatch(entry -> "configured".equals(entry.packageName())
|
||||
&& "BLOCK".equals(entry.publishRestriction()) && "ALLOW".equals(entry.upstreamRestriction())));
|
||||
verify(origins, times(1)).keysForAccount(ACCOUNT_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPackagesFormatFilterOnlyTouchesThatOneFormatsSidecar() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
@@ -7078,4 +7111,271 @@ class CodeArtifactServiceTest {
|
||||
"my-pkg", "1.0.0");
|
||||
assertEquals(assetCount, pv.getAssets().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyNugetOriginRestrictionRemainsEffective() {
|
||||
assertLegacyRestriction("nuget", "Newtonsoft.Json", "newtonsoft.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyPypiOriginRestrictionRemainsEffective() {
|
||||
assertLegacyRestriction("pypi", "My_Proj", "my-proj");
|
||||
}
|
||||
|
||||
private void assertLegacyRestriction(String format, String original, String normalized) {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String legacyKey = REGION + "::dom::repo::" + format + "::::" + original;
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, legacyKey,
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", format, null, original));
|
||||
assertTrue(service.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, normalized));
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalizedNugetOriginRestrictionControl() {
|
||||
assertNormalizedRestriction("nuget", "Newtonsoft.Json", "newtonsoft.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalizedPypiOriginRestrictionControl() {
|
||||
assertNormalizedRestriction("pypi", "My_Proj", "my-proj");
|
||||
}
|
||||
|
||||
private void assertNormalizedRestriction(String format, String original, String normalized) {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", format, null, original, "BLOCK", "BLOCK");
|
||||
assertTrue(service.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, normalized));
|
||||
}
|
||||
@Test
|
||||
void readingLegacyOriginConfigMigratesItBeforeRemovingTheOldKey() {
|
||||
assertLegacyRestriction("nuget", "Newtonsoft.Json", "newtonsoft.json");
|
||||
assertTrue(packageOriginConfigStore.getForAccount(ACCOUNT_ID,
|
||||
REGION + "::dom::repo::nuget::::Newtonsoft.Json").isEmpty());
|
||||
assertTrue(packageOriginConfigStore.getForAccount(ACCOUNT_ID,
|
||||
REGION + "::dom::repo::nuget::::newtonsoft.json").isPresent());
|
||||
assertEquals("BLOCK", service.describePackage(REGION, "dom", null, "repo", "nuget", null,
|
||||
"NEWTONSOFT.JSON").publishRestriction());
|
||||
assertThrows(AwsException.class, () -> service.requireContainerBackedPackagePublishAllowed(REGION,
|
||||
"dom", null, "repo", "nuget", null, "NEWTONSOFT.JSON"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitOriginUpdateRetiresEveryLegacySpelling() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
for (String name : List.of("My_Proj", "MY.PROJ")) {
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::" + name,
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", "pypi", null, name));
|
||||
}
|
||||
service.putPackageOriginConfiguration(REGION, "dom", null, "repo", "pypi", null, "my-proj",
|
||||
"ALLOW", "ALLOW");
|
||||
assertEquals(List.of(REGION + "::dom::repo::pypi::::my-proj"),
|
||||
packageOriginConfigStore.keysForAccount(ACCOUNT_ID).stream().sorted().toList());
|
||||
assertFalse(service.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "pypi", null, "MY_PROJ"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountMigrationPreservesOtherOwnersAndCoordinateBoundaries() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
PackageOriginConfig config = new PackageOriginConfig("BLOCK", "BLOCK", "nuget", null, "Newtonsoft.Json");
|
||||
packageOriginConfigStore.putForAccount("999999999999", REGION + "::dom::repo::nuget::::Newtonsoft.Json", config);
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::other::nuget::::Newtonsoft.Json", config);
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, OTHER_REGION + "::dom::repo::nuget::::Newtonsoft.Json", config);
|
||||
assertFalse(service.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "nuget", null, "newtonsoft.json"));
|
||||
assertTrue(packageOriginConfigStore.getForAccount(ACCOUNT_ID,
|
||||
REGION + "::dom::repo::nuget::::newtonsoft.json").isEmpty());
|
||||
assertEquals(2, packageOriginConfigStore.keysForAccount(ACCOUNT_ID).size());
|
||||
assertEquals(1, packageOriginConfigStore.keysForAccount("999999999999").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void conflictingLegacySpellingsPreserveBothBlocks() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::My_Proj",
|
||||
new PackageOriginConfig("BLOCK", "ALLOW", "pypi", null, "My_Proj"));
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::MY.PROJ",
|
||||
new PackageOriginConfig("ALLOW", "BLOCK", "pypi", null, "MY.PROJ"));
|
||||
CodeArtifactService.PackageDescription description = service.describePackage(REGION, "dom", null, "repo",
|
||||
"pypi", null, "my-proj");
|
||||
assertEquals("BLOCK", description.publishRestriction());
|
||||
assertEquals("BLOCK", description.upstreamRestriction());
|
||||
assertEquals(1, packageOriginConfigStore.keysForAccount(ACCOUNT_ID).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingCanonicalPackageAlsoRemovesLegacyOriginEntries() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::my-proj",
|
||||
new PackageOriginConfig("ALLOW", "ALLOW", "pypi", null, "my-proj"));
|
||||
packageOriginConfigStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::My_Proj",
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", "pypi", null, "My_Proj"));
|
||||
assertFalse(service.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "pypi", null, "MY_PROJ"));
|
||||
service.deletePackage(REGION, "dom", null, "repo", "pypi", null, "my-proj");
|
||||
assertTrue(packageOriginConfigStore.keysForAccount(ACCOUNT_ID).isEmpty());
|
||||
assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom", null, "repo",
|
||||
"pypi", null, "MY_PROJ"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedMigrationSavePreservesLegacyRestrictionsForRetry() {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> store = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService failingService = new CodeArtifactService(AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID), AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
store, regionResolver, mock(EmulatorConfig.class), true, null,
|
||||
new CodeArtifactSidecarRegistry(List.of()));
|
||||
failingService.createDomain(REGION, "dom", null, Map.of());
|
||||
failingService.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String legacyKey = REGION + "::dom::repo::nuget::::Newtonsoft.Json";
|
||||
String canonicalKey = REGION + "::dom::repo::nuget::::newtonsoft.json";
|
||||
store.putForAccount(ACCOUNT_ID, legacyKey,
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", "nuget", null, "Newtonsoft.Json"));
|
||||
doThrow(new IllegalStateException("save failed")).when(store)
|
||||
.putForAccount(eq(ACCOUNT_ID), eq(canonicalKey), any(PackageOriginConfig.class));
|
||||
assertThrows(IllegalStateException.class, () -> failingService.isUpstreamRetentionBlocked(REGION,
|
||||
"dom", null, "repo", "nuget", null, "newtonsoft.json"));
|
||||
assertTrue(store.getForAccount(ACCOUNT_ID, legacyKey).isPresent());
|
||||
assertTrue(store.getForAccount(ACCOUNT_ID, canonicalKey).isEmpty());
|
||||
doAnswer(invocation -> invocation.callRealMethod()).when(store)
|
||||
.putForAccount(eq(ACCOUNT_ID), eq(canonicalKey), any(PackageOriginConfig.class));
|
||||
assertTrue(failingService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "nuget", null,
|
||||
"newtonsoft.json"));
|
||||
assertTrue(store.getForAccount(ACCOUNT_ID, legacyKey).isEmpty());
|
||||
assertTrue(store.getForAccount(ACCOUNT_ID, canonicalKey).isPresent());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"nuget", "pypi"})
|
||||
void ordinaryOriginLookupsMigrateAccountOnlyOnce(String format) {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
origins.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::" + format + "::::Legacy_Package",
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", format, null, "Legacy_Package"));
|
||||
clearInvocations(origins);
|
||||
|
||||
for (String name : List.of("first", "second")) {
|
||||
lookupService.requireContainerBackedPackagePublishAllowed(REGION, "dom", null, "repo", format, null, name);
|
||||
assertFalse(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, name));
|
||||
assertThrows(AwsException.class, () -> lookupService.describePackage(REGION, "dom", null, "repo",
|
||||
format, null, name));
|
||||
lookupService.listPackages(REGION, "dom", null, "repo", format, null, null, null, null, null, null);
|
||||
}
|
||||
String normalized = "pypi".equals(format) ? "legacy-package" : "legacy_package";
|
||||
assertEquals("BLOCK", lookupService.describePackage(REGION, "dom", null, "repo", format, null,
|
||||
normalized).publishRestriction());
|
||||
assertThrows(AwsException.class, () -> lookupService.requireContainerBackedPackagePublishAllowed(REGION,
|
||||
"dom", null, "repo", format, null, normalized));
|
||||
verify(origins, times(1)).keysForAccount(ACCOUNT_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountMigrationRetriesFailedAliasDeletionBeforeCachingCompletion() {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
String legacy = REGION + "::dom::repo::pypi::::My_Proj";
|
||||
String canonical = REGION + "::dom::repo::pypi::::my-proj";
|
||||
origins.putForAccount(ACCOUNT_ID, legacy, new PackageOriginConfig("BLOCK", "BLOCK", "pypi", null, "My_Proj"));
|
||||
doThrow(new IllegalStateException("controlled delete failure")).when(origins).deleteForAccount(ACCOUNT_ID, legacy);
|
||||
assertThrows(IllegalStateException.class, () -> lookupService.isUpstreamRetentionBlocked(REGION,
|
||||
"dom", null, "repo", "pypi", null, "my-proj"));
|
||||
assertTrue(origins.getForAccount(ACCOUNT_ID, canonical).isPresent());
|
||||
assertTrue(origins.getForAccount(ACCOUNT_ID, legacy).isPresent());
|
||||
doAnswer(invocation -> invocation.callRealMethod()).when(origins).deleteForAccount(ACCOUNT_ID, legacy);
|
||||
assertTrue(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "pypi", null, "my-proj"));
|
||||
assertTrue(origins.getForAccount(ACCOUNT_ID, legacy).isEmpty());
|
||||
lookupService.requireContainerBackedPackagePublishAllowed(REGION, "dom", null, "repo", "pypi", null, "new");
|
||||
verify(origins, times(2)).keysForAccount(ACCOUNT_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearingServiceResetsAccountMigration() {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
assertFalse(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "pypi", null, "absent"));
|
||||
lookupService.clear();
|
||||
lookupService.createDomain(REGION, "dom", null, Map.of());
|
||||
lookupService.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
origins.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::pypi::::My_Proj",
|
||||
new PackageOriginConfig("BLOCK", "BLOCK", "pypi", null, "My_Proj"));
|
||||
assertTrue(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", "pypi", null, "my-proj"));
|
||||
verify(origins, times(2)).keysForAccount(ACCOUNT_ID);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"nuget", "pypi"})
|
||||
void firstOriginLookupDoesNotRewriteCanonicalRecords(String format) {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
for (String name : List.of("first", "second", "third")) {
|
||||
origins.putForAccount(ACCOUNT_ID, REGION + "::dom::repo::" + format + "::::" + name,
|
||||
new PackageOriginConfig("BLOCK", "ALLOW", format, null, name));
|
||||
}
|
||||
clearInvocations(origins);
|
||||
|
||||
assertEquals("BLOCK", lookupService.describePackage(REGION, "dom", null, "repo", format, null,
|
||||
"first").publishRestriction());
|
||||
assertFalse(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, "second"));
|
||||
|
||||
verify(origins, never()).putForAccount(anyString(), anyString(), any(PackageOriginConfig.class));
|
||||
verify(origins, never()).deleteForAccount(anyString(), anyString());
|
||||
verify(origins, times(1)).keysForAccount(ACCOUNT_ID);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"nuget", "pypi"})
|
||||
void canonicalOriginCoordinatesAreRepairedBeforeAliasRemoval(String format) {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
String canonical = REGION + "::dom::repo::" + format + "::::example";
|
||||
String legacy = REGION + "::dom::repo::" + format + "::::EXAMPLE";
|
||||
origins.putForAccount(ACCOUNT_ID, canonical, new PackageOriginConfig("ALLOW", "BLOCK", null, null, null));
|
||||
origins.putForAccount(ACCOUNT_ID, legacy, new PackageOriginConfig("BLOCK", "ALLOW", format, null, "EXAMPLE"));
|
||||
clearInvocations(origins);
|
||||
|
||||
assertTrue(lookupService.isUpstreamRetentionBlocked(REGION, "dom", null, "repo", format, null, "example"));
|
||||
|
||||
PackageOriginConfig repaired = origins.getForAccount(ACCOUNT_ID, canonical).orElseThrow();
|
||||
assertEquals(format, repaired.getFormat());
|
||||
assertNull(repaired.getNamespace());
|
||||
assertEquals("example", repaired.getPackageName());
|
||||
assertEquals("ALLOW", repaired.getPublishRestriction());
|
||||
assertEquals("BLOCK", repaired.getUpstreamRestriction());
|
||||
InOrder order = inOrder(origins);
|
||||
order.verify(origins).putForAccount(ACCOUNT_ID, canonical, repaired);
|
||||
order.verify(origins).deleteForAccount(ACCOUNT_ID, legacy);
|
||||
verify(origins, times(1)).putForAccount(anyString(), anyString(), any(PackageOriginConfig.class));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"nuget", "pypi"})
|
||||
void unchangedCanonicalOriginRemovesAliasesWithoutRewriting(String format) {
|
||||
AccountAwareStorageBackend<PackageOriginConfig> origins = spy(AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
CodeArtifactService lookupService = originLookupService(origins);
|
||||
String canonical = REGION + "::dom::repo::" + format + "::::example";
|
||||
String legacy = REGION + "::dom::repo::" + format + "::::EXAMPLE";
|
||||
origins.putForAccount(ACCOUNT_ID, canonical, new PackageOriginConfig("ALLOW", "BLOCK", format, null, "example"));
|
||||
origins.putForAccount(ACCOUNT_ID, legacy, new PackageOriginConfig("BLOCK", "ALLOW", format, null, "EXAMPLE"));
|
||||
clearInvocations(origins);
|
||||
|
||||
assertEquals("ALLOW", lookupService.describePackage(REGION, "dom", null, "repo", format, null,
|
||||
"example").publishRestriction());
|
||||
assertTrue(origins.getForAccount(ACCOUNT_ID, legacy).isEmpty());
|
||||
assertEquals("BLOCK", origins.getForAccount(ACCOUNT_ID, canonical).orElseThrow().getUpstreamRestriction());
|
||||
verify(origins, never()).putForAccount(anyString(), anyString(), any(PackageOriginConfig.class));
|
||||
verify(origins).deleteForAccount(ACCOUNT_ID, legacy);
|
||||
}
|
||||
|
||||
private CodeArtifactService originLookupService(AccountAwareStorageBackend<PackageOriginConfig> origins) {
|
||||
CodeArtifactService lookupService = new CodeArtifactService(AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID), AccountAwareStorageBackend.inMemory(ACCOUNT_ID),
|
||||
origins, regionResolver, mock(EmulatorConfig.class), true, null,
|
||||
new CodeArtifactSidecarRegistry(List.of()));
|
||||
lookupService.createDomain(REGION, "dom", null, Map.of());
|
||||
lookupService.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
return lookupService;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user