@@ -18,11 +18,14 @@ package integration
1818
1919import (
2020 "encoding/json"
21+ "fmt"
2122 "slices"
23+ "strings"
2224 "testing"
2325
2426 "github.com/awslabs/soci-snapshotter/soci"
2527 shell "github.com/awslabs/soci-snapshotter/util/dockershell"
28+ "github.com/containerd/platforms"
2629 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2730)
2831
@@ -229,3 +232,72 @@ func TestConvertAndPush(t *testing.T) {
229232 })
230233 }
231234}
235+
236+ func TestInvalidConversion (t * testing.T ) {
237+ registryConfig := newRegistryConfig ()
238+ sh , done := newShellWithRegistry (t , registryConfig )
239+ defer done ()
240+
241+ tests := []struct {
242+ name string
243+ repo string
244+ modifier func (t * testing.T , sh * shell.Shell , img imageInfo )
245+ }{
246+ {
247+ name : "deleting manifest invalidates image" ,
248+ repo : "manifest" ,
249+ modifier : func (t * testing.T , sh * shell.Shell , img imageInfo ) {
250+ digest , err := getManifestDigest (sh , img .ref , platforms .DefaultSpec ())
251+ if err != nil {
252+ t .Fatalf ("failed to get manifest digest: %v" , err )
253+ }
254+ sh .X ("ctr" , "content" , "delete" , digest )
255+ },
256+ },
257+ {
258+ name : "deleting soci index invalidates image" ,
259+ repo : "sociindex" ,
260+ modifier : func (t * testing.T , sh * shell.Shell , img imageInfo ) {
261+ index , err := getImageIndex (sh , img .ref )
262+ if err != nil {
263+ t .Fatalf ("failed to get image index: %v" , err )
264+ }
265+ idx := slices .IndexFunc (index .Manifests , func (desc ocispec.Descriptor ) bool {
266+ return desc .ArtifactType == soci .SociIndexArtifactTypeV2
267+ })
268+ if idx == - 1 {
269+ t .Fatalf ("no soci index found" )
270+ }
271+ sh .X ("ctr" , "content" , "delete" , index .Manifests [idx ].Digest .String ())
272+ },
273+ },
274+ }
275+
276+ for _ , imageName := range convertImages {
277+ t .Run (imageName , func (t * testing.T ) {
278+ rebootContainerd (t , sh , "" , "" )
279+ img := dockerhub (imageName )
280+
281+ sh .X ("nerdctl" , "pull" , "--all-platforms" , img .ref )
282+
283+ for _ , test := range tests {
284+ t .Run (test .name , func (t * testing.T ) {
285+ imageName = fmt .Sprintf ("%s/%s" , test .repo , imageName )
286+ convertedImg := registryConfig .mirror (imageName )
287+ sh .X ("soci" , "convert" , "--min-layer-size" , "0" , img .ref , convertedImg .ref )
288+
289+ test .modifier (t , sh , convertedImg )
290+
291+ sh .X ("nerdctl" , "login" , "--username" , registryConfig .user , "--password" , registryConfig .pass , convertedImg .ref )
292+ out , err := sh .CombinedOLog ("nerdctl" , "push" , "--all-platforms" , convertedImg .ref )
293+ if err == nil {
294+ t .Fatalf ("expected push to fail" )
295+ }
296+ if ! strings .Contains (string (out ), "not found" ) {
297+ t .Fatalf ("expected push to fail with 'not found' error, got %s" , string (out ))
298+ }
299+ })
300+ }
301+ })
302+ }
303+ }
0 commit comments