@@ -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 }
@@ -4312,138 +4305,15 @@ func TestArtifactReferences(t *testing.T) {
43124305 So (err , ShouldBeNil )
43134306 So (resp .StatusCode (), ShouldEqual , http .StatusOK )
43144307 So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4315- })
4316- })
4317-
4318- Convey ("Validate Artifact Manifest Reference" , func () {
4319- resp , err := resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4320- So (err , ShouldBeNil )
4321- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4322-
4323- var referrers ispec.Index
4324- err = json .Unmarshal (resp .Body (), & referrers )
4325- So (err , ShouldBeNil )
4326- So (referrers .Manifests , ShouldBeEmpty )
4327-
4328- // now upload a reference
4329-
4330- // upload image config blob
4331- resp , err = resty .R ().Post (baseURL + fmt .Sprintf ("/v2/%s/blobs/uploads/" , repoName ))
4332- So (err , ShouldBeNil )
4333- So (resp .StatusCode (), ShouldEqual , http .StatusAccepted )
4334- loc := test .Location (baseURL , resp )
4335- cblob , cdigest := test .GetEmptyImageConfig ()
4336-
4337- resp , err = resty .R ().
4338- SetContentLength (true ).
4339- SetHeader ("Content-Length" , fmt .Sprintf ("%d" , len (cblob ))).
4340- SetHeader ("Content-Type" , "application/octet-stream" ).
4341- SetQueryParam ("digest" , cdigest .String ()).
4342- SetBody (cblob ).
4343- Put (loc )
4344- So (err , ShouldBeNil )
4345- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4346-
4347- // create a artifact
4348- manifest := ispec.Artifact {
4349- MediaType : ispec .MediaTypeArtifactManifest ,
4350- ArtifactType : artifactType ,
4351- Blobs : []ispec.Descriptor {
4352- {
4353- MediaType : "application/vnd.oci.image.layer.v1.tar" ,
4354- Digest : digest ,
4355- Size : int64 (len (content )),
4356- },
4357- },
4358- Subject : & ispec.Descriptor {
4359- MediaType : ispec .MediaTypeImageManifest ,
4360- Digest : digest ,
4361- Size : int64 (len (content )),
4362- },
4363- Annotations : map [string ]string {
4364- "key" : "val" ,
4365- },
4366- }
4367- Convey ("Using invalid content" , func () {
4368- content := []byte ("invalid data" )
4369- So (err , ShouldBeNil )
4370- mdigest := godigest .FromBytes (content )
4371- So (mdigest , ShouldNotBeNil )
4372- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4373- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4374- So (err , ShouldBeNil )
4375- So (resp .StatusCode (), ShouldEqual , http .StatusBadRequest )
4376-
4377- // unknown repo will return status not found
4378- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , "unknown" , digest .String ()))
4379- So (err , ShouldBeNil )
4380- So (resp .StatusCode (), ShouldEqual , http .StatusNotFound )
4381-
4382- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4383- So (err , ShouldBeNil )
4384- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4308+ So (resp .Header ().Get ("OCI-Filters-Applied" ), ShouldEqual , artifactType )
43854309
4386- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4387- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4388- So (err , ShouldBeNil )
4389- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4390- })
4391- Convey ("Using valid content" , func () {
4392- content , err = json .Marshal (manifest )
4393- So (err , ShouldBeNil )
4394- mdigest := godigest .FromBytes (content )
4395- So (mdigest , ShouldNotBeNil )
4396- resp , err = resty .R ().SetHeader ("Content-Type" , ispec .MediaTypeArtifactManifest ).
4397- SetBody (content ).Put (baseURL + fmt .Sprintf ("/v2/%s/manifests/%s" , repoName , mdigest .String ()))
4398- So (err , ShouldBeNil )
4399- So (resp .StatusCode (), ShouldEqual , http .StatusCreated )
4400-
4401- resp , err = resty .R ().Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4402- So (err , ShouldBeNil )
4403- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4404-
4405- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifact" : "invalid" }).
4406- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4407- So (err , ShouldBeNil )
4408- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4409-
4410- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : "invalid" }).
4411- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4412- So (err , ShouldBeNil )
4413- So (resp .StatusCode (), ShouldEqual , http .StatusOK )
4414-
4415- resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType }).
4416- Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()))
4310+ resp , err = resty .R ().SetQueryParams (map [string ]string {"artifactType" : artifactType +
4311+ ",otherArtType" }).Get (baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName ,
4312+ digest .String ()))
44174313 So (err , ShouldBeNil )
44184314 So (resp .StatusCode (), ShouldEqual , http .StatusOK )
44194315 So (resp .Header ().Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4420-
4421- var index ispec.Index
4422- err = json .Unmarshal (resp .Body (), & index )
4423- So (err , ShouldBeNil )
4424- So (index .Manifests , ShouldNotBeEmpty )
4425- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4426-
4427- // filter by multiple artifactTypes
4428- req , err := http .NewRequestWithContext (context .TODO (), http .MethodGet ,
4429- baseURL + fmt .Sprintf ("/v2/%s/referrers/%s" , repoName , digest .String ()), nil )
4430- So (err , ShouldBeNil )
4431- values := url.Values {}
4432- values .Add ("artifactType" , artifactType )
4433- values .Add ("artifactType" , "foobar" )
4434- req .URL .RawQuery = values .Encode ()
4435- rsp , err := http .DefaultClient .Do (req )
4436- So (err , ShouldBeNil )
4437- defer rsp .Body .Close ()
4438- So (rsp .StatusCode , ShouldEqual , http .StatusOK )
4439- So (rsp .Header .Get ("Content-Type" ), ShouldEqual , ispec .MediaTypeImageIndex )
4440- body , err := io .ReadAll (rsp .Body )
4441- So (err , ShouldBeNil )
4442- err = json .Unmarshal (body , & index )
4443- So (err , ShouldBeNil )
4444- So (index .Manifests , ShouldNotBeEmpty )
4445- So (index .Annotations [storageConstants .ReferrerFilterAnnotation ], ShouldNotBeEmpty )
4446- So (len (strings .Split (index .Annotations [storageConstants .ReferrerFilterAnnotation ], "," )), ShouldEqual , 2 )
4316+ So (resp .Header ().Get ("OCI-Filters-Applied" ), ShouldEqual , artifactType + ",otherArtType" )
44474317 })
44484318 })
44494319 })
0 commit comments