mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): apply ImageScanningConfiguration on AWS::ECR::Repository (#9215)
Read ImageScanningConfiguration.ScanOnPush in EcrCfnProvisioner and pass it to createRepository, and call putImageScanningConfiguration on an in-place update when the template declares it. An update that drops the property leaves the stored setting in place, as the ECR resource handler does. AWS::ECR::Repository ImageScanningConfiguration leaves the writable-property gap list. Closes #9198
This commit is contained in:
1 parent
ce02956615
commit
749daf638f
4 files changed
+280
-7
No files matched your search
+72
@@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -403,6 +404,77 @@ class LeafCfnProvisionerTest {
|
||||
verify(ecr, never()).deleteLifecyclePolicy(anyString(), any(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageScanningConfigurationReachesCreateRepository() {
|
||||
when(ecr.createRepository(eq("app"), eq(null), eq(null), eq(Boolean.TRUE),
|
||||
eq(null), eq(null), any(), eq(REGION)))
|
||||
.thenReturn(repo("arn:app", "uri:app"));
|
||||
|
||||
provisioner.provision(resource("Repo", "AWS::ECR::Repository"), props("""
|
||||
{"RepositoryName": "app", "ImageScanningConfiguration": {"ScanOnPush": true}}
|
||||
"""), ctx);
|
||||
|
||||
verify(ecr).createRepository(eq("app"), eq(null), eq(null), eq(Boolean.TRUE),
|
||||
eq(null), eq(null), any(), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageScanningConfigurationStringTrueFromRefReachesCreateRepository() {
|
||||
when(ecr.createRepository(eq("app"), eq(null), eq(null), eq(Boolean.TRUE),
|
||||
eq(null), eq(null), any(), eq(REGION)))
|
||||
.thenReturn(repo("arn:app", "uri:app"));
|
||||
|
||||
provisioner.provision(resource("Repo", "AWS::ECR::Repository"), props("""
|
||||
{"RepositoryName": "app", "ImageScanningConfiguration": {"ScanOnPush": "true"}}
|
||||
"""), ctx);
|
||||
|
||||
verify(ecr).createRepository(eq("app"), eq(null), eq(null), eq(Boolean.TRUE),
|
||||
eq(null), eq(null), any(), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedImageScanningConfigurationPassesNullToCreateRepository() {
|
||||
when(ecr.createRepository(eq("app"), eq(null), eq(null), eq(null),
|
||||
eq(null), eq(null), any(), eq(REGION)))
|
||||
.thenReturn(repo("arn:app", "uri:app"));
|
||||
|
||||
provisioner.provision(resource("Repo", "AWS::ECR::Repository"), props("""
|
||||
{"RepositoryName": "app"}
|
||||
"""), ctx);
|
||||
|
||||
verify(ecr).createRepository(eq("app"), eq(null), eq(null), eq(null),
|
||||
eq(null), eq(null), any(), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingImageScanningConfigurationCallsPutImageScanningConfiguration() {
|
||||
Repository updated = repo("arn:updated", "uri:updated");
|
||||
when(ecr.putImageTagMutability("app", null, "MUTABLE", REGION))
|
||||
.thenReturn(repo("arn:existing", "uri:existing"));
|
||||
when(ecr.putImageScanningConfiguration("app", null, true, REGION))
|
||||
.thenReturn(updated);
|
||||
|
||||
StackResource r = resource("Repo", "AWS::ECR::Repository");
|
||||
provisioner.provision(r, props("""
|
||||
{"RepositoryName": "app", "ImageScanningConfiguration": {"ScanOnPush": true}}
|
||||
"""), new ProvisionContext(engine, REGION, "000000000000", "my-stack", "app"));
|
||||
|
||||
verify(ecr).putImageScanningConfiguration("app", null, true, REGION);
|
||||
assertEquals("arn:updated", r.getAttributes().get("Arn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void droppingImageScanningConfigurationOnUpdateLeavesItUnchanged() {
|
||||
when(ecr.putImageTagMutability("app", null, "MUTABLE", REGION))
|
||||
.thenReturn(repo("arn:existing", "uri:existing"));
|
||||
|
||||
provisioner.provision(resource("Repo", "AWS::ECR::Repository"), props("""
|
||||
{"RepositoryName": "app"}
|
||||
"""), new ProvisionContext(engine, REGION, "000000000000", "my-stack", "app"));
|
||||
|
||||
verify(ecr, never()).putImageScanningConfiguration(anyString(), any(), anyBoolean(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteForcesRemovalSoANonEmptyRepositoryStillGoes() {
|
||||
provisioner.delete("AWS::ECR::Repository", "app", REGION);
|
||||
|
||||
Reference in new issue
Block a user