@@ -51,7 +51,6 @@ import (
5151 "zotregistry.io/zot/pkg/log"
5252 "zotregistry.io/zot/pkg/meta/repodb/repodbfactory"
5353 "zotregistry.io/zot/pkg/storage"
54- storageConstants "zotregistry.io/zot/pkg/storage/constants"
5554 "zotregistry.io/zot/pkg/storage/local"
5655 "zotregistry.io/zot/pkg/test"
5756)
@@ -3457,6 +3456,7 @@ func TestCrossRepoMount(t *testing.T) {
34573456 // wait for dedupe task to run
34583457 time .Sleep (15 * time .Second )
34593458
3459+ // TODO: What is happening here?
34603460 params ["mount" ] = string (manifestDigest )
34613461 postResponse , err = client .R ().
34623462 SetBasicAuth (username , passphrase ).SetQueryParams (params ).
@@ -4156,6 +4156,8 @@ func TestImageSignatures(t *testing.T) {
41564156 })
41574157}
41584158
4159+ // TODO: Refactor
4160+ // Here are notes to follow:
41594161func TestArtifactReferences (t * testing.T ) {
41604162 Convey ("Validate Artifact References" , t , func () {
41614163 // start a new server
@@ -4300,138 +4302,6 @@ func TestArtifactReferences(t *testing.T) {
43004302 So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
43014303 })
43024304 })
4303-
4304- Convey ("Validate Artifact Manifest Reference" , func () {
4305- resp , err := resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4306- So (err , ShouldBeNil )
4307- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4308-
4309- var referrers ispec.Index
4310- err = json .Unmarshal (resp .Body (), & referrers )
4311- So (err , ShouldBeNil )
4312- So (referrers .Manifests , ShouldBeEmpty )
4313-
4314- // now upload a reference
4315-
4316- // upload image config blob
4317- resp , err = resty .R ().Post (baseURL + fmt .Sprintf ("/v2/%s/blobs/uploads/" , repoName ))
4318- So (err , ShouldBeNil )
4319- So (resp .StatusCode (), ShouldEqual , http .StatusAccepted )
4320- loc := test .Location (baseURL , resp )
4321- cblob , cdigest := test .GetEmptyImageConfig ()
4322-
4323- resp , err = resty .R ().
4324- SetContentLength (true ).
4325- SetHeader ("Content-Length" , fmt .Sprintf ("%d" , len (cblob ))).
4326- SetHeader ("Content-Type" , "application/octet-stream" ).
4327- SetQueryParam ("digest" , cdigest .String ()).
4328- SetBody (cblob ).
4329- Put (loc )
4330- So (err , ShouldBeNil )
4331- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4332-
4333- // create a artifact
4334- manifest := ispec.Artifact {
4335- MediaType : ispec .MediaTypeArtifactManifest ,
4336- ArtifactType : artifactType ,
4337- Blobs : []ispec.Descriptor {
4338- {
4339- MediaType : "application/vnd.oci.image.layer.v1.tar" ,
4340- Digest : digest ,
4341- Size : int64 (len (content )),
4342- },
4343- },
4344- Subject : & ispec.Descriptor {
4345- MediaType : ispec .MediaTypeImageManifest ,
4346- Digest : digest ,
4347- Size : int64 (len (content )),
4348- },
4349- Annotations : map [string ]string {
4350- "key" : "val" ,
4351- },
4352- }
4353- Convey ("Using invalid content" , func () {
4354- content := []byte ("invalid data" )
4355- So (err , ShouldBeNil )
4356- mdigest := godigest .FromBytes (content )
4357- So (mdigest , ShouldNotBeNil )
4358- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4359- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4360- So (err , ShouldBeNil )
4361- So (resp .StatusCode (), ShouldEqual , http .StatusBadRequest )
4362-
4363- // unknown repo will return status not found
4364- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , "unknown" , digest .String ()))
4365- So (err , ShouldBeNil )
4366- So (resp .StatusCode (), ShouldEqual , http .StatusNotFound )
4367-
4368- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4369- So (err , ShouldBeNil )
4370- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4371-
4372- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4373- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4374- So (err , ShouldBeNil )
4375- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4376- })
4377- Convey ("Using valid content" , func () {
4378- content , err = json .Marshal (manifest )
4379- So (err , ShouldBeNil )
4380- mdigest := godigest .FromBytes (content )
4381- So (mdigest , ShouldNotBeNil )
4382- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4383- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4384- So (err , ShouldBeNil )
4385- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4386-
4387- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4388- So (err , ShouldBeNil )
4389- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4390-
4391- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifact" : "invalid" }).
4392- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4393- So (err , ShouldBeNil )
4394- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4395-
4396- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : "invalid" }).
4397- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4398- So (err , ShouldBeNil )
4399- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4400-
4401- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4402- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4403- So (err , ShouldBeNil )
4404- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4405- So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4406-
4407- var index ispec.Index
4408- err = json .Unmarshal (resp .Body (), & index )
4409- So (err , ShouldBeNil )
4410- So (index .Manifests , ShouldNotBeEmpty )
4411- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4412-
4413- // filter by multiple artifactTypes
4414- req , err := http .NewRequestWithContext (context .TODO (), http .MethodGet ,
4415- baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()), nil )
4416- So (err , ShouldBeNil )
4417- values := url.Values {}
4418- values .Add ("artifactType" , artifactType )
4419- values .Add ("artifactType" , "foobar" )
4420- req .URL .RawQuery = values .Encode ()
4421- rsp , err := http .DefaultClient .Do (req )
4422- So (err , ShouldBeNil )
4423- defer rsp .Body .Close ()
4424- So (rsp .StatusCode , ShouldEqual , http .StatusOK )
4425- So (rsp .Header .Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4426- body , err := io .ReadAll (rsp .Body )
4427- So (err , ShouldBeNil )
4428- err = json .Unmarshal (body , & index )
4429- So (err , ShouldBeNil )
4430- So (index .Manifests , ShouldNotBeEmpty )
4431- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4432- So (len (strings .Split (index .Annotations [storageConstants .ReferrerFilterAnnotation ], "," )), ShouldEqual , 2 )
4433- })
4434- })
44354305 })
44364306}
44374307
0 commit comments