mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Remove sub-path from container registry realm (#31293)
Container registry requires that the "/v2" must be in the root, so the sub-path in AppURL should be removed
This commit is contained in:
@ -84,7 +84,7 @@ func TestPackageContainer(t *testing.T) {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
authenticate := []string{`Bearer realm="` + setting.AppURL + `v2/token",service="container_registry",scope="*"`}
|
||||
defaultAuthenticateValues := []string{`Bearer realm="` + setting.AppURL + `v2/token",service="container_registry",scope="*"`}
|
||||
|
||||
t.Run("Anonymous", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
@ -92,7 +92,7 @@ func TestPackageContainer(t *testing.T) {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
|
||||
resp := MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
assert.ElementsMatch(t, authenticate, resp.Header().Values("WWW-Authenticate"))
|
||||
assert.ElementsMatch(t, defaultAuthenticateValues, resp.Header().Values("WWW-Authenticate"))
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL))
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
@ -115,6 +115,12 @@ func TestPackageContainer(t *testing.T) {
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL))
|
||||
MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
defer test.MockVariableValue(&setting.AppURL, "https://domain:8443/sub-path/")()
|
||||
defer test.MockVariableValue(&setting.AppSubURL, "/sub-path")()
|
||||
req = NewRequest(t, "GET", "/v2")
|
||||
resp = MakeRequest(t, req, http.StatusUnauthorized)
|
||||
assert.Equal(t, `Bearer realm="https://domain:8443/v2/token",service="container_registry",scope="*"`, resp.Header().Get("WWW-Authenticate"))
|
||||
})
|
||||
|
||||
t.Run("User", func(t *testing.T) {
|
||||
@ -123,7 +129,7 @@ func TestPackageContainer(t *testing.T) {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
|
||||
resp := MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
assert.ElementsMatch(t, authenticate, resp.Header().Values("WWW-Authenticate"))
|
||||
assert.ElementsMatch(t, defaultAuthenticateValues, resp.Header().Values("WWW-Authenticate"))
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL)).
|
||||
AddBasicAuth(user.Name)
|
||||
|
Reference in New Issue
Block a user