github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/session/session_test.go (about) 1 package session // import "github.com/docker/docker/integration/session" 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/docker/docker/api/types/versions" 8 req "github.com/docker/docker/testutil/request" 9 "gotest.tools/v3/assert" 10 is "gotest.tools/v3/assert/cmp" 11 "gotest.tools/v3/skip" 12 ) 13 14 func TestSessionCreate(t *testing.T) { 15 skip.If(t, testEnv.OSType == "windows", "FIXME") 16 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.39"), "experimental in older versions") 17 18 defer setupTest(t)() 19 daemonHost := req.DaemonHost() 20 21 res, body, err := req.Post("/session", 22 req.Host(daemonHost), 23 req.With(func(r *http.Request) error { 24 r.Header.Set("X-Docker-Expose-Session-Uuid", "testsessioncreate") // so we don't block default name if something else is using it 25 r.Header.Set("Upgrade", "h2c") 26 return nil 27 }), 28 ) 29 assert.NilError(t, err) 30 assert.NilError(t, body.Close()) 31 assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusSwitchingProtocols)) 32 assert.Check(t, is.Equal(res.Header.Get("Upgrade"), "h2c")) 33 } 34 35 func TestSessionCreateWithBadUpgrade(t *testing.T) { 36 skip.If(t, testEnv.OSType == "windows", "FIXME") 37 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.39"), "experimental in older versions") 38 39 defer setupTest(t)() 40 daemonHost := req.DaemonHost() 41 42 res, body, err := req.Post("/session", req.Host(daemonHost)) 43 assert.NilError(t, err) 44 assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest)) 45 buf, err := req.ReadBody(body) 46 assert.NilError(t, err) 47 assert.Check(t, is.Contains(string(buf), "no upgrade")) 48 49 res, body, err = req.Post("/session", 50 req.Host(daemonHost), 51 req.With(func(r *http.Request) error { 52 r.Header.Set("Upgrade", "foo") 53 return nil 54 }), 55 ) 56 assert.NilError(t, err) 57 assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest)) 58 buf, err = req.ReadBody(body) 59 assert.NilError(t, err) 60 assert.Check(t, is.Contains(string(buf), "not supported")) 61 }