docker_api_test.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httputil"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "github.com/docker/docker/api"
  9. "github.com/go-check/check"
  10. )
  11. func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
  12. status, _, err := sockRequest("OPTIONS", "/", nil)
  13. c.Assert(err, check.IsNil)
  14. c.Assert(status, check.Equals, http.StatusOK)
  15. }
  16. func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
  17. res, body, err := sockRequestRaw("GET", "/version", nil, "")
  18. c.Assert(err, check.IsNil)
  19. c.Assert(res.StatusCode, check.Equals, http.StatusOK)
  20. body.Close()
  21. // TODO: @runcom incomplete tests, why old integration tests had this headers
  22. // and here none of the headers below are in the response?
  23. //c.Log(res.Header)
  24. //c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
  25. //c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
  26. }
  27. func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
  28. conn, err := sockConn(time.Duration(10 * time.Second))
  29. c.Assert(err, check.IsNil)
  30. client := httputil.NewClientConn(conn, nil)
  31. defer client.Close()
  32. req, err := http.NewRequest("GET", "/v999.0/version", nil)
  33. c.Assert(err, check.IsNil)
  34. req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
  35. res, err := client.Do(req)
  36. c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
  37. }
  38. func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
  39. v := strings.Split(string(api.Version), ".")
  40. vMinInt, err := strconv.Atoi(v[1])
  41. c.Assert(err, check.IsNil)
  42. vMinInt++
  43. v[1] = strconv.Itoa(vMinInt)
  44. version := strings.Join(v, ".")
  45. status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
  46. c.Assert(err, check.IsNil)
  47. c.Assert(status, check.Equals, http.StatusBadRequest)
  48. c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
  49. }
  50. func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
  51. v := strings.Split(string(api.MinVersion), ".")
  52. vMinInt, err := strconv.Atoi(v[1])
  53. c.Assert(err, check.IsNil)
  54. vMinInt--
  55. v[1] = strconv.Itoa(vMinInt)
  56. version := strings.Join(v, ".")
  57. status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
  58. c.Assert(err, check.IsNil)
  59. c.Assert(status, check.Equals, http.StatusBadRequest)
  60. c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
  61. }