@@ -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)
@@ -157,7 +156,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
157156 "cacheTablename" : "BlobTable" ,
158157 "repoMetaTablename" : "RepoMetadataTable" ,
159158 "manifestDataTablename" : "ManifestDataTable" ,
160- "artifactDataTablename" : "ArtifactDataTable" ,
161159 "userDataTablename" : "ZotUserDataTable" ,
162160 "versionTablename" : "Version" ,
163161 }
@@ -173,7 +171,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
173171 "cacheTablename" : "BlobTable" ,
174172 "repoMetaTablename" : "RepoMetadataTable" ,
175173 "manifestDataTablename" : "ManifestDataTable" ,
176- "artifactDataTablename" : "ArtifactDataTable" ,
177174 "userDataTablename" : "ZotUserDataTable" ,
178175 "versionTablename" : "Version" ,
179176 }
@@ -188,7 +185,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
188185 "cacheTablename" : "BlobTable" ,
189186 "repoMetaTablename" : "RepoMetadataTable" ,
190187 "manifestDataTablename" : "ManifestDataTable" ,
191- "artifactDataTablename" : "ArtifactDataTable" ,
192188 "userDataTablename" : "ZotUserDataTable" ,
193189 "versionTablename" : "Version" ,
194190 }
@@ -222,7 +218,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
222218 "cachetablename" : "BlobTable" ,
223219 "repometatablename" : "RepoMetadataTable" ,
224220 "manifestdatatablename" : "ManifestDataTable" ,
225- "artifactDataTablename" : "ArtifactDataTable" ,
226221 "userdatatablename" : "UserDatatable" ,
227222 }
228223
@@ -236,7 +231,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
236231 "cachetablename" : "" ,
237232 "repometatablename" : "RepoMetadataTable" ,
238233 "manifestdatatablename" : "ManifestDataTable" ,
239- "artifactDataTablename" : "ArtifactDataTable" ,
240234 "userDataTablename" : "ZotUserDataTable" ,
241235 "versiontablename" : 1 ,
242236 }
@@ -252,7 +246,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
252246 "repometatablename" : "RepoMetadataTable" ,
253247 "manifestdatatablename" : "ManifestDataTable" ,
254248 "indexdatatablename" : "IndexDataTable" ,
255- "artifactdatatablename" : "ArtifactDataTable" ,
256249 "userdatatablename" : "ZotUserDataTable" ,
257250 "versiontablename" : "1" ,
258251 }
@@ -4395,138 +4388,15 @@ func TestArtifactReferences(t *testing.T) {
43954388 So (err , ShouldBeNil )
43964389 So (resp .StatusCode (), ShouldEqual , http .StatusOK )
43974390 So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4398- })
4399- })
4400-
4401- Convey ("Validate Artifact Manifest Reference" , func () {
4402- resp , err := resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4403- So (err , ShouldBeNil )
4404- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4405-
4406- var referrers ispec.Index
4407- err = json .Unmarshal (resp .Body (), & referrers )
4408- So (err , ShouldBeNil )
4409- So (referrers .Manifests , ShouldBeEmpty )
4410-
4411- // now upload a reference
4412-
4413- // upload image config blob
4414- resp , err = resty .R ().Post (baseURL + fmt .Sprintf ("/v2/%s/blobs/uploads/" , repoName ))
4415- So (err , ShouldBeNil )
4416- So (resp .StatusCode (), ShouldEqual , http .StatusAccepted )
4417- loc := test .Location (baseURL , resp )
4418- cblob , cdigest := test .GetEmptyImageConfig ()
4419-
4420- resp , err = resty .R ().
4421- SetContentLength (true ).
4422- SetHeader ("Content-Length" , fmt .Sprintf ("%d" , len (cblob ))).
4423- SetHeader ("Content-Type" , "application/octet-stream" ).
4424- SetQueryParam ("digest" , cdigest .String ()).
4425- SetBody (cblob ).
4426- Put (loc )
4427- So (err , ShouldBeNil )
4428- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4429-
4430- // create a artifact
4431- manifest := ispec.Artifact {
4432- MediaType : ispec .MediaTypeArtifactManifest ,
4433- ArtifactType : artifactType ,
4434- Blobs : []ispec.Descriptor {
4435- {
4436- MediaType : "application/vnd.oci.image.layer.v1.tar" ,
4437- Digest : digest ,
4438- Size : int64 (len (content )),
4439- },
4440- },
4441- Subject : & ispec.Descriptor {
4442- MediaType : ispec .MediaTypeImageManifest ,
4443- Digest : digest ,
4444- Size : int64 (len (content )),
4445- },
4446- Annotations : map [string ]string {
4447- "key" : "val" ,
4448- },
4449- }
4450- Convey ("Using invalid content" , func () {
4451- content := []byte ("invalid data" )
4452- So (err , ShouldBeNil )
4453- mdigest := godigest .FromBytes (content )
4454- So (mdigest , ShouldNotBeNil )
4455- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4456- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4457- So (err , ShouldBeNil )
4458- So (resp .StatusCode (), ShouldEqual , http .StatusBadRequest )
4459-
4460- // unknown repo will return status not found
4461- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , "unknown" , digest .String ()))
4462- So (err , ShouldBeNil )
4463- So (resp .StatusCode (), ShouldEqual , http .StatusNotFound )
4464-
4465- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4466- So (err , ShouldBeNil )
4467- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4391+ So (resp .Header ().Get ("OCI-Filters-Applied" ), ShouldEqual , artifactType )
44684392
4469- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4470- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4471- So (err , ShouldBeNil )
4472- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4473- })
4474- Convey ("Using valid content" , func () {
4475- content , err = json .Marshal (manifest )
4476- So (err , ShouldBeNil )
4477- mdigest := godigest .FromBytes (content )
4478- So (mdigest , ShouldNotBeNil )
4479- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4480- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4481- So (err , ShouldBeNil )
4482- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4483-
4484- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4485- So (err , ShouldBeNil )
4486- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4487-
4488- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifact" : "invalid" }).
4489- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4490- So (err , ShouldBeNil )
4491- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4492-
4493- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : "invalid" }).
4494- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4495- So (err , ShouldBeNil )
4496- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4497-
4498- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4499- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4393+ resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType +
4394+ ",otherArtType" }).Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName ,
4395+ digest .String ()))
45004396 So (err , ShouldBeNil )
45014397 So (resp .StatusCode (), ShouldEqual , http .StatusOK )
45024398 So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4503-
4504- var index ispec.Index
4505- err = json .Unmarshal (resp .Body (), & index )
4506- So (err , ShouldBeNil )
4507- So (index .Manifests , ShouldNotBeEmpty )
4508- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4509-
4510- // filter by multiple artifactTypes
4511- req , err := http .NewRequestWithContext (context .TODO (), http .MethodGet ,
4512- baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()), nil )
4513- So (err , ShouldBeNil )
4514- values := url.Values {}
4515- values .Add ("artifactType" , artifactType )
4516- values .Add ("artifactType" , "foobar" )
4517- req .URL .RawQuery = values .Encode ()
4518- rsp , err := http .DefaultClient .Do (req )
4519- So (err , ShouldBeNil )
4520- defer rsp .Body .Close ()
4521- So (rsp .StatusCode , ShouldEqual , http .StatusOK )
4522- So (rsp .Header .Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4523- body , err := io .ReadAll (rsp .Body )
4524- So (err , ShouldBeNil )
4525- err = json .Unmarshal (body , & index )
4526- So (err , ShouldBeNil )
4527- So (index .Manifests , ShouldNotBeEmpty )
4528- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4529- So (len (strings .Split (index .Annotations [storageConstants .ReferrerFilterAnnotation ], "," )), ShouldEqual , 2 )
4399+ So (resp .Header ().Get ("OCI-Filters-Applied" ), ShouldEqual , artifactType + ",otherArtType" )
45304400 })
45314401 })
45324402 })
0 commit comments