@@ -198,42 +198,63 @@ func validateConversion(t *testing.T, sh *shell.Shell, originalDigest, converted
198198 t .Errorf ("manifest %v does not contain expected soci index digest %v" , manifestDesc , sociIndexDesc .Digest )
199199 }
200200
201- configDigest , err := getManifestLabelsAndConfigDigest (sh , manifestDesc .Digest .String ())
201+ // get labels associated with the manifest and extract the digest
202+ configDigest , err := getDigestLabelMapping (sh , manifestDesc .Digest .String ())
202203 if err != nil {
203204 t .Errorf ("failed to get config digest from manifest: %v" , err )
204205 continue
205206 }
206- configBytes := sh .O ("ctr" , "content" , "get" , configDigest )
207207
208- var configInfo ocispec.Image
209- if err := json .Unmarshal (configBytes , & configInfo ); err != nil {
210- fmt .Errorf ("failed to decode config: %v" , err )
208+ _ , err = verifyImageLayersContainsLabel (configDigest , manifest )
209+ if err != nil {
210+ t .Errorf ("error verifying layers: %v" , err )
211+ continue
211212 }
212-
213213 }
214214
215215}
216216
217- func getManifestLabelsAndConfigDigest (sh * shell.Shell , manifestDigest string ) (string , error ) {
218- gcConfigLabelKey := "containerd.io/gc.ref.content.config"
217+ func getDigestLabelMapping (sh * shell.Shell , manifestDigest string ) (map [ string ][] string , error ) {
218+ digestMap := make ( map [ string ][] string )
219219
220- // Get manifest labels
221220 manifestLabelOutput := sh .O ("ctr" , "content" , "label" , manifestDigest )
222221 manifestLabels := strings .Split (strings .TrimSpace (string (manifestLabelOutput )), "," )
223222
224223 if len (manifestLabels ) <= 0 {
225- return "" , fmt .Errorf ("manifest does not contain any labels" )
224+ return nil , fmt .Errorf ("manifest does not contain any labels" )
226225 }
227226
228- // Extract config digest from labels
229227 for _ , label := range manifestLabels {
230- parts := strings .Split (label , "=" )
231- if len (parts ) == 2 && parts [0 ] == gcConfigLabelKey {
232- return parts [1 ], nil
228+ keyVal := strings .Split (label , "=" )
229+ if len (keyVal ) != 2 {
230+ continue
231+ } else {
232+ digestMap [keyVal [1 ]] = append (digestMap [keyVal [1 ]], keyVal [0 ])
233233 }
234234 }
235+ return digestMap , nil
236+ }
235237
236- return "" , fmt .Errorf ("config label %q not found in manifest labels" , gcConfigLabelKey )
238+ func verifyImageLayersContainsLabel (digestMap map [string ][]string , manifest ocispec.Manifest ) (bool , error ) {
239+ for i := 0 ; i < len (manifest .Layers ); i = i + 1 {
240+ layerDigest := manifest .Layers [i ].Digest .String ()
241+ if labels , ok := digestMap [layerDigest ]; ok {
242+ found := false
243+ for _ , label := range labels {
244+ if strings .Contains (label , "containerd.io/gc.ref.content" ) {
245+ found = true
246+ break
247+ }
248+ }
249+ if ! found {
250+ return false , fmt .Errorf ("digest %s does not have associated gc label" , layerDigest )
251+ }
252+ } else {
253+ // Layer digest not found in digestMap
254+ return false , fmt .Errorf ("digest %s not found in digestMap" , layerDigest )
255+ }
256+ }
257+ return true , nil
237258}
238259
239260func TestConvert (t * testing.T ) {
0 commit comments