summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-06-10 12:04:49 +0800
committerGitHub <noreply@github.com>2024-06-10 12:04:49 +0800
commit1dc8a660741ad162f8b59a74f07b5517467c5262 (patch)
tree54d8b291e6a9dc0a6227b32372ff63f53f916862 /tests
parentbbe98a3254e65eb8b9ec8fddf5e0ffe416a96614 (diff)
downloadgitea-1dc8a660741ad162f8b59a74f07b5517467c5262.tar.gz
gitea-1dc8a660741ad162f8b59a74f07b5517467c5262.zip
Remove sub-path from container registry realm (#31293) (#31300)
Backport #31293 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_packages_container_test.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index 9ac6e5256b..fcd1cc529f 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -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)