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