2015-04-29 07:56:45 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2015-05-19 12:28:50 -04:00
|
|
|
"net/http/httputil"
|
2015-06-17 17:57:32 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2015-05-19 12:28:50 -04:00
|
|
|
"time"
|
2015-04-29 07:56:45 -04:00
|
|
|
|
2015-06-17 17:57:32 -04:00
|
|
|
"github.com/docker/docker/api"
|
2015-04-29 07:56:45 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
|
|
|
status, _, err := sockRequest("OPTIONS", "/", nil)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-06-17 17:57:32 -04:00
|
|
|
c.Assert(status, check.Equals, http.StatusOK)
|
2015-04-29 07:56:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
|
|
|
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
2015-07-23 07:24:14 -04:00
|
|
|
body.Close()
|
2015-04-29 07:56:45 -04: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 12:28:50 -04:00
|
|
|
|
2015-06-17 17:57:32 -04:00
|
|
|
func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
|
2015-05-19 12:28:50 -04:00
|
|
|
conn, err := sockConn(time.Duration(10 * time.Second))
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
client := httputil.NewClientConn(conn, nil)
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
req, err := http.NewRequest("GET", "/v999.0/version", nil)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-06-04 13:29:57 -04:00
|
|
|
req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
|
2015-05-19 12:28:50 -04:00
|
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
|
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
|
|
|
|
}
|
2015-06-17 17:57:32 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
|
|
|
|
v := strings.Split(string(api.Version), ".")
|
|
|
|
vMinInt, err := strconv.Atoi(v[1])
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
vMinInt++
|
|
|
|
v[1] = strconv.Itoa(vMinInt)
|
|
|
|
version := strings.Join(v, ".")
|
|
|
|
|
|
|
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(status, check.Equals, http.StatusBadRequest)
|
|
|
|
c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
|
|
|
|
v := strings.Split(string(api.MinVersion), ".")
|
|
|
|
vMinInt, err := strconv.Atoi(v[1])
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
vMinInt--
|
|
|
|
v[1] = strconv.Itoa(vMinInt)
|
|
|
|
version := strings.Join(v, ".")
|
|
|
|
|
|
|
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(status, check.Equals, http.StatusBadRequest)
|
|
|
|
c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
|
|
|
|
}
|