aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-07 17:30:59 +0200
committerGitHub <noreply@github.com>2022-10-07 23:30:59 +0800
commit69fc510d6dcf9cda7993eae8cd5c7725b345a9a1 (patch)
tree3ad6e0f5a1d86cc57b6a7e9fb97fd46c97b095e4 /tests
parentd94f15c2fd921722796a4cfdbbf266dd3017525c (diff)
downloadgitea-69fc510d6dcf9cda7993eae8cd5c7725b345a9a1.tar.gz
gitea-69fc510d6dcf9cda7993eae8cd5c7725b345a9a1.zip
Add GET and DELETE endpoints for Docker blob uploads (#21367)
This PR adds support for https://docs.docker.com/registry/spec/api/#get-blob-upload https://docs.docker.com/registry/spec/api/#delete-blob-upload Both are not required by the OCI spec but some clients call these endpoints. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_packages_container_test.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index adced5d661..b8a3884371 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -205,18 +205,54 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
assert.Equal(t, contentRange, resp.Header().Get("Range"))
+ uploadURL = resp.Header().Get("Location")
+
+ req = NewRequest(t, "GET", setting.AppURL+uploadURL[1:])
+ addTokenAuthHeader(req, userToken)
+ resp = MakeRequest(t, req, http.StatusNoContent)
+
+ assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
+ assert.Equal(t, fmt.Sprintf("0-%d", len(blobContent)), resp.Header().Get("Range"))
+
pbu, err = packages_model.GetBlobUploadByID(db.DefaultContext, uuid)
assert.NoError(t, err)
assert.EqualValues(t, len(blobContent), pbu.BytesReceived)
- uploadURL = resp.Header().Get("Location")
-
req = NewRequest(t, "PUT", fmt.Sprintf("%s?digest=%s", setting.AppURL+uploadURL[1:], blobDigest))
addTokenAuthHeader(req, userToken)
resp = MakeRequest(t, req, http.StatusCreated)
assert.Equal(t, fmt.Sprintf("/v2/%s/%s/blobs/%s", user.Name, image, blobDigest), resp.Header().Get("Location"))
assert.Equal(t, blobDigest, resp.Header().Get("Docker-Content-Digest"))
+
+ t.Run("Cancel", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ req := NewRequest(t, "POST", fmt.Sprintf("%s/blobs/uploads", url))
+ addTokenAuthHeader(req, userToken)
+ resp := MakeRequest(t, req, http.StatusAccepted)
+
+ uuid := resp.Header().Get("Docker-Upload-Uuid")
+ assert.NotEmpty(t, uuid)
+
+ uploadURL := resp.Header().Get("Location")
+ assert.NotEmpty(t, uploadURL)
+
+ req = NewRequest(t, "GET", setting.AppURL+uploadURL[1:])
+ addTokenAuthHeader(req, userToken)
+ resp = MakeRequest(t, req, http.StatusNoContent)
+
+ assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
+ assert.Equal(t, "0-0", resp.Header().Get("Range"))
+
+ req = NewRequest(t, "DELETE", setting.AppURL+uploadURL[1:])
+ addTokenAuthHeader(req, userToken)
+ MakeRequest(t, req, http.StatusNoContent)
+
+ req = NewRequest(t, "GET", setting.AppURL+uploadURL[1:])
+ addTokenAuthHeader(req, userToken)
+ MakeRequest(t, req, http.StatusNotFound)
+ })
})
for _, tag := range tags {