2018-02-11 18:14:39 -05:00
|
|
|
package session // import "github.com/docker/docker/integration/session"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2019-07-17 17:40:37 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
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) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
2019-07-17 17:40:37 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.39"), "experimental in older versions")
|
2018-02-11 18:14:39 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
2018-12-24 10:55:22 -05:00
|
|
|
daemonHost := req.DaemonHost()
|
|
|
|
|
|
|
|
res, body, err := req.Post("/session",
|
|
|
|
req.Host(daemonHost),
|
|
|
|
req.With(func(r *http.Request) error {
|
|
|
|
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-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) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
2019-07-17 17:40:37 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.39"), "experimental in older versions")
|
2018-02-11 18:14:39 -05:00
|
|
|
|
2018-12-24 10:55:22 -05:00
|
|
|
defer setupTest(t)()
|
|
|
|
daemonHost := req.DaemonHost()
|
|
|
|
|
|
|
|
res, body, err := req.Post("/session", req.Host(daemonHost))
|
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-12-24 10:55:22 -05:00
|
|
|
res, body, err = req.Post("/session",
|
|
|
|
req.Host(daemonHost),
|
|
|
|
req.With(func(r *http.Request) error {
|
|
|
|
r.Header.Set("Upgrade", "foo")
|
|
|
|
return nil
|
|
|
|
}),
|
|
|
|
)
|
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
|
|
|
}
|