From f321fa91fe9ed9b6a4db190ade7395b1489b4fde Mon Sep 17 00:00:00 2001 From: Andrei Aaron Date: Wed, 6 Dec 2023 19:54:47 +0200 Subject: [PATCH] feat(pagination): make sure the URL to in the link header is inside angle brackets (#2116) Signed-off-by: Andrei Aaron --- pkg/api/controller_test.go | 2 +- pkg/api/routes.go | 2 +- pkg/compliance/v1_0_0/check.go | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index a5a849ae..f146c721 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -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("; rel=\"next\"", repoName, testCase.pageSize, tags.Tags[len(tags.Tags)-1], ) So(actualLinkValue, ShouldEqual, expectedLinkValue) diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 82160ef3..7c32bac2 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -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("; rel=\"next\"", name, numTags, tags[stopIndex], diff --git a/pkg/compliance/v1_0_0/check.go b/pkg/compliance/v1_0_0/check.go index 31d5eefc..5a559393 100644 --- a/pkg/compliance/v1_0_0/check.go +++ b/pkg/compliance/v1_0_0/check.go @@ -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")