|
@@ -549,32 +549,61 @@ func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *check.C) {
|
|
c.Assert(out, checker.Contains, "unauthorized: access to the requested resource is not authorized")
|
|
c.Assert(out, checker.Contains, "unauthorized: access to the requested resource is not authorized")
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *check.C) {
|
|
|
|
- ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
- w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
|
|
+func getTestTokenService(status int, body string) *httptest.Server {
|
|
|
|
+ return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ w.WriteHeader(status)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
- w.Write([]byte(`{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`))
|
|
|
|
|
|
+ w.Write([]byte(body))
|
|
}))
|
|
}))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *check.C) {
|
|
|
|
+ ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`)
|
|
defer ts.Close()
|
|
defer ts.Close()
|
|
s.setupRegistryWithTokenService(c, ts.URL)
|
|
s.setupRegistryWithTokenService(c, ts.URL)
|
|
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
|
out, _, err := dockerCmdWithError("push", repoName)
|
|
out, _, err := dockerCmdWithError("push", repoName)
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
+ c.Assert(out, checker.Not(checker.Contains), "Retrying")
|
|
c.Assert(out, checker.Contains, "unauthorized: a message")
|
|
c.Assert(out, checker.Contains, "unauthorized: a message")
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse(c *check.C) {
|
|
|
|
- ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
- w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
- w.Header().Set("Content-Type", "application/json")
|
|
|
|
- // this will make the daemon panics if no check is performed in retryOnError
|
|
|
|
- w.Write([]byte(`{"error": "unauthorized"}`))
|
|
|
|
- }))
|
|
|
|
|
|
+func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnauthorized(c *check.C) {
|
|
|
|
+ ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`)
|
|
|
|
+ defer ts.Close()
|
|
|
|
+ s.setupRegistryWithTokenService(c, ts.URL)
|
|
|
|
+ repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
|
|
+ dockerCmd(c, "tag", "busybox", repoName)
|
|
|
|
+ out, _, err := dockerCmdWithError("push", repoName)
|
|
|
|
+ c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
+ c.Assert(out, checker.Not(checker.Contains), "Retrying")
|
|
|
|
+ split := strings.Split(out, "\n")
|
|
|
|
+ c.Assert(split[len(split)-2], check.Equals, "unauthorized: authentication required")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseError(c *check.C) {
|
|
|
|
+ ts := getTestTokenService(http.StatusInternalServerError, `{"error": "unexpected"}`)
|
|
|
|
+ defer ts.Close()
|
|
|
|
+ s.setupRegistryWithTokenService(c, ts.URL)
|
|
|
|
+ repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
|
|
+ dockerCmd(c, "tag", "busybox", repoName)
|
|
|
|
+ out, _, err := dockerCmdWithError("push", repoName)
|
|
|
|
+ c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
+ c.Assert(out, checker.Contains, "Retrying")
|
|
|
|
+ split := strings.Split(out, "\n")
|
|
|
|
+ c.Assert(split[len(split)-2], check.Equals, "received unexpected HTTP status: 500 Internal Server Error")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnparsable(c *check.C) {
|
|
|
|
+ ts := getTestTokenService(http.StatusForbidden, `no way`)
|
|
defer ts.Close()
|
|
defer ts.Close()
|
|
s.setupRegistryWithTokenService(c, ts.URL)
|
|
s.setupRegistryWithTokenService(c, ts.URL)
|
|
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
|
out, _, err := dockerCmdWithError("push", repoName)
|
|
out, _, err := dockerCmdWithError("push", repoName)
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
+ c.Assert(out, checker.Not(checker.Contains), "Retrying")
|
|
|
|
+ split := strings.Split(out, "\n")
|
|
|
|
+ c.Assert(split[len(split)-2], checker.Contains, "error parsing HTTP 403 response body: ")
|
|
}
|
|
}
|