mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14344 from Mashimiao/add-json-check-for-execcreate
api/server: Add missing json check
This commit is contained in:
commit
26a35dd09b
2 changed files with 25 additions and 0 deletions
|
@ -1349,6 +1349,9 @@ func (s *Server) postContainerExecCreate(version version.Version, w http.Respons
|
|||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkForJson(r); err != nil {
|
||||
return err
|
||||
}
|
||||
name := vars["name"]
|
||||
|
||||
execConfig := &runconfig.ExecConfig{}
|
||||
|
|
|
@ -4,6 +4,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
|
@ -27,3 +28,24 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
|||
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
||||
name := "exec_test"
|
||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil {
|
||||
c.Fatalf("Can not encode data to json %s", err)
|
||||
}
|
||||
|
||||
res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain")
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
|
||||
|
||||
b, err := readBody(body)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if !bytes.Contains(b, []byte("Content-Type specified")) {
|
||||
c.Fatalf("Expected message when creating exec command with invalid Content-Type specified")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue