diff --git a/builder/dockerfile/copy_test.go b/builder/dockerfile/copy_test.go index ed384fd20b..86f4dcff30 100644 --- a/builder/dockerfile/copy_test.go +++ b/builder/dockerfile/copy_test.go @@ -1,6 +1,7 @@ package dockerfile import ( + "net/http" "testing" "github.com/gotestyourself/gotestyourself/fs" @@ -43,3 +44,103 @@ func TestIsExistingDirectory(t *testing.T) { assert.Equal(t, testcase.expected, result, testcase.doc) } } + +func TestGetFilenameForDownload(t *testing.T) { + var testcases = []struct { + path string + disposition string + expected string + }{ + { + path: "http://www.example.com/", + expected: "", + }, + { + path: "http://www.example.com/xyz", + expected: "xyz", + }, + { + path: "http://www.example.com/xyz.html", + expected: "xyz.html", + }, + { + path: "http://www.example.com/xyz/", + expected: "", + }, + { + path: "http://www.example.com/xyz/uvw", + expected: "uvw", + }, + { + path: "http://www.example.com/xyz/uvw.html", + expected: "uvw.html", + }, + { + path: "http://www.example.com/xyz/uvw/", + expected: "", + }, + { + path: "/", + expected: "", + }, + { + path: "/xyz", + expected: "xyz", + }, + { + path: "/xyz.html", + expected: "xyz.html", + }, + { + path: "/xyz/", + expected: "", + }, + { + path: "/xyz/", + disposition: "attachment; filename=xyz.html", + expected: "xyz.html", + }, + { + disposition: "", + expected: "", + }, + { + disposition: "attachment; filename=xyz", + expected: "xyz", + }, + { + disposition: "attachment; filename=xyz.html", + expected: "xyz.html", + }, + { + disposition: "attachment; filename=\"xyz\"", + expected: "xyz", + }, + { + disposition: "attachment; filename=\"xyz.html\"", + expected: "xyz.html", + }, + { + disposition: "attachment; filename=\"/xyz.html\"", + expected: "xyz.html", + }, + { + disposition: "attachment; filename=\"/xyz/uvw\"", + expected: "uvw", + }, + { + disposition: "attachment; filename=\"Naïve file.txt\"", + expected: "Naïve file.txt", + }, + } + for _, testcase := range testcases { + resp := http.Response{ + Header: make(map[string][]string), + } + if testcase.disposition != "" { + resp.Header.Add("Content-Disposition", testcase.disposition) + } + filename := getFilenameForDownload(testcase.path, &resp) + assert.Equal(t, testcase.expected, filename) + } +} diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 3dedf45f31..59213e5404 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -6506,19 +6506,3 @@ RUN touch /foop c.Assert(err, check.IsNil) c.Assert(d.String(), checker.Equals, getIDByName(c, name)) } - -// Test case for #34208 -func (s *DockerSuite) TestBuildAddHTTPRoot(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - buildImageSuccessfully(c, "buildaddhttproot", build.WithDockerfile(` - FROM scratch - ADD http://example.com/index.html /example1 - ADD http://example.com /example2 - ADD http://example.com /example3`)) - buildImage("buildaddhttprootfailure", build.WithDockerfile(` - FROM scratch - ADD http://example.com/ /`)).Assert(c, icmd.Expected{ - ExitCode: 1, - Err: "cannot determine filename for source http://example.com/", - }) -}