Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package dockerfile |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "net/http" |
|
| 4 | 5 |
"testing" |
| 5 | 6 |
|
| 6 | 7 |
"github.com/gotestyourself/gotestyourself/fs" |
| ... | ... |
@@ -43,3 +44,103 @@ func TestIsExistingDirectory(t *testing.T) {
|
| 43 | 43 |
assert.Equal(t, testcase.expected, result, testcase.doc) |
| 44 | 44 |
} |
| 45 | 45 |
} |
| 46 |
+ |
|
| 47 |
+func TestGetFilenameForDownload(t *testing.T) {
|
|
| 48 |
+ var testcases = []struct {
|
|
| 49 |
+ path string |
|
| 50 |
+ disposition string |
|
| 51 |
+ expected string |
|
| 52 |
+ }{
|
|
| 53 |
+ {
|
|
| 54 |
+ path: "http://www.example.com/", |
|
| 55 |
+ expected: "", |
|
| 56 |
+ }, |
|
| 57 |
+ {
|
|
| 58 |
+ path: "http://www.example.com/xyz", |
|
| 59 |
+ expected: "xyz", |
|
| 60 |
+ }, |
|
| 61 |
+ {
|
|
| 62 |
+ path: "http://www.example.com/xyz.html", |
|
| 63 |
+ expected: "xyz.html", |
|
| 64 |
+ }, |
|
| 65 |
+ {
|
|
| 66 |
+ path: "http://www.example.com/xyz/", |
|
| 67 |
+ expected: "", |
|
| 68 |
+ }, |
|
| 69 |
+ {
|
|
| 70 |
+ path: "http://www.example.com/xyz/uvw", |
|
| 71 |
+ expected: "uvw", |
|
| 72 |
+ }, |
|
| 73 |
+ {
|
|
| 74 |
+ path: "http://www.example.com/xyz/uvw.html", |
|
| 75 |
+ expected: "uvw.html", |
|
| 76 |
+ }, |
|
| 77 |
+ {
|
|
| 78 |
+ path: "http://www.example.com/xyz/uvw/", |
|
| 79 |
+ expected: "", |
|
| 80 |
+ }, |
|
| 81 |
+ {
|
|
| 82 |
+ path: "/", |
|
| 83 |
+ expected: "", |
|
| 84 |
+ }, |
|
| 85 |
+ {
|
|
| 86 |
+ path: "/xyz", |
|
| 87 |
+ expected: "xyz", |
|
| 88 |
+ }, |
|
| 89 |
+ {
|
|
| 90 |
+ path: "/xyz.html", |
|
| 91 |
+ expected: "xyz.html", |
|
| 92 |
+ }, |
|
| 93 |
+ {
|
|
| 94 |
+ path: "/xyz/", |
|
| 95 |
+ expected: "", |
|
| 96 |
+ }, |
|
| 97 |
+ {
|
|
| 98 |
+ path: "/xyz/", |
|
| 99 |
+ disposition: "attachment; filename=xyz.html", |
|
| 100 |
+ expected: "xyz.html", |
|
| 101 |
+ }, |
|
| 102 |
+ {
|
|
| 103 |
+ disposition: "", |
|
| 104 |
+ expected: "", |
|
| 105 |
+ }, |
|
| 106 |
+ {
|
|
| 107 |
+ disposition: "attachment; filename=xyz", |
|
| 108 |
+ expected: "xyz", |
|
| 109 |
+ }, |
|
| 110 |
+ {
|
|
| 111 |
+ disposition: "attachment; filename=xyz.html", |
|
| 112 |
+ expected: "xyz.html", |
|
| 113 |
+ }, |
|
| 114 |
+ {
|
|
| 115 |
+ disposition: "attachment; filename=\"xyz\"", |
|
| 116 |
+ expected: "xyz", |
|
| 117 |
+ }, |
|
| 118 |
+ {
|
|
| 119 |
+ disposition: "attachment; filename=\"xyz.html\"", |
|
| 120 |
+ expected: "xyz.html", |
|
| 121 |
+ }, |
|
| 122 |
+ {
|
|
| 123 |
+ disposition: "attachment; filename=\"/xyz.html\"", |
|
| 124 |
+ expected: "xyz.html", |
|
| 125 |
+ }, |
|
| 126 |
+ {
|
|
| 127 |
+ disposition: "attachment; filename=\"/xyz/uvw\"", |
|
| 128 |
+ expected: "uvw", |
|
| 129 |
+ }, |
|
| 130 |
+ {
|
|
| 131 |
+ disposition: "attachment; filename=\"Naïve file.txt\"", |
|
| 132 |
+ expected: "Naïve file.txt", |
|
| 133 |
+ }, |
|
| 134 |
+ } |
|
| 135 |
+ for _, testcase := range testcases {
|
|
| 136 |
+ resp := http.Response{
|
|
| 137 |
+ Header: make(map[string][]string), |
|
| 138 |
+ } |
|
| 139 |
+ if testcase.disposition != "" {
|
|
| 140 |
+ resp.Header.Add("Content-Disposition", testcase.disposition)
|
|
| 141 |
+ } |
|
| 142 |
+ filename := getFilenameForDownload(testcase.path, &resp) |
|
| 143 |
+ assert.Equal(t, testcase.expected, filename) |
|
| 144 |
+ } |
|
| 145 |
+} |
| ... | ... |
@@ -6506,19 +6506,3 @@ RUN touch /foop |
| 6506 | 6506 |
c.Assert(err, check.IsNil) |
| 6507 | 6507 |
c.Assert(d.String(), checker.Equals, getIDByName(c, name)) |
| 6508 | 6508 |
} |
| 6509 |
- |
|
| 6510 |
-// Test case for #34208 |
|
| 6511 |
-func (s *DockerSuite) TestBuildAddHTTPRoot(c *check.C) {
|
|
| 6512 |
- testRequires(c, Network, DaemonIsLinux) |
|
| 6513 |
- buildImageSuccessfully(c, "buildaddhttproot", build.WithDockerfile(` |
|
| 6514 |
- FROM scratch |
|
| 6515 |
- ADD http://example.com/index.html /example1 |
|
| 6516 |
- ADD http://example.com /example2 |
|
| 6517 |
- ADD http://example.com /example3`)) |
|
| 6518 |
- buildImage("buildaddhttprootfailure", build.WithDockerfile(`
|
|
| 6519 |
- FROM scratch |
|
| 6520 |
- ADD http://example.com/ /`)).Assert(c, icmd.Expected{
|
|
| 6521 |
- ExitCode: 1, |
|
| 6522 |
- Err: "cannot determine filename for source http://example.com/", |
|
| 6523 |
- }) |
|
| 6524 |
-} |