1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-09 20:17:21 +00:00

Fix "oras" OCI client compatibility (#34666) (#34671)

Backport #34666 by wxiaoguang

Fix #25846

1. the ImageConfig can be empty, fall back to default
2. the blob size can be empty, it still needs "Content-Length" header

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2025-06-10 03:20:34 +08:00
committed by GitHub
parent bf5d00074d
commit 18dc41d6f8
4 changed files with 35 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"net/http"
"strconv"
@ -623,6 +624,22 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, blobContent, resp.Body.Bytes())
})
t.Run("GetBlob/Empty", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
emptyDigestBuf := sha256.Sum256(nil)
emptyDigest := "sha256:" + hex.EncodeToString(emptyDigestBuf[:])
req := NewRequestWithBody(t, "POST", fmt.Sprintf("%s/blobs/uploads?digest=%s", url, emptyDigest), strings.NewReader("")).AddTokenAuth(userToken)
MakeRequest(t, req, http.StatusCreated)
req = NewRequest(t, "HEAD", fmt.Sprintf("%s/blobs/%s", url, emptyDigest)).AddTokenAuth(userToken)
resp := MakeRequest(t, req, http.StatusOK)
assert.Equal(t, "0", resp.Header().Get("Content-Length"))
req = NewRequest(t, "GET", fmt.Sprintf("%s/blobs/%s", url, emptyDigest)).AddTokenAuth(userToken)
resp = MakeRequest(t, req, http.StatusOK)
assert.Equal(t, "0", resp.Header().Get("Content-Length"))
})
t.Run("GetTagList", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()