github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/rpc/websocket_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:42</date> 10 //</624450110104801280> 11 12 13 package rpc 14 15 import "testing" 16 17 func TestWSGetConfigNoAuth(t *testing.T) { 18 config, err := wsGetConfig("ws://示例.com:1234“,”) 19 if err != nil { 20 t.Logf("wsGetConfig failed: %s", err) 21 t.Fail() 22 return 23 } 24 if config.Location.User != nil { 25 t.Log("User should have been stripped from the URL") 26 t.Fail() 27 } 28 if config.Location.Hostname() != "example.com" || 29 config.Location.Port() != "1234" || config.Location.Scheme != "ws" { 30 t.Logf("Unexpected URL: %s", config.Location) 31 t.Fail() 32 } 33 } 34 35 func TestWSGetConfigWithBasicAuth(t *testing.T) { 36 config, err := wsGetConfig("wss://testuser:test-pass_01@example.com:1234“,”) 37 if err != nil { 38 t.Logf("wsGetConfig failed: %s", err) 39 t.Fail() 40 return 41 } 42 if config.Location.User != nil { 43 t.Log("User should have been stripped from the URL") 44 t.Fail() 45 } 46 if config.Header.Get("Authorization") != "Basic dGVzdHVzZXI6dGVzdC1QQVNTXzAx" { 47 t.Log("Basic auth header is incorrect") 48 t.Fail() 49 } 50 } 51