0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

feat(pagination): make sure the URL to in the link header is inside angle brackets (#2116)

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron 2023-12-06 19:54:47 +02:00 committed by GitHub
parent e3bd9a8fa8
commit f321fa91fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -7303,7 +7303,7 @@ func TestListingTags(t *testing.T) {
} else if testCase.expectedTags[len(testCase.expectedTags)-1] == alltags[len(alltags)-1] {
So(actualLinkValue, ShouldEqual, "")
} else {
expectedLinkValue := fmt.Sprintf("/v2/%s/tags/list?n=%s&last=%s; rel=\"next\"",
expectedLinkValue := fmt.Sprintf("</v2/%s/tags/list?n=%s&last=%s>; rel=\"next\"",
repoName, testCase.pageSize, tags.Tags[len(tags.Tags)-1],
)
So(actualLinkValue, ShouldEqual, expectedLinkValue)

View file

@ -375,7 +375,7 @@ func (rh *RouteHandler) ListTags(response http.ResponseWriter, request *http.Req
stopIndex = startIndex + numTags - 1
response.Header().Set(
"Link",
fmt.Sprintf("/v2/%s/tags/list?n=%d&last=%s; rel=\"next\"",
fmt.Sprintf("</v2/%s/tags/list?n=%d&last=%s>; rel=\"next\"",
name,
numTags,
tags[stopIndex],

View file

@ -602,8 +602,16 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
next := resp.Header().Get("Link")
So(next, ShouldNotBeEmpty)
u := baseURL + strings.Split(next, ";")[0]
resp, err = resty.R().Get(u)
nextURL := strings.Split(next, ";")[0]
if strings.HasPrefix(nextURL, "<") || strings.HasPrefix(nextURL, "\"") {
nextURL = nextURL[1:]
}
if strings.HasSuffix(nextURL, ">") || strings.HasSuffix(nextURL, "\"") {
nextURL = nextURL[:len(nextURL)-1]
}
nextURL = baseURL + nextURL
resp, err = resty.R().Get(nextURL)
So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
next = resp.Header().Get("Link")