Skip to content

Commit

Permalink
Fix websocket tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Donini <[email protected]>
  • Loading branch information
lorenzodonini committed Jul 25, 2021
1 parent 904e603 commit 747c045
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ws/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ func TestClientDuplicateConnection(t *testing.T) {
require.IsType(t, &websocket.CloseError{}, err)
wsErr, _ := err.(*websocket.CloseError)
assert.Equal(t, websocket.ClosePolicyViolation, wsErr.Code)
assert.Equal(t, "client already exists", wsErr.Text)
assert.Equal(t, "a connection with this ID already exists", wsErr.Text)
wsClient2.SetDisconnectedHandler(nil)
disconnectC <- struct{}{}
})
err = wsClient2.Start(u.String())
Expand Down Expand Up @@ -482,6 +483,9 @@ func TestValidBasicAuth(t *testing.T) {
wsClient := NewTLSClient(&tls.Config{
RootCAs: certPool,
})
wsClient.AddOption(func(dialer *websocket.Dialer) {
dialer.Subprotocols = append(dialer.Subprotocols, defaultSubProtocol)
})
// Add basic auth
wsClient.SetBasicAuth(authUsername, authPassword)
// Test connection
Expand Down Expand Up @@ -679,6 +683,9 @@ func TestValidClientTLSCertificate(t *testing.T) {
RootCAs: certPool,
Certificates: []tls.Certificate{loadedCert},
})
wsClient.AddOption(func(dialer *websocket.Dialer) {
dialer.Subprotocols = append(dialer.Subprotocols, defaultSubProtocol)
})
// Test connection
host := fmt.Sprintf("localhost:%v", serverPort)
u := url.URL{Scheme: "wss", Host: host, Path: testPath}
Expand Down Expand Up @@ -736,6 +743,9 @@ func TestInvalidClientTLSCertificate(t *testing.T) {
RootCAs: certPool, // Contains server certificate as allowed server CA
Certificates: []tls.Certificate{loadedCert}, // Contains self-signed client certificate. Will be rejected by server
})
wsClient.AddOption(func(dialer *websocket.Dialer) {
dialer.Subprotocols = append(dialer.Subprotocols, defaultSubProtocol)
})
// Test connection
host := fmt.Sprintf("localhost:%v", serverPort)
u := url.URL{Scheme: "wss", Host: host, Path: testPath}
Expand Down Expand Up @@ -775,6 +785,7 @@ func TestUnsupportedSubprotocol(t *testing.T) {
wsErr, _ := err.(*websocket.CloseError)
assert.Equal(t, websocket.CloseProtocolError, wsErr.Code)
assert.Equal(t, "invalid or unsupported subprotocol", wsErr.Text)
wsClient.SetDisconnectedHandler(nil)
disconnectC <- struct{}{}
})
// Set invalid subprotocol
Expand Down

0 comments on commit 747c045

Please sign in to comment.