2014-12-30 22:22:31 +00:00
|
|
|
// +build !test_no_exec
|
|
|
|
|
2014-12-01 17:16:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2015-07-02 06:57:44 +00:00
|
|
|
"encoding/json"
|
2014-12-01 17:16:49 +00:00
|
|
|
"fmt"
|
2015-04-20 21:03:56 +00:00
|
|
|
"net/http"
|
2014-12-01 17:16:49 +00:00
|
|
|
"os/exec"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-12-01 17:16:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Regression test for #9414
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
2014-12-01 17:16:49 +00:00
|
|
|
name := "exec_test"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-12-01 17:16:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 21:03:56 +00:00
|
|
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
|
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
if !bytes.Contains(body, []byte("No exec command specified")) {
|
|
|
|
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
2014-12-01 17:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-02 06:57:44 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|