diff options
author | Boaz Shuster <ripcurld.github@gmail.com> | 2017-02-05 13:39:37 +0200 |
---|---|---|
committer | Boaz Shuster <ripcurld.github@gmail.com> | 2017-03-26 15:21:13 +0300 |
commit | e050f1760dd8a3d48d95bb3d2de503fc4177ff5f (patch) | |
tree | 3ca593555002f798d19ce864cfc160232865f59b /integration-cli/docker_api_images_test.go | |
parent | 41650df87e55c0d018c66d0d221920f87c343391 (diff) | |
download | docker-e050f1760dd8a3d48d95bb3d2de503fc4177ff5f.tar.gz |
Fix the create API when fromSrc has a bad URL
When sending a bad URL in the fromSrc parameter using cURL
the response will have status code 200 while it should have 404
or 500 (depends on the error).
This commit addresses this problem in the following ways:
* Before, `src` was parsed using url.Parse and if the
returned `url.Scheme` was empty it was set to 'http'
and `url.Host` was set to `src`.
This is bad because if `src` was 'web.com/tars/image1.tar'
The `url.String()` returns 'web.com%2Ftars%2Fimage1.tar`
which will cause the daemon to fail downloading the file
* Before writing the "Downloading" message, the image
is attempted to be downloaded and if there is no error
the "Downloading" message is sent.
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
Diffstat (limited to 'integration-cli/docker_api_images_test.go')
-rw-r--r-- | integration-cli/docker_api_images_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index 6f911491bf..80a9ca3229 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -115,6 +115,29 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest") } +func (s *DockerSuite) TestAPIImagesImportBadSrc(c *check.C) { + testRequires(c, Network) + + tt := []struct { + statusExp int + fromSrc string + }{ + {http.StatusNotFound, "http://example.com/nofile.tar"}, + {http.StatusNotFound, "example.com/nofile.tar"}, + {http.StatusNotFound, "example.com%2Fdata%2Ffile.tar"}, + {http.StatusInternalServerError, "%2Fdata%2Ffile.tar"}, + } + + for _, te := range tt { + res, b, err := request.SockRequestRaw("POST", strings.Join([]string{"/images/create?fromSrc=", te.fromSrc}, ""), nil, "application/json", daemonHost()) + c.Assert(err, check.IsNil) + b.Close() + c.Assert(res.StatusCode, checker.Equals, te.statusExp) + c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json") + } + +} + // #14846 func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) { testRequires(c, Network) |