Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
20483c23
Commit
20483c23
authored
Dec 26, 2016
by
Leonard Hecker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added end-to-end test case for #1292
parent
9f9ad21a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
10 deletions
+65
-10
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+65
-10
No files found.
caddyhttp/proxy/proxy_test.go
View file @
20483c23
...
@@ -123,7 +123,7 @@ func TestWebSocketReverseProxyNonHijackerPanic(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestWebSocketReverseProxyNonHijackerPanic(t *testing.T) {
defer
wsNop
.
Close
()
defer
wsNop
.
Close
()
// Get proxy to use for the test
// Get proxy to use for the test
p
:=
newWebSocketTestProxy
(
wsNop
.
URL
)
p
:=
newWebSocketTestProxy
(
wsNop
.
URL
,
false
)
// Create client request
// Create client request
r
:=
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
:=
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
)
...
@@ -148,7 +148,7 @@ func TestWebSocketReverseProxyServeHTTPHandler(t *testing.T) {
...
@@ -148,7 +148,7 @@ func TestWebSocketReverseProxyServeHTTPHandler(t *testing.T) {
defer
wsNop
.
Close
()
defer
wsNop
.
Close
()
// Get proxy to use for the test
// Get proxy to use for the test
p
:=
newWebSocketTestProxy
(
wsNop
.
URL
)
p
:=
newWebSocketTestProxy
(
wsNop
.
URL
,
false
)
// Create client request
// Create client request
r
:=
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
:=
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
)
...
@@ -189,7 +189,7 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
...
@@ -189,7 +189,7 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
defer
wsEcho
.
Close
()
defer
wsEcho
.
Close
()
// Get proxy to use for the test
// Get proxy to use for the test
p
:=
newWebSocketTestProxy
(
wsEcho
.
URL
)
p
:=
newWebSocketTestProxy
(
wsEcho
.
URL
,
false
)
// This is a full end-end test, so the proxy handler
// This is a full end-end test, so the proxy handler
// has to be part of a server listening on a port. Our
// has to be part of a server listening on a port. Our
...
@@ -228,6 +228,52 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
...
@@ -228,6 +228,52 @@ func TestWebSocketReverseProxyFromWSClient(t *testing.T) {
}
}
}
}
func
TestWebSocketReverseProxyFromWSSClient
(
t
*
testing
.
T
)
{
wsEcho
:=
newTLSServer
(
websocket
.
Handler
(
func
(
ws
*
websocket
.
Conn
)
{
io
.
Copy
(
ws
,
ws
)
}))
defer
wsEcho
.
Close
()
p
:=
newWebSocketTestProxy
(
wsEcho
.
URL
,
true
)
echoProxy
:=
newTLSServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
p
.
ServeHTTP
(
w
,
r
)
}))
defer
echoProxy
.
Close
()
// Set up WebSocket client
url
:=
strings
.
Replace
(
echoProxy
.
URL
,
"https://"
,
"wss://"
,
1
)
wsCfg
,
err
:=
websocket
.
NewConfig
(
url
,
echoProxy
.
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wsCfg
.
TlsConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
ws
,
err
:=
websocket
.
DialConfig
(
wsCfg
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
ws
.
Close
()
// Send test message
trialMsg
:=
"Is it working?"
if
sendErr
:=
websocket
.
Message
.
Send
(
ws
,
trialMsg
);
sendErr
!=
nil
{
t
.
Fatal
(
sendErr
)
}
// It should be echoed back to us
var
actualMsg
string
if
rcvErr
:=
websocket
.
Message
.
Receive
(
ws
,
&
actualMsg
);
rcvErr
!=
nil
{
t
.
Fatal
(
rcvErr
)
}
if
actualMsg
!=
trialMsg
{
t
.
Errorf
(
"Expected '%s' but got '%s' instead"
,
trialMsg
,
actualMsg
)
}
}
func
TestUnixSocketProxy
(
t
*
testing
.
T
)
{
func
TestUnixSocketProxy
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
return
return
...
@@ -264,7 +310,7 @@ func TestUnixSocketProxy(t *testing.T) {
...
@@ -264,7 +310,7 @@ func TestUnixSocketProxy(t *testing.T) {
defer
ts
.
Close
()
defer
ts
.
Close
()
url
:=
strings
.
Replace
(
ts
.
URL
,
"http://"
,
"unix:"
,
1
)
url
:=
strings
.
Replace
(
ts
.
URL
,
"http://"
,
"unix:"
,
1
)
p
:=
newWebSocketTestProxy
(
url
)
p
:=
newWebSocketTestProxy
(
url
,
false
)
echoProxy
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
echoProxy
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
p
.
ServeHTTP
(
w
,
r
)
p
.
ServeHTTP
(
w
,
r
)
...
@@ -982,10 +1028,14 @@ func (u *fakeUpstream) GetTryInterval() time.Duration { return 250 * time.
...
@@ -982,10 +1028,14 @@ func (u *fakeUpstream) GetTryInterval() time.Duration { return 250 * time.
// redirect to the specified backendAddr. The function
// redirect to the specified backendAddr. The function
// also sets up the rules/environment for testing WebSocket
// also sets up the rules/environment for testing WebSocket
// proxy.
// proxy.
func
newWebSocketTestProxy
(
backendAddr
string
)
*
Proxy
{
func
newWebSocketTestProxy
(
backendAddr
string
,
insecure
bool
)
*
Proxy
{
return
&
Proxy
{
return
&
Proxy
{
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Upstreams
:
[]
Upstream
{
&
fakeWsUpstream
{
name
:
backendAddr
,
without
:
""
}},
Upstreams
:
[]
Upstream
{
&
fakeWsUpstream
{
name
:
backendAddr
,
without
:
""
,
insecure
:
insecure
,
}},
}
}
}
}
...
@@ -997,8 +1047,9 @@ func newPrefixedWebSocketTestProxy(backendAddr string, prefix string) *Proxy {
...
@@ -997,8 +1047,9 @@ func newPrefixedWebSocketTestProxy(backendAddr string, prefix string) *Proxy {
}
}
type
fakeWsUpstream
struct
{
type
fakeWsUpstream
struct
{
name
string
name
string
without
string
without
string
insecure
bool
}
}
func
(
u
*
fakeWsUpstream
)
From
()
string
{
func
(
u
*
fakeWsUpstream
)
From
()
string
{
...
@@ -1007,13 +1058,17 @@ func (u *fakeWsUpstream) From() string {
...
@@ -1007,13 +1058,17 @@ func (u *fakeWsUpstream) From() string {
func
(
u
*
fakeWsUpstream
)
Select
(
r
*
http
.
Request
)
*
UpstreamHost
{
func
(
u
*
fakeWsUpstream
)
Select
(
r
*
http
.
Request
)
*
UpstreamHost
{
uri
,
_
:=
url
.
Parse
(
u
.
name
)
uri
,
_
:=
url
.
Parse
(
u
.
name
)
return
&
UpstreamHost
{
host
:=
&
UpstreamHost
{
Name
:
u
.
name
,
Name
:
u
.
name
,
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
,
u
.
without
,
http
.
DefaultMaxIdleConnsPerHost
),
ReverseProxy
:
NewSingleHostReverseProxy
(
uri
,
u
.
without
,
http
.
DefaultMaxIdleConnsPerHost
),
UpstreamHeaders
:
http
.
Header
{
UpstreamHeaders
:
http
.
Header
{
"Connection"
:
{
"{>Connection}"
},
"Connection"
:
{
"{>Connection}"
},
"Upgrade"
:
{
"{>Upgrade}"
}},
"Upgrade"
:
{
"{>Upgrade}"
}},
}
}
if
u
.
insecure
{
host
.
ReverseProxy
.
UseInsecureTransport
()
}
return
host
}
}
func
(
u
*
fakeWsUpstream
)
AllowedPath
(
requestPath
string
)
bool
{
return
true
}
func
(
u
*
fakeWsUpstream
)
AllowedPath
(
requestPath
string
)
bool
{
return
true
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment