You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package websocket
  5. import (
  6. "crypto/tls"
  7. "fmt"
  8. "log"
  9. "net"
  10. "net/http/httptest"
  11. "testing"
  12. "time"
  13. )
  14. // This test depend on Go 1.3+ because in earlier versions the Dialer won't be
  15. // used in TLS connections and a timeout won't be triggered.
  16. func TestDialConfigTLSWithDialer(t *testing.T) {
  17. tlsServer := httptest.NewTLSServer(nil)
  18. tlsServerAddr := tlsServer.Listener.Addr().String()
  19. log.Print("Test TLS WebSocket server listening on ", tlsServerAddr)
  20. defer tlsServer.Close()
  21. config, _ := NewConfig(fmt.Sprintf("wss://%s/echo", tlsServerAddr), "http://localhost")
  22. config.Dialer = &net.Dialer{
  23. Deadline: time.Now().Add(-time.Minute),
  24. }
  25. config.TlsConfig = &tls.Config{
  26. InsecureSkipVerify: true,
  27. }
  28. _, err := DialConfig(config)
  29. dialerr, ok := err.(*DialError)
  30. if !ok {
  31. t.Fatalf("DialError expected, got %#v", err)
  32. }
  33. neterr, ok := dialerr.Err.(*net.OpError)
  34. if !ok {
  35. t.Fatalf("net.OpError error expected, got %#v", dialerr.Err)
  36. }
  37. if !neterr.Timeout() {
  38. t.Fatalf("expected timeout error, got %#v", neterr)
  39. }
  40. }