mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-24 07:41:40 +01:00
Merge pull request #13675 from reasonerjt/fix-v2catalog-uri
Fix the pattern to match v2 catalog URI
This commit is contained in:
commit
878ef7c205
@ -27,7 +27,7 @@ var (
|
|||||||
// V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group
|
// V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group
|
||||||
V2BlobUploadURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$`, RepositorySubexp, reference.NameRegexp.String()))
|
V2BlobUploadURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$`, RepositorySubexp, reference.NameRegexp.String()))
|
||||||
// V2CatalogURLRe is the regular expression for mathing the request to v2 handler to list catalog
|
// V2CatalogURLRe is the regular expression for mathing the request to v2 handler to list catalog
|
||||||
V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog$`)
|
V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog/?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// MatchManifestURLPattern checks whether the provided path matches the manifest URL pattern,
|
// MatchManifestURLPattern checks whether the provided path matches the manifest URL pattern,
|
||||||
|
@ -66,3 +66,26 @@ func TestMatchBlobUploadURLPattern(t *testing.T) {
|
|||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, "library/hello-world", repository)
|
assert.Equal(t, "library/hello-world", repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatchCatalogURLPattern(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
url string
|
||||||
|
match bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
url: "/v2/_catalog",
|
||||||
|
match: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "/v2/_catalog/",
|
||||||
|
match: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "/v2/_catalog/xxx",
|
||||||
|
match: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
assert.Equal(t, c.match, len(V2CatalogURLRe.FindStringSubmatch(c.url)) == 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user