Backport #31293 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
bbe98a3254
commit
1dc8a66074
5 changed files with 23 additions and 14 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue