@@ -11167,6 +11167,211 @@ func RunAuthorizationTests(t *testing.T, client *resty.Client, baseURL, user str
1116711167 })
1116811168}
1116911169
11170+ func TestSupportedDigestAlgorithms (t * testing.T ) {
11171+ port := test .GetFreePort ()
11172+ baseURL := test .GetBaseURL (port )
11173+
11174+ conf := config .New ()
11175+ conf .HTTP .Port = port
11176+
11177+ dir := t .TempDir ()
11178+
11179+ ctlr := api .NewController (conf )
11180+ ctlr .Config .Storage .RootDirectory = dir
11181+ ctlr .Config .Storage .Dedupe = false
11182+ ctlr .Config .Storage .GC = false
11183+
11184+ cm := test .NewControllerManager (ctlr )
11185+
11186+ cm .StartAndWait (port )
11187+ defer cm .StopServer ()
11188+
11189+ Convey ("Test SHA512 single-arch image" , t , func () {
11190+ image := CreateImageWithDigestAlgorithm (godigest .SHA512 ).
11191+ RandomLayers (1 , 10 ).DefaultConfig ().Build ()
11192+
11193+ name := "algo-sha512"
11194+ tag := "singlearch"
11195+
11196+ err := UploadImage (image , baseURL , name , tag )
11197+ So (err , ShouldBeNil )
11198+
11199+ client := resty .New ()
11200+
11201+ // The server picks canonical digests when tags are pushed
11202+ // See https://github.com/opencontainers/distribution-spec/issues/494
11203+ // It would be nice to be able to push tags with other digest algorithms and verify those are returned
11204+ // but there is no way to specify a client preference
11205+ // so all we can do is verify the correct algorithm is returned
11206+
11207+ expectedDigestStr := image .DigestForAlgorithm (godigest .Canonical ).String ()
11208+
11209+ verifyReturnedManifestDigest (t , client , baseURL , name , tag , expectedDigestStr )
11210+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11211+ })
11212+
11213+ Convey ("Test SHA512 single-arch image pushed by digest" , t , func () {
11214+ image := CreateImageWithDigestAlgorithm (godigest .SHA512 ).
11215+ RandomLayers (1 , 11 ).DefaultConfig ().Build ()
11216+
11217+ name := "algo-sha512-2"
11218+
11219+ err := UploadImage (image , baseURL , name , image .DigestStr ())
11220+ So (err , ShouldBeNil )
11221+
11222+ client := resty .New ()
11223+
11224+ expectedDigestStr := image .DigestForAlgorithm (godigest .SHA512 ).String ()
11225+
11226+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11227+ })
11228+
11229+ Convey ("Test SHA384 single-arch image" , t , func () {
11230+ image := CreateImageWithDigestAlgorithm (godigest .SHA384 ).
11231+ RandomLayers (1 , 10 ).DefaultConfig ().Build ()
11232+
11233+ name := "algo-sha384"
11234+ tag := "singlearch"
11235+
11236+ err := UploadImage (image , baseURL , name , tag )
11237+ So (err , ShouldBeNil )
11238+
11239+ client := resty .New ()
11240+
11241+ // The server picks canonical digests when tags are pushed
11242+ // See https://github.com/opencontainers/distribution-spec/issues/494
11243+ // It would be nice to be able to push tags with other digest algorithms and verify those are returned
11244+ // but there is no way to specify a client preference
11245+ // so all we can do is verify the correct algorithm is returned
11246+
11247+ expectedDigestStr := image .DigestForAlgorithm (godigest .Canonical ).String ()
11248+
11249+ verifyReturnedManifestDigest (t , client , baseURL , name , tag , expectedDigestStr )
11250+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11251+ })
11252+
11253+ Convey ("Test SHA512 multi-arch image" , t , func () {
11254+ subImage1 := CreateImageWithDigestAlgorithm (godigest .SHA512 ).RandomLayers (1 , 10 ).
11255+ DefaultConfig ().Build ()
11256+ subImage2 := CreateImageWithDigestAlgorithm (godigest .SHA512 ).RandomLayers (1 , 10 ).
11257+ DefaultConfig ().Build ()
11258+ multiarch := CreateMultiarchWithDigestAlgorithm (godigest .SHA512 ).
11259+ Images ([]Image {subImage1 , subImage2 }).Build ()
11260+
11261+ name := "algo-sha512"
11262+ tag := "multiarch"
11263+
11264+ err := UploadMultiarchImage (multiarch , baseURL , name , tag )
11265+ So (err , ShouldBeNil )
11266+
11267+ client := resty .New ()
11268+
11269+ // The server picks canonical digests when tags are pushed
11270+ // See https://github.com/opencontainers/distribution-spec/issues/494
11271+ // It would be nice to be able to push tags with other digest algorithms and verify those are returned
11272+ // but there is no way to specify a client preference
11273+ // so all we can do is verify the correct algorithm is returned
11274+ expectedDigestStr := multiarch .DigestForAlgorithm (godigest .Canonical ).String ()
11275+
11276+ verifyReturnedManifestDigest (t , client , baseURL , name , tag , expectedDigestStr )
11277+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11278+
11279+ // While the expected multiarch manifest digest is always using the canonical algorithm
11280+ // the sub-imgage manifest digest can use any algorith
11281+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11282+ subImage1 .ManifestDescriptor .Digest .String (), subImage1 .ManifestDescriptor .Digest .String ())
11283+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11284+ subImage2 .ManifestDescriptor .Digest .String (), subImage2 .ManifestDescriptor .Digest .String ())
11285+ })
11286+
11287+ Convey ("Test SHA512 multi-arch image pushed by digest" , t , func () {
11288+ subImage1 := CreateImageWithDigestAlgorithm (godigest .SHA512 ).RandomLayers (1 , 10 ).
11289+ DefaultConfig ().Build ()
11290+ subImage2 := CreateImageWithDigestAlgorithm (godigest .SHA512 ).RandomLayers (1 , 10 ).
11291+ DefaultConfig ().Build ()
11292+ multiarch := CreateMultiarchWithDigestAlgorithm (godigest .SHA512 ).
11293+ Images ([]Image {subImage1 , subImage2 }).Build ()
11294+
11295+ name := "algo-sha512-2"
11296+
11297+ t .Log (multiarch .DigestStr ())
11298+
11299+ err := UploadMultiarchImage (multiarch , baseURL , name , multiarch .DigestStr ())
11300+ So (err , ShouldBeNil )
11301+
11302+ client := resty .New ()
11303+
11304+ expectedDigestStr := multiarch .DigestForAlgorithm (godigest .SHA512 ).String ()
11305+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11306+
11307+ // While the expected multiarch manifest digest is always using the canonical algorithm
11308+ // the sub-imgage manifest digest can use any algorith
11309+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11310+ subImage1 .ManifestDescriptor .Digest .String (), subImage1 .ManifestDescriptor .Digest .String ())
11311+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11312+ subImage2 .ManifestDescriptor .Digest .String (), subImage2 .ManifestDescriptor .Digest .String ())
11313+ })
11314+
11315+ Convey ("Test SHA384 multi-arch image" , t , func () {
11316+ subImage1 := CreateImageWithDigestAlgorithm (godigest .SHA384 ).RandomLayers (1 , 10 ).
11317+ DefaultConfig ().Build ()
11318+ subImage2 := CreateImageWithDigestAlgorithm (godigest .SHA384 ).RandomLayers (1 , 10 ).
11319+ DefaultConfig ().Build ()
11320+ multiarch := CreateMultiarchWithDigestAlgorithm (godigest .SHA384 ).
11321+ Images ([]Image {subImage1 , subImage2 }).Build ()
11322+
11323+ name := "algo-sha384"
11324+ tag := "multiarch"
11325+
11326+ err := UploadMultiarchImage (multiarch , baseURL , name , tag )
11327+ So (err , ShouldBeNil )
11328+
11329+ client := resty .New ()
11330+
11331+ // The server picks canonical digests when tags are pushed
11332+ // See https://github.com/opencontainers/distribution-spec/issues/494
11333+ // It would be nice to be able to push tags with other digest algorithms and verify those are returned
11334+ // but there is no way to specify a client preference
11335+ // so all we can do is verify the correct algorithm is returned
11336+ expectedDigestStr := multiarch .DigestForAlgorithm (godigest .Canonical ).String ()
11337+
11338+ verifyReturnedManifestDigest (t , client , baseURL , name , tag , expectedDigestStr )
11339+ verifyReturnedManifestDigest (t , client , baseURL , name , expectedDigestStr , expectedDigestStr )
11340+
11341+ // While the expected multiarch manifest digest is always using the canonical algorithm
11342+ // the sub-imgage manifest digest can use any algorith
11343+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11344+ subImage1 .ManifestDescriptor .Digest .String (), subImage1 .ManifestDescriptor .Digest .String ())
11345+ verifyReturnedManifestDigest (t , client , baseURL , name ,
11346+ subImage2 .ManifestDescriptor .Digest .String (), subImage2 .ManifestDescriptor .Digest .String ())
11347+ })
11348+ }
11349+
11350+ func verifyReturnedManifestDigest (t * testing.T , client * resty.Client , baseURL , repoName ,
11351+ reference , expectedDigestStr string ,
11352+ ) {
11353+ t .Helper ()
11354+
11355+ t .Logf ("Verify Docker-Content-Digest returned for repo %s reference %s is %s" ,
11356+ repoName , reference , expectedDigestStr )
11357+
11358+ getResponse , err := client .R ().Get (fmt .Sprintf ("%s/v2/%s/manifests/%s" , baseURL , repoName , reference ))
11359+ So (err , ShouldBeNil )
11360+ So (getResponse , ShouldNotBeNil )
11361+ So (getResponse .StatusCode (), ShouldEqual , http .StatusOK )
11362+
11363+ contentDigestStr := getResponse .Header ().Get ("Docker-Content-Digest" )
11364+ So (contentDigestStr , ShouldEqual , expectedDigestStr )
11365+
11366+ getResponse , err = client .R ().Head (fmt .Sprintf ("%s/v2/%s/manifests/%s" , baseURL , repoName , reference ))
11367+ So (err , ShouldBeNil )
11368+ So (getResponse , ShouldNotBeNil )
11369+ So (getResponse .StatusCode (), ShouldEqual , http .StatusOK )
11370+
11371+ contentDigestStr = getResponse .Header ().Get ("Docker-Content-Digest" )
11372+ So (contentDigestStr , ShouldEqual , expectedDigestStr )
11373+ }
11374+
1117011375func getEmptyImageConfig () ([]byte , godigest.Digest ) {
1117111376 config := ispec.Image {}
1117211377
0 commit comments