Skip to content

Commit

Permalink
refactor(pkg/test): split logic in pkg/test/common.go into multiple p…
Browse files Browse the repository at this point in the history
…ackages

Which could be imported independently. See more details:
1. "zotregistry.io/zot/pkg/test/common" - currently used as
   tcommon "zotregistry.io/zot/pkg/test/common" - inside pkg/test
   test "zotregistry.io/zot/pkg/test/common" - in tests
   . "zotregistry.io/zot/pkg/test/common" - in tests
Move function getLocation to zb in order not to impot pkg/test in zb.

2. "zotregistry.io/zot/pkg/test/image-utils" - curently used as
   . "zotregistry.io/zot/pkg/test/image-utils"

3. "zotregistry.io/zot/pkg/test/deprecated" -  curently used as
   "zotregistry.io/zot/pkg/test/deprecated"
This one will bre replaced gradually by image-utils in the future.

4. "zotregistry.io/zot/pkg/test/signature" - (cosign + notation) use as
   "zotregistry.io/zot/pkg/test/signature"

5. "zotregistry.io/zot/pkg/test/auth" - (bearer + oidc)  curently used as
   authutils "zotregistry.io/zot/pkg/test/auth"

 6. "zotregistry.io/zot/pkg/test/oci-utils" -  curently used as
   ociutils "zotregistry.io/zot/pkg/test/oci-utils"

Some unused functions were removed, some were replaced, and in
a few cases specific funtions were moved to the files they were used in.

Signed-off-by: Andrei Aaron <[email protected]>
  • Loading branch information
andaaron committed Sep 26, 2023
1 parent dee67d1 commit a1ed1a0
Show file tree
Hide file tree
Showing 80 changed files with 3,324 additions and 3,182 deletions.
36 changes: 27 additions & 9 deletions cmd/zb/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"math/rand"
"net/http"
"net/url"
"os"
"path"
"sync"
Expand All @@ -21,7 +22,6 @@ import (

zerr "zotregistry.io/zot/errors"
"zotregistry.io/zot/pkg/common"
testc "zotregistry.io/zot/pkg/test/common"
"zotregistry.io/zot/pkg/test/image-utils"
)

Expand Down Expand Up @@ -344,7 +344,7 @@ func pushMonolithImage(workdir, url, trepo string, repos []string, config testCo
resp.StatusCode(), string(resp.Body())) //nolint: goerr113
}

loc := testc.Location(url, resp)
loc := getLocation(url, resp)

var size int

Expand Down Expand Up @@ -398,7 +398,7 @@ func pushMonolithImage(workdir, url, trepo string, repos []string, config testCo
resp.StatusCode(), string(resp.Body()))
}

loc = testc.Location(url, resp)
loc = getLocation(url, resp)
cblob, cdigest := getRandomImageConfig()
resp, err = client.R().
SetContentLength(true).
Expand Down Expand Up @@ -526,7 +526,7 @@ func pushMonolithAndCollect(workdir, url, trepo string, count int,
return
}

loc := testc.Location(url, resp)
loc := getLocation(url, resp)

var size int

Expand Down Expand Up @@ -594,7 +594,7 @@ func pushMonolithAndCollect(workdir, url, trepo string, count int,
return
}

loc = testc.Location(url, resp)
loc = getLocation(url, resp)
cblob, cdigest := getRandomImageConfig()
resp, err = client.R().
SetContentLength(true).
Expand Down Expand Up @@ -730,7 +730,7 @@ func pushChunkAndCollect(workdir, url, trepo string, count int,
return
}

loc := testc.Location(url, resp)
loc := getLocation(url, resp)

var size int

Expand Down Expand Up @@ -768,7 +768,7 @@ func pushChunkAndCollect(workdir, url, trepo string, count int,
return
}

loc = testc.Location(url, resp)
loc = getLocation(url, resp)

// request specific check
statusCode = resp.StatusCode()
Expand Down Expand Up @@ -822,7 +822,7 @@ func pushChunkAndCollect(workdir, url, trepo string, count int,
return
}

loc = testc.Location(url, resp)
loc = getLocation(url, resp)
cblob, cdigest := getRandomImageConfig()
resp, err = client.R().
SetContentLength(true).
Expand Down Expand Up @@ -859,7 +859,7 @@ func pushChunkAndCollect(workdir, url, trepo string, count int,
return
}

loc = testc.Location(url, resp)
loc = getLocation(url, resp)

// request specific check
statusCode = resp.StatusCode()
Expand Down Expand Up @@ -1033,3 +1033,21 @@ func getRandomImageConfig() ([]byte, godigest.Digest) {

return configBlobContent, configBlobDigestRaw
}

func getLocation(baseURL string, resp *resty.Response) string {
// For some API responses, the Location header is set and is supposed to
// indicate an opaque value. However, it is not clear if this value is an
// absolute URL (https://server:port/v2/...) or just a path (/v2/...)
// zot implements the latter as per the spec, but some registries appear to
// return the former - this needs to be clarified
loc := resp.Header().Get("Location")

uloc, err := url.Parse(loc)
if err != nil {
return ""
}

path := uloc.Path

return baseURL + path
}
7 changes: 4 additions & 3 deletions pkg/api/authn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
"zotregistry.io/zot/pkg/log"
mTypes "zotregistry.io/zot/pkg/meta/types"
reqCtx "zotregistry.io/zot/pkg/requestcontext"
"zotregistry.io/zot/pkg/test"
authutils "zotregistry.io/zot/pkg/test/auth"
test "zotregistry.io/zot/pkg/test/common"
"zotregistry.io/zot/pkg/test/mocks"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ func TestAPIKeys(t *testing.T) {
htpasswdPath := test.MakeHtpasswdFile()
defer os.Remove(htpasswdPath)

mockOIDCServer, err := test.MockOIDCRun()
mockOIDCServer, err := authutils.MockOIDCRun()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -834,7 +835,7 @@ func TestAPIKeysOpenDBError(t *testing.T) {
htpasswdPath := test.MakeHtpasswdFile()
defer os.Remove(htpasswdPath)

mockOIDCServer, err := test.MockOIDCRun()
mockOIDCServer, err := authutils.MockOIDCRun()
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit a1ed1a0

Please sign in to comment.