2015-04-29 14:56:45 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2015-09-01 00:45:27 +03:00
|
|
|
"net/http/httptest"
|
2015-05-19 19:28:50 +03:00
|
|
|
"net/http/httputil"
|
2015-09-01 00:45:27 +03:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2015-06-18 00:57:32 +03:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2015-05-19 19:28:50 +03:00
|
|
|
"time"
|
2015-04-29 14:56:45 +03:00
|
|
|
|
2015-06-18 00:57:32 +03:00
|
|
|
"github.com/docker/docker/api"
|
2015-10-13 15:01:58 +03:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-29 14:56:45 +03:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
|
|
|
status, _, err := sockRequest("OPTIONS", "/", nil)
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-04-29 14:56:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
|
|
|
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-07-23 14:24:14 +03:00
|
|
|
body.Close()
|
2015-04-29 14:56:45 +03:00
|
|
|
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
|
|
|
// and here none of the headers below are in the response?
|
|
|
|
//c.Log(res.Header)
|
|
|
|
//c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
|
|
|
|
//c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
|
|
|
|
}
|
2015-05-19 19:28:50 +03:00
|
|
|
|
2015-06-18 00:57:32 +03:00
|
|
|
func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
|
2015-05-19 19:28:50 +03:00
|
|
|
conn, err := sockConn(time.Duration(10 * time.Second))
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-19 19:28:50 +03:00
|
|
|
|
|
|
|
client := httputil.NewClientConn(conn, nil)
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
req, err := http.NewRequest("GET", "/v999.0/version", nil)
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-04 20:29:57 +03:00
|
|
|
req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
|
2015-05-19 19:28:50 +03:00
|
|
|
|
|
|
|
res, err := client.Do(req)
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
|
2015-05-19 19:28:50 +03:00
|
|
|
}
|
2015-06-18 00:57:32 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
|
2015-12-18 23:28:17 +03:00
|
|
|
v := strings.Split(api.DefaultVersion.String(), ".")
|
2015-06-18 00:57:32 +03:00
|
|
|
vMinInt, err := strconv.Atoi(v[1])
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-18 00:57:32 +03:00
|
|
|
vMinInt++
|
|
|
|
v[1] = strconv.Itoa(vMinInt)
|
|
|
|
version := strings.Join(v, ".")
|
|
|
|
|
|
|
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
|
|
|
c.Assert(len(string(body)), check.Not(checker.Equals), 0) // Expected not empty body
|
2015-06-18 00:57:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
|
2015-12-18 23:28:17 +03:00
|
|
|
v := strings.Split(api.MinVersion.String(), ".")
|
2015-06-18 00:57:32 +03:00
|
|
|
vMinInt, err := strconv.Atoi(v[1])
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-18 00:57:32 +03:00
|
|
|
vMinInt--
|
|
|
|
v[1] = strconv.Itoa(vMinInt)
|
|
|
|
version := strings.Join(v, ".")
|
|
|
|
|
|
|
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
2015-10-13 15:01:58 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
|
|
|
c.Assert(len(string(body)), checker.Not(check.Equals), 0) // Expected not empty body
|
2015-06-18 00:57:32 +03:00
|
|
|
}
|
2015-09-01 00:45:27 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiDockerApiVersion(c *check.C) {
|
|
|
|
var svrVersion string
|
|
|
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
url := r.URL.Path
|
|
|
|
svrVersion = url
|
|
|
|
}))
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
// Test using the env var first
|
|
|
|
cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "version")
|
|
|
|
cmd.Env = append([]string{"DOCKER_API_VERSION=xxx"}, os.Environ()...)
|
|
|
|
out, _, _ := runCommandWithOutput(cmd)
|
|
|
|
|
|
|
|
c.Assert(svrVersion, check.Equals, "/vxxx/version")
|
|
|
|
|
|
|
|
if !strings.Contains(out, "API version: xxx") {
|
|
|
|
c.Fatalf("Out didn't have 'xxx' for the API version, had:\n%s", out)
|
|
|
|
}
|
|
|
|
}
|