@@ -293,6 +293,38 @@ func TestPublishPublicECRTagsCandidateCleanupIsBestEffort(t *testing.T) {
293293 }
294294}
295295
296+ func TestPublishPublicECRTagsRefusesUnsafeCandidateCleanup (t * testing.T ) {
297+ digestFile := writeDigestFile (t , fmt .Sprintf ("%s public.ecr.aws/conductorone/bridge-client:temporary\n " , digestA ))
298+ fake := & fakeAWS {
299+ describeResults : []describeResult {
300+ {notFound : true },
301+ {digest : digestA },
302+ },
303+ }
304+ cfg := config {
305+ repositoryName : "bridge-client" ,
306+ versionTag : "1.2.3" ,
307+ candidateTag : "temporary" ,
308+ digestFile : digestFile ,
309+ registryURI : defaultRegistryURI ,
310+ }
311+ var stdout , stderr bytes.Buffer
312+
313+ err := publish (cfg , fake , & fakeDocker {}, & stdout , & stderr )
314+ if err != nil {
315+ t .Fatalf ("publish: %v" , err )
316+ }
317+ if fake .calledCommand ("batch-delete-image" ) {
318+ t .Fatal ("unsafe candidate tag must not be sent to BatchDeleteImage" )
319+ }
320+ if ! strings .Contains (stderr .String (), `refusing to delete non-candidate Public ECR tag "temporary"` ) {
321+ t .Fatalf ("stderr = %q" , stderr .String ())
322+ }
323+ if ! strings .Contains (stdout .String (), "Published public.ecr.aws/conductorone/bridge-client:1.2.3" ) {
324+ t .Fatalf ("stdout = %q" , stdout .String ())
325+ }
326+ }
327+
296328func runPublishForTest (t * testing.T , digestFile string , fake * fakeAWS ) (string , string , error ) {
297329 t .Helper ()
298330 return runPublishForTestWithDocker (t , digestFile , fake , & fakeDocker {})
0 commit comments