2018-02-11 18:14:39 -05:00
|
|
|
package session // import "github.com/docker/docker/integration/session"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2018-04-17 04:22:04 -04:00
|
|
|
req "github.com/docker/docker/internal/test/request"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/skip"
|
2018-02-11 18:14:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionCreate(t *testing.T) {
|
|
|
|
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
2018-02-11 18:14:39 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
|
2018-04-17 04:22:04 -04:00
|
|
|
res, body, err := req.Post("/session", req.With(func(r *http.Request) error {
|
2018-02-11 18:14:39 -05:00
|
|
|
r.Header.Set("X-Docker-Expose-Session-Uuid", "testsessioncreate") // so we don't block default name if something else is using it
|
|
|
|
r.Header.Set("Upgrade", "h2c")
|
|
|
|
return nil
|
2018-04-17 04:22:04 -04:00
|
|
|
}))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NilError(t, body.Close())
|
|
|
|
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusSwitchingProtocols))
|
|
|
|
assert.Check(t, is.Equal(res.Header.Get("Upgrade"), "h2c"))
|
2018-02-11 18:14:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSessionCreateWithBadUpgrade(t *testing.T) {
|
|
|
|
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
2018-02-11 18:14:39 -05:00
|
|
|
|
|
|
|
res, body, err := req.Post("/session")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
|
2018-02-11 18:14:39 -05:00
|
|
|
buf, err := req.ReadBody(body)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(buf), "no upgrade"))
|
2018-02-11 18:14:39 -05:00
|
|
|
|
2018-04-17 04:22:04 -04:00
|
|
|
res, body, err = req.Post("/session", req.With(func(r *http.Request) error {
|
2018-02-11 18:14:39 -05:00
|
|
|
r.Header.Set("Upgrade", "foo")
|
|
|
|
return nil
|
2018-04-17 04:22:04 -04:00
|
|
|
}))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
|
2018-02-11 18:14:39 -05:00
|
|
|
buf, err = req.ReadBody(body)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(string(buf), "not supported"))
|
2018-02-11 18:14:39 -05:00
|
|
|
}
|