MCPcopy
hub / github.com/gorilla/websocket / TestDialCookieJar

Function TestDialCookieJar

client_server_test.go:241–287  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestDialCookieJar(t *testing.T) {
242 s := newServer(t)
243 defer s.Close()
244
245 jar, _ := cookiejar.New(nil)
246 d := cstDialer
247 d.Jar = jar
248
249 u, _ := url.Parse(s.URL)
250
251 switch u.Scheme {
252 case "ws":
253 u.Scheme = "http"
254 case "wss":
255 u.Scheme = "https"
256 }
257
258 cookies := []*http.Cookie{{Name: "gorilla", Value: "ws", Path: "/"}}
259 d.Jar.SetCookies(u, cookies)
260
261 ws, _, err := d.Dial(s.URL, nil)
262 if err != nil {
263 t.Fatalf("Dial: %v", err)
264 }
265 defer ws.Close()
266
267 var gorilla string
268 var sessionID string
269 for _, c := range d.Jar.Cookies(u) {
270 if c.Name == "gorilla" {
271 gorilla = c.Value
272 }
273
274 if c.Name == "sessionID" {
275 sessionID = c.Value
276 }
277 }
278 if gorilla != "ws" {
279 t.Error("Cookie not present in jar.")
280 }
281
282 if sessionID != "1234" {
283 t.Error("Set-Cookie not received from the server.")
284 }
285
286 sendRecv(t, ws)
287}
288
289func rootCAs(t *testing.T, s *httptest.Server) *x509.CertPool {
290 certs := x509.NewCertPool()

Callers

nothing calls this directly

Calls 5

newServerFunction · 0.85
sendRecvFunction · 0.85
DialMethod · 0.65
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected