0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00

refactor(tests): remove hardcoded digests (#871)

Signed-off-by: Catalin Hofnar <catalin.hofnar@gmail.com>
This commit is contained in:
Catalin Hofnar 2022-10-19 06:43:56 +03:00 committed by GitHub
parent 7d08985f75
commit caf88ddb1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 32 deletions

View file

@ -3077,7 +3077,7 @@ func TestInvalidCases(t *testing.T) {
}(ctlr)
test.WaitTillServerReady(baseURL)
digest := "sha256:8dd57e171a61368ffcfde38045ddb6ed74a32950c271c1da93eaddfb66a77e78"
digest := test.GetTestBlobDigest("zot-cve-test", "config").String()
name := "zot-c-test"
client := resty.New()
@ -3380,7 +3380,7 @@ func TestCrossRepoMount(t *testing.T) {
defer stopServer(ctlr)
test.WaitTillServerReady(baseURL)
digest := "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"
digest := test.GetTestBlobDigest("zot-cve-test", "layer").String()
name := "zot-c-test"
client := resty.New()
headResponse, err := client.R().SetBasicAuth(username, passphrase).

View file

@ -254,7 +254,7 @@ func TestRoutes(t *testing.T) {
statusCode := testDeleteBlob(
map[string]string{
"name": "ErrUnexpectedError",
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
},
&mocks.MockedImageStore{
DeleteBlobFn: func(repo, digest string) error {
@ -279,7 +279,7 @@ func TestRoutes(t *testing.T) {
statusCode = testDeleteBlob(
map[string]string{
"name": "ErrBlobNotFound",
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
},
&mocks.MockedImageStore{
DeleteBlobFn: func(repo, digest string) error {
@ -292,7 +292,7 @@ func TestRoutes(t *testing.T) {
statusCode = testDeleteBlob(
map[string]string{
"name": "ErrRepoNotFound",
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
},
&mocks.MockedImageStore{
DeleteBlobFn: func(repo, digest string) error {
@ -402,7 +402,7 @@ func TestRoutes(t *testing.T) {
statusCode := testGetBlob(
map[string]string{
"name": "ErrRepoNotFound",
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
},
&mocks.MockedImageStore{
GetBlobFn: func(repo, digest, mediaType string) (io.ReadCloser, int64, error) {
@ -415,7 +415,7 @@ func TestRoutes(t *testing.T) {
statusCode = testGetBlob(
map[string]string{
"name": "ErrRepoNotFound",
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
},
&mocks.MockedImageStore{
GetBlobFn: func(repo, digest, mediaType string) (io.ReadCloser, int64, error) {
@ -835,7 +835,7 @@ func TestRoutes(t *testing.T) {
status := testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "",
@ -851,7 +851,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "100",
@ -867,7 +867,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "100",
@ -887,7 +887,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "100",
@ -907,7 +907,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "100",
@ -927,7 +927,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "100",
@ -947,7 +947,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -967,7 +967,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -987,7 +987,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -1007,7 +1007,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -1027,7 +1027,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -1298,7 +1298,7 @@ func TestRoutes(t *testing.T) {
status := testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -1318,7 +1318,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",
@ -1338,7 +1338,7 @@ func TestRoutes(t *testing.T) {
status = testUpdateBlobUpload(
[]struct{ k, v string }{
{"digest", "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"},
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
},
map[string]string{
"Content-Length": "0",

View file

@ -142,6 +142,8 @@ func signUsingCosign(port string) error {
defer os.RemoveAll(tdir)
digest := GetTestBlobDigest("zot-cve-test", "manifest").String()
_ = os.Chdir(tdir)
// generate a keypair
@ -152,8 +154,7 @@ func signUsingCosign(port string) error {
return err
}
imageURL := fmt.Sprintf("localhost:%s/%s@%s", port, "zot-cve-test",
"sha256:63a795ca90aa6e7cca60941e826810a4cd0a2e73ea02bf458241df2a5c973e29")
imageURL := fmt.Sprintf("localhost:%s/%s@%s", port, "zot-cve-test", digest)
// sign the image
return sign.SignCmd(&options.RootOptions{Verbose: true, Timeout: 1 * time.Minute},
@ -318,7 +319,7 @@ func TestRepoListWithNewestImage(t *testing.T) {
So(resp.StatusCode(), ShouldEqual, 200)
err = os.Remove(path.Join(rootDir,
"zot-test/blobs/sha256/2bacca16b9df395fc855c14ccf50b12b58d35d468b8e7f25758aff90f89bf396"))
"zot-test/blobs/sha256", GetTestBlobDigest("zot-test", "manifest").Encoded()))
if err != nil {
panic(err)
}
@ -337,13 +338,13 @@ func TestRepoListWithNewestImage(t *testing.T) {
}
err = os.Remove(path.Join(rootDir,
"zot-test/blobs/sha256/adf3bb6cc81f8bd6a9d5233be5f0c1a4f1e3ed1cf5bbdfad7708cc8d4099b741"))
"zot-test/blobs/sha256/", GetTestBlobDigest("zot-test", "config").Encoded()))
if err != nil {
panic(err)
}
err = os.Remove(path.Join(rootDir,
"zot-test/blobs/sha256/2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc"))
"zot-test/blobs/sha256", GetTestBlobDigest("zot-test", "layer").Encoded()))
if err != nil {
panic(err)
}
@ -366,7 +367,7 @@ func TestRepoListWithNewestImage(t *testing.T) {
panic(err)
}
//nolint: lll
manifestNoAnnotations := "{\"schemaVersion\":2,\"manifests\":[{\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"digest\":\"sha256:2bacca16b9df395fc855c14ccf50b12b58d35d468b8e7f25758aff90f89bf396\",\"size\":350}]}"
manifestNoAnnotations := "{\"schemaVersion\":2,\"manifests\":[{\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"digest\":\"" + GetTestBlobDigest("zot-test", "manifest").String() + "\",\"size\":350}]}"
err = os.WriteFile(path.Join(rootDir, "zot-test/index.json"), []byte(manifestNoAnnotations), 0o600)
if err != nil {
panic(err)
@ -838,7 +839,7 @@ func TestExpandedRepoInfo(t *testing.T) {
So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Layers), ShouldNotEqual, 0)
found := false
for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries {
if m.Digest == "63a795ca90aa6e7cca60941e826810a4cd0a2e73ea02bf458241df2a5c973e29" {
if m.Digest == GetTestBlobDigest("zot-cve-test", "manifest").Encoded() {
found = true
So(m.IsSigned, ShouldEqual, false)
}
@ -859,7 +860,7 @@ func TestExpandedRepoInfo(t *testing.T) {
So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Layers), ShouldNotEqual, 0)
found = false
for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries {
if m.Digest == "63a795ca90aa6e7cca60941e826810a4cd0a2e73ea02bf458241df2a5c973e29" {
if m.Digest == GetTestBlobDigest("zot-cve-test", "manifest").Encoded() {
found = true
So(m.IsSigned, ShouldEqual, true)
}
@ -885,7 +886,7 @@ func TestExpandedRepoInfo(t *testing.T) {
So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Layers), ShouldNotEqual, 0)
found = false
for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries {
if m.Digest == "2bacca16b9df395fc855c14ccf50b12b58d35d468b8e7f25758aff90f89bf396" {
if m.Digest == GetTestBlobDigest("zot-test", "manifest").Encoded() {
found = true
So(m.IsSigned, ShouldEqual, false)
}
@ -906,7 +907,7 @@ func TestExpandedRepoInfo(t *testing.T) {
So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Layers), ShouldNotEqual, 0)
found = false
for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries {
if m.Digest == "2bacca16b9df395fc855c14ccf50b12b58d35d468b8e7f25758aff90f89bf396" {
if m.Digest == GetTestBlobDigest("zot-test", "manifest").Encoded() {
found = true
So(m.IsSigned, ShouldEqual, true)
}
@ -2698,7 +2699,7 @@ func TestBuildImageInfo(t *testing.T) {
}
func TestBaseOciLayoutUtils(t *testing.T) {
manifestDigest := "sha256:adf3bb6cc81f8bd6a9d5233be5f0c1a4f1e3ed1cf5bbdfad7708cc8d4099b741"
manifestDigest := GetTestBlobDigest("zot-test", "config").String()
Convey("GetImageManifestSize fail", t, func() {
mockStoreController := mocks.MockedImageStore{

View file

@ -29,6 +29,29 @@ const (
SleepTime = 100 * time.Millisecond
)
// which: manifest, config, layer
func GetTestBlobDigest(image, which string) godigest.Digest {
prePath := "../test/data"
for _, err := os.Stat(prePath); err != nil; _, err = os.Stat(prePath) {
prePath = "../" + prePath
}
imgPath := path.Join(prePath, image)
manifest, config, layer := GetOciLayoutDigests(imgPath)
switch which {
case "manifest":
return manifest
case "config":
return config
case "layer":
return layer
}
return ""
}
var (
ErrPostBlob = errors.New("can't post blob")
ErrPutBlob = errors.New("can't put blob")