Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-http-proxy
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
node-http-proxy
Commits
734769fa
Commit
734769fa
authored
Sep 10, 2011
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Updated tests to reflect finalized API of the RoutingProxy
parent
f765f90e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
55 deletions
+72
-55
test/helpers.js
test/helpers.js
+36
-17
test/http/http-proxy-test.js
test/http/http-proxy-test.js
+4
-5
test/http/routing-proxy-test.js
test/http/routing-proxy-test.js
+11
-12
test/websocket/websocket-proxy-test.js
test/websocket/websocket-proxy-test.js
+12
-12
test/websocket/websocket-routing-proxy-test.js
test/websocket/websocket-routing-proxy-test.js
+9
-9
No files found.
test/helpers.js
View file @
734769fa
...
...
@@ -5,15 +5,16 @@
*
*/
var
fs
=
require
(
'
fs
'
),
var
assert
=
require
(
'
assert
'
),
fs
=
require
(
'
fs
'
),
http
=
require
(
'
http
'
),
https
=
require
(
'
https
'
),
path
=
require
(
'
path
'
),
vows
=
require
(
'
vows
'
),
assert
=
require
(
'
assert
'
),
argv
=
require
(
'
optimist
'
).
argv
,
request
=
require
(
'
request
'
),
websocket
=
require
(
'
./../vendor/websocket
'
),
httpProxy
=
require
(
'
./../lib/node-http-proxy
'
);
vows
=
require
(
'
vows
'
),
websocket
=
require
(
'
../vendor/websocket
'
),
httpProxy
=
require
(
'
../lib/node-http-proxy
'
);
var
loadHttps
=
exports
.
loadHttps
=
function
()
{
return
{
...
...
@@ -22,16 +23,34 @@ var loadHttps = exports.loadHttps = function () {
};
};
var
TestRunner
=
exports
.
TestRunner
=
function
(
source
,
target
)
{
this
.
source
=
{
protocol
:
source
},
this
.
target
=
{
protocol
:
target
};
var
parseProtocol
=
exports
.
parseProtocol
=
function
()
{
function
setupProtocol
(
secure
)
{
return
{
secure
:
secure
,
protocols
:
{
http
:
secure
?
'
https
'
:
'
http
'
,
ws
:
secure
?
'
wss
'
:
'
ws
'
}
}
}
return
{
source
:
setupProtocol
(
argv
.
source
===
'
secure
'
),
target
:
setupProtocol
(
argv
.
target
===
'
secure
'
)
};
}
var
TestRunner
=
exports
.
TestRunner
=
function
(
options
)
{
options
=
options
||
{};
this
.
source
=
options
.
source
||
{};
this
.
target
=
options
.
target
||
{};
this
.
testServers
=
[];
if
(
source
===
'
https
'
)
{
if
(
this
.
source
.
secure
)
{
this
.
source
.
https
=
loadHttps
();
}
if
(
t
arget
===
'
https
'
)
{
if
(
t
his
.
target
.
secure
)
{
this
.
target
.
https
=
loadHttps
();
}
};
...
...
@@ -48,7 +67,7 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
options
=
{
method
:
'
GET
'
,
uri
:
self
.
source
.
protocol
+
'
://localhost:
'
+
proxyPort
,
uri
:
self
.
source
.
protocol
s
.
http
+
'
://localhost:
'
+
proxyPort
,
headers
:
{
host
:
host
}
...
...
@@ -79,7 +98,7 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
TestRunner
.
prototype
.
assertResponseCode
=
function
(
proxyPort
,
statusCode
,
createProxy
)
{
var
assertion
=
"
should receive
"
+
statusCode
+
"
responseCode
"
,
protocol
=
this
.
source
.
protocol
;
protocol
=
this
.
source
.
protocol
s
.
http
;
var
test
=
{
topic
:
function
()
{
...
...
@@ -240,11 +259,11 @@ TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, laten
// Initialize the nodeProxy and start proxying the request
//
var
that
=
this
,
proxy
=
new
httpProxy
.
Http
Proxy
(
merge
({},
options
,
this
.
getOptions
())),
proxy
=
new
httpProxy
.
Routing
Proxy
(
merge
({},
options
,
this
.
getOptions
())),
proxyServer
;
var
handler
=
function
(
req
,
res
)
{
var
buffer
=
p
roxy
.
buffer
(
req
);
var
buffer
=
httpP
roxy
.
buffer
(
req
);
setTimeout
(
function
()
{
proxy
.
proxyRequest
(
req
,
res
,
{
buffer
:
buffer
...
...
@@ -252,9 +271,9 @@ TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, laten
},
latency
);
};
proxyServer
=
th
at
.
options
.
https
?
https
.
createServer
(
th
at
.
options
.
https
,
handler
,
that
.
options
)
:
http
.
createServer
(
handler
,
that
.
options
);
proxyServer
=
th
is
.
source
.
https
?
https
.
createServer
(
th
is
.
source
.
https
,
handler
)
:
http
.
createServer
(
handler
);
proxyServer
.
listen
(
port
,
function
()
{
that
.
testServers
.
push
(
proxyServer
);
...
...
test/http/http-proxy-test.js
View file @
734769fa
...
...
@@ -26,7 +26,6 @@
var
assert
=
require
(
'
assert
'
),
util
=
require
(
'
util
'
),
argv
=
require
(
'
optimist
'
).
argv
,
request
=
require
(
'
request
'
),
vows
=
require
(
'
vows
'
),
helpers
=
require
(
'
../helpers
'
);
...
...
@@ -45,11 +44,11 @@ var badForwardOptions = {
}
};
var
protocol
=
argv
.
https
?
'
https
'
:
'
http
'
,
t
arget
=
argv
.
target
?
argv
.
target
:
'
http
'
,
runner
=
new
helpers
.
TestRunner
(
protocol
,
target
);
var
options
=
helpers
.
parseProtocol
()
,
t
estName
=
[
options
.
source
.
protocols
.
http
,
options
.
target
.
protocols
.
http
].
join
(
'
-to-
'
)
,
runner
=
new
helpers
.
TestRunner
(
options
);
vows
.
describe
(
'
node-http-proxy/
'
+
protocol
).
addBatch
({
vows
.
describe
(
'
node-http-proxy/
http-proxy/
'
+
testName
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
with no latency
"
:
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8080
,
8081
,
function
(
callback
)
{
...
...
test/http/routing-proxy-test.js
View file @
734769fa
...
...
@@ -14,8 +14,9 @@ var assert = require('assert'),
vows
=
require
(
'
vows
'
),
helpers
=
require
(
'
../helpers
'
);
var
protocol
=
argv
.
https
?
'
https
'
:
'
http
'
,
runner
=
new
helpers
.
TestRunner
(
protocol
),
var
options
=
helpers
.
parseProtocol
(),
testName
=
[
options
.
source
.
protocols
.
http
,
options
.
target
.
protocols
.
http
].
join
(
'
-to-
'
),
runner
=
new
helpers
.
TestRunner
(
options
),
routeFile
=
path
.
join
(
__dirname
,
'
config.json
'
);
var
fileOptions
=
{
...
...
@@ -40,7 +41,7 @@ var hostnameOptions = {
}
};
vows
.
describe
(
'
node-http-proxy/
proxy-table/
'
+
protocol
).
addBatch
({
vows
.
describe
(
'
node-http-proxy/
routing-proxy/
'
+
testName
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
when passed a routing table
"
:
{
"
and routing by RegExp
"
:
{
...
...
@@ -81,16 +82,14 @@ vows.describe('node-http-proxy/proxy-table/' + protocol).addBatch({
fs
.
writeFileSync
(
routeFile
,
JSON
.
stringify
(
config
));
this
.
server
.
on
(
'
routes
'
,
function
()
{
var
options
=
{
method
:
'
GET
'
,
uri
:
protocol
+
'
://localhost:8100
'
,
headers
:
{
host
:
'
dynamic.com
'
}
};
runner
.
startTargetServer
(
8103
,
'
hello dynamic.com
'
,
function
()
{
request
(
options
,
that
.
callback
);
request
({
method
:
'
GET
'
,
uri
:
options
.
source
.
protocols
.
http
+
'
://localhost:8100
'
,
headers
:
{
host
:
'
dynamic.com
'
}
},
that
.
callback
);
});
});
},
...
...
test/websocket/websocket-proxy-test.js
View file @
734769fa
...
...
@@ -43,11 +43,11 @@ catch (ex) {
process
.
exit
(
1
);
}
var
protocol
=
argv
.
https
?
'
https
'
:
'
http
'
,
wsprotocol
=
argv
.
https
?
'
wss
'
:
'
ws
'
,
runner
=
new
helpers
.
TestRunner
(
protocol
);
var
options
=
helpers
.
parseProtocol
()
,
testName
=
[
options
.
source
.
protocols
.
ws
,
options
.
target
.
protocols
.
ws
].
join
(
'
-to-
'
)
,
runner
=
new
helpers
.
TestRunner
(
options
);
vows
.
describe
(
'
node-http-proxy/
websocket/
'
+
wsprotocol
).
addBatch
({
vows
.
describe
(
'
node-http-proxy/
http-proxy/
'
+
testName
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
with no latency
"
:
{
"
when an inbound message is sent from a WebSocket client
"
:
{
...
...
@@ -58,8 +58,8 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
runner
.
webSocketTest
({
io
:
io
,
host
:
'
localhost
'
,
wsprotocol
:
wsprotocol
,
protocol
:
protocol
,
wsprotocol
:
options
.
source
.
protocols
.
ws
,
protocol
:
options
.
source
.
protocols
.
http
,
ports
:
{
target
:
8130
,
proxy
:
8131
...
...
@@ -85,7 +85,7 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
},
"
the origin and sec-websocket-origin headers should match
"
:
function
(
err
,
msg
,
headers
)
{
assert
.
isString
(
headers
.
response
[
'
sec-websocket-location
'
]);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
wsprotocol
)
!==
-
1
);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
options
.
source
.
protocols
.
ws
)
!==
-
1
);
assert
.
equal
(
headers
.
request
.
Origin
,
headers
.
response
[
'
sec-websocket-origin
'
]);
}
},
...
...
@@ -97,8 +97,8 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
runner
.
webSocketTest
({
io
:
io
,
host
:
'
localhost
'
,
wsprotocol
:
wsprotocol
,
protocol
:
protocol
,
wsprotocol
:
options
.
source
.
protocols
.
ws
,
protocol
:
options
.
source
.
protocols
.
http
,
ports
:
{
target
:
8132
,
proxy
:
8133
...
...
@@ -126,8 +126,8 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
runner
.
webSocketTest
({
io
:
io
,
host
:
'
localhost
'
,
wsprotocol
:
wsprotocol
,
protocol
:
protocol
,
wsprotocol
:
options
.
source
.
protocols
.
ws
,
protocol
:
options
.
source
.
protocols
.
http
,
ports
:
{
target
:
8134
,
proxy
:
8135
...
...
@@ -154,7 +154,7 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
},
"
the origin and sec-websocket-origin headers should match
"
:
function
(
err
,
msg
,
headers
)
{
assert
.
isString
(
headers
.
response
[
'
sec-websocket-location
'
]);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
wsprotocol
)
!==
-
1
);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
options
.
source
.
protocols
.
ws
)
!==
-
1
);
assert
.
equal
(
headers
.
request
.
Origin
,
headers
.
response
[
'
sec-websocket-origin
'
]);
}
}
...
...
test/websocket/websocket-routing-proxy-test.js
View file @
734769fa
...
...
@@ -30,7 +30,7 @@ var util = require('util'),
colors
=
require
(
'
colors
'
),
request
=
require
(
'
request
'
),
vows
=
require
(
'
vows
'
),
websocket
=
require
(
'
../vendor/websocket
'
),
websocket
=
require
(
'
../
../
vendor/websocket
'
),
helpers
=
require
(
'
../helpers
'
);
try
{
...
...
@@ -43,11 +43,11 @@ catch (ex) {
process
.
exit
(
1
);
}
var
protocol
=
argv
.
https
?
'
https
'
:
'
http
'
,
wsprotocol
=
argv
.
https
?
'
wss
'
:
'
ws
'
,
runner
=
new
helpers
.
TestRunner
(
protocol
);
var
options
=
helpers
.
parseProtocol
()
,
testName
=
[
options
.
source
.
protocols
.
ws
,
options
.
target
.
protocols
.
ws
].
join
(
'
-to-
'
)
,
runner
=
new
helpers
.
TestRunner
(
options
);
vows
.
describe
(
'
node-http-proxy/
websocket/
'
+
wsprotocol
).
addBatch
({
vows
.
describe
(
'
node-http-proxy/
routing-proxy/
'
+
testName
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
using proxy table with no latency
"
:
{
"
when an inbound message is sent from a WebSocket client
"
:
{
...
...
@@ -58,9 +58,9 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
runner
.
webSocketTestWithTable
({
io
:
io
,
host
:
'
localhost
'
,
wsprotocol
:
wsprotocol
,
protocol
:
protocol
,
router
:
{
'
localhost
'
:
'
localhost:8230
'
},
wsprotocol
:
options
.
source
.
protocols
.
ws
,
protocol
:
options
.
source
.
protocols
.
http
,
router
:
{
'
localhost
'
:
'
localhost:8230
'
},
ports
:
{
target
:
8230
,
proxy
:
8231
...
...
@@ -86,7 +86,7 @@ vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
},
"
the origin and sec-websocket-origin headers should match
"
:
function
(
err
,
msg
,
headers
)
{
assert
.
isString
(
headers
.
response
[
'
sec-websocket-location
'
]);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
wsprotocol
)
!==
-
1
);
assert
.
isTrue
(
headers
.
response
[
'
sec-websocket-location
'
].
indexOf
(
options
.
source
.
protocols
.
ws
)
!==
-
1
);
assert
.
equal
(
headers
.
request
.
Origin
,
headers
.
response
[
'
sec-websocket-origin
'
]);
}
}
...
...
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