2018-02-11 18:14:39 -05:00
|
|
|
package session // import "github.com/docker/docker/integration/session"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
req "github.com/docker/docker/integration-cli/request"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-02-11 18:14:39 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/skip"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionCreate(t *testing.T) {
|
|
|
|
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
|
|
|
|
res, body, err := req.Post("/session", 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) {
|
|
|
|
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
res, body, err = req.Post("/session", 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
|
|
|
}
|