Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Websocket: discovered urls would not have "wss://" scheme #915

Merged
merged 1 commit into from Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nats.go
Expand Up @@ -1435,7 +1435,7 @@ func (nc *Conn) setupServerPool() error {

// Check for Scheme hint to move to TLS mode.
for _, srv := range nc.srvPool {
if srv.url.Scheme == tlsScheme {
if srv.url.Scheme == tlsScheme || srv.url.Scheme == wsSchemeTLS {
// FIXME(dlc), this is for all in the pool, should be case by case.
nc.Opts.Secure = true
if nc.Opts.TLSConfig == nil {
Expand Down
30 changes: 30 additions & 0 deletions ws_test.go
Expand Up @@ -860,6 +860,36 @@ func TestWSWithTLS(t *testing.T) {
}
}

func TestWSTlsNoConfig(t *testing.T) {
opts := GetDefaultOptions()
opts.Servers = []string{"wss://localhost:443"}

nc := &Conn{Opts: opts}
if err := nc.setupServerPool(); err != nil {
t.Fatalf("Error setting up pool: %v", err)
}
// Verify that this has set Secure/TLSConfig
nc.mu.Lock()
ok := nc.Opts.Secure && nc.Opts.TLSConfig != nil
nc.mu.Unlock()
if !ok {
t.Fatal("Secure and TLSConfig were not set")
}
// Now try to add a bare host:ip to the pool and verify
// that the wss:// scheme is added.
if err := nc.addURLToPool("1.2.3.4:443", true, false); err != nil {
t.Fatalf("Error adding to pool: %v", err)
}
nc.mu.Lock()
for _, srv := range nc.srvPool {
if srv.url.Scheme != wsSchemeTLS {
nc.mu.Unlock()
t.Fatalf("Expected scheme to be %q, got url: %s", wsSchemeTLS, srv.url)
}
}
nc.mu.Unlock()
}

func TestWSGossipAndReconnect(t *testing.T) {
o1 := testWSGetDefaultOptions(t, false)
o1.ServerName = "A"
Expand Down