|
|
@ -84,7 +84,7 @@ func TestPackageContainer(t *testing.T) { |
|
|
|
Token string `json:"token"` |
|
|
|
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) { |
|
|
|
t.Run("Anonymous", func(t *testing.T) { |
|
|
|
defer tests.PrintCurrentTest(t)() |
|
|
|
defer tests.PrintCurrentTest(t)() |
|
|
@ -92,7 +92,7 @@ func TestPackageContainer(t *testing.T) { |
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL)) |
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL)) |
|
|
|
resp := MakeRequest(t, req, http.StatusUnauthorized) |
|
|
|
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)) |
|
|
|
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL)) |
|
|
|
resp = MakeRequest(t, req, http.StatusOK) |
|
|
|
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)) |
|
|
|
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL)) |
|
|
|
MakeRequest(t, req, http.StatusUnauthorized) |
|
|
|
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) { |
|
|
|
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)) |
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL)) |
|
|
|
resp := MakeRequest(t, req, http.StatusUnauthorized) |
|
|
|
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)). |
|
|
|
req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL)). |
|
|
|
AddBasicAuth(user.Name) |
|
|
|
AddBasicAuth(user.Name) |
|
|
|