aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/client_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-05-11 16:28:49 +0700
committerShulhan <m.shulhan@gmail.com>2020-05-11 16:28:59 +0700
commit25caa3fb9d7c87f08afae5c7f2d742deebb88efc (patch)
tree94626e875772f973ed6ad1c869df03ed070a471c /lib/websocket/client_test.go
parent312aebe8d792c8c85accde1148d870362a1974ae (diff)
downloadpakakeh.go-25caa3fb9d7c87f08afae5c7f2d742deebb88efc.tar.xz
websocket: allow "https" scheme on Client's Endpoint
Previously, we only check for "wss" scheme to initialize the TLS configuration. At some point, user may have one single address to connect to HTTP and WebSocket server on the same domain, which require two addresses on their side. This commit relaxing the Endpoint rule when parsing WebSocket URI. Scheme "https" will be considered as "wss" or secure connection with TLS.
Diffstat (limited to 'lib/websocket/client_test.go')
-rw-r--r--lib/websocket/client_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/websocket/client_test.go b/lib/websocket/client_test.go
index 9aae9cfc..466e0932 100644
--- a/lib/websocket/client_test.go
+++ b/lib/websocket/client_test.go
@@ -5,6 +5,7 @@
package websocket
import (
+ "crypto/tls"
"net/http"
"sync"
"testing"
@@ -60,6 +61,56 @@ func TestConnect(t *testing.T) {
}
}
+func TestClient_parseURI(t *testing.T) {
+ cl := &Client{}
+
+ cases := []struct {
+ endpoint string
+ expRemoteAddress string
+ expTLSConfig *tls.Config
+ expError string
+ }{{
+ endpoint: "ws://127.0.0.1:8080",
+ expRemoteAddress: "127.0.0.1:8080",
+ }, {
+ endpoint: "wss://127.0.0.1",
+ expRemoteAddress: "127.0.0.1:443",
+ expTLSConfig: new(tls.Config),
+ }, {
+ endpoint: "wss://127.0.0.1:8000",
+ expRemoteAddress: "127.0.0.1:8000",
+ expTLSConfig: new(tls.Config),
+ }, {
+ endpoint: "http://127.0.0.1",
+ expRemoteAddress: "127.0.0.1:80",
+ }, {
+ endpoint: "https://127.0.0.1",
+ expRemoteAddress: "127.0.0.1:443",
+ expTLSConfig: new(tls.Config),
+ }, {
+ endpoint: "https://127.0.0.1:8443",
+ expRemoteAddress: "127.0.0.1:8443",
+ expTLSConfig: new(tls.Config),
+ }}
+
+ for _, c := range cases {
+ t.Log("parseURI", c.endpoint)
+
+ cl.remoteAddr = ""
+ cl.TLSConfig = nil
+ cl.Endpoint = c.endpoint
+
+ err := cl.parseURI()
+ if err != nil {
+ test.Assert(t, "error", c.expError, err.Error(), true)
+ continue
+ }
+
+ test.Assert(t, "remote address", c.expRemoteAddress, cl.remoteAddr, true)
+ test.Assert(t, "TLS config", c.expTLSConfig, cl.TLSConfig, true)
+ }
+}
+
func TestClientPing(t *testing.T) {
if _testServer == nil {
runTestServer()