Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
| ... | ... |
@@ -1349,6 +1349,9 @@ func (s *Server) postContainerExecCreate(version version.Version, w http.Respons |
| 1349 | 1349 |
if err := parseForm(r); err != nil {
|
| 1350 | 1350 |
return err |
| 1351 | 1351 |
} |
| 1352 |
+ if err := checkForJson(r); err != nil {
|
|
| 1353 |
+ return err |
|
| 1354 |
+ } |
|
| 1352 | 1355 |
name := vars["name"] |
| 1353 | 1356 |
|
| 1354 | 1357 |
execConfig := &runconfig.ExecConfig{}
|
| ... | ... |
@@ -4,6 +4,7 @@ package main |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"bytes" |
| 7 |
+ "encoding/json" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"net/http" |
| 9 | 10 |
"os/exec" |
| ... | ... |
@@ -27,3 +28,24 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
| 27 | 27 |
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
| 28 | 28 |
} |
| 29 | 29 |
} |
| 30 |
+ |
|
| 31 |
+func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|
| 32 |
+ name := "exec_test" |
|
| 33 |
+ dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") |
|
| 34 |
+ |
|
| 35 |
+ jsonData := bytes.NewBuffer(nil) |
|
| 36 |
+ if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil {
|
|
| 37 |
+ c.Fatalf("Can not encode data to json %s", err)
|
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain")
|
|
| 41 |
+ c.Assert(err, check.IsNil) |
|
| 42 |
+ c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError) |
|
| 43 |
+ |
|
| 44 |
+ b, err := readBody(body) |
|
| 45 |
+ c.Assert(err, check.IsNil) |
|
| 46 |
+ |
|
| 47 |
+ if !bytes.Contains(b, []byte("Content-Type specified")) {
|
|
| 48 |
+ c.Fatalf("Expected message when creating exec command with invalid Content-Type specified")
|
|
| 49 |
+ } |
|
| 50 |
+} |