MCPcopy
hub / github.com/nats-io/nats.go / TestWSWithTLSCustomDialer

Function TestWSWithTLSCustomDialer

test/ws_test.go:370–409  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

368}
369
370func TestWSWithTLSCustomDialer(t *testing.T) {
371 sopts := testWSGetDefaultOptions(t, true)
372 s := RunServerWithOptions(sopts)
373 defer s.Shutdown()
374
375 sd := &testSkipTLSDialer{
376 dialer: &net.Dialer{
377 Timeout: 2 * time.Second,
378 },
379 skipTLS: true,
380 }
381
382 // Connect with CustomDialer that fails since TLSHandshake is disabled.
383 copts := make([]nats.Option, 0)
384 copts = append(copts, nats.Secure(&tls.Config{InsecureSkipVerify: true}))
385 copts = append(copts, nats.SetCustomDialer(sd))
386 _, err := nats.Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
387 if err == nil {
388 t.Fatalf("Expected error on connect: %v", err)
389 }
390 if err.Error() != `invalid websocket connection` {
391 t.Logf("Expected invalid websocket connection: %v", err)
392 }
393
394 // Retry with the dialer.
395 copts = make([]nats.Option, 0)
396 sd = &testSkipTLSDialer{
397 dialer: &net.Dialer{
398 Timeout: 2 * time.Second,
399 },
400 skipTLS: false,
401 }
402 copts = append(copts, nats.Secure(&tls.Config{InsecureSkipVerify: true}))
403 copts = append(copts, nats.SetCustomDialer(sd))
404 nc, err := nats.Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
405 if err != nil {
406 t.Fatalf("Unexpected error on connect: %v", err)
407 }
408 defer nc.Close()
409}
410
411func TestWSGossipAndReconnect(t *testing.T) {
412 o1 := testWSGetDefaultOptions(t, false)

Callers

nothing calls this directly

Calls 6

testWSGetDefaultOptionsFunction · 0.85
ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerWithOptionsFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected