tg-redbird 0.12.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -16
- package/lib/docker.js +22 -18
- package/lib/etcd-backend.js +32 -35
- package/lib/letsencrypt.js +41 -38
- package/lib/proxy.js +197 -238
- package/lib/redis-backend.js +84 -79
- package/package.json +17 -4
- package/.dockerignore +0 -1
- package/.eslintrc +0 -22
- package/.travis.yml +0 -21
- package/.vscode/launch.json +0 -30
- package/Dockerfile +0 -6
- package/gulpfile.js +0 -36
- package/hl-tests/64/proxy.js +0 -52
- package/hl-tests/letsencrypt/a.js +0 -36
- package/hl-tests/letsencrypt/certs/accounts/acme-staging.api.letsencrypt.org/directory/367e0270a5d31ab031561f9f284ca350/meta.json +0 -1
- package/hl-tests/letsencrypt/certs/accounts/acme-staging.api.letsencrypt.org/directory/367e0270a5d31ab031561f9f284ca350/private_key.json +0 -1
- package/hl-tests/letsencrypt/certs/accounts/acme-staging.api.letsencrypt.org/directory/367e0270a5d31ab031561f9f284ca350/regr.json +0 -1
- package/hl-tests/letsencrypt/certs/accounts/acme-v01.api.letsencrypt.org/directory/49881ab35d6ac7bb51f05ca3a220fbac/meta.json +0 -1
- package/hl-tests/letsencrypt/certs/accounts/acme-v01.api.letsencrypt.org/directory/49881ab35d6ac7bb51f05ca3a220fbac/private_key.json +0 -1
- package/hl-tests/letsencrypt/certs/accounts/acme-v01.api.letsencrypt.org/directory/49881ab35d6ac7bb51f05ca3a220fbac/regr.json +0 -1
- package/hl-tests/letsencrypt/certs/api/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/api.com/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/archive/caturra.exactbytes.com/cert0.pem +0 -29
- package/hl-tests/letsencrypt/certs/archive/caturra.exactbytes.com/chain0.pem +0 -27
- package/hl-tests/letsencrypt/certs/archive/caturra.exactbytes.com/fullchain0.pem +0 -56
- package/hl-tests/letsencrypt/certs/archive/caturra.exactbytes.com/privkey0.pem +0 -27
- package/hl-tests/letsencrypt/certs/caturra.exactbytes.com/cert.pem +0 -29
- package/hl-tests/letsencrypt/certs/caturra.exactbytes.com/chain.pem +0 -27
- package/hl-tests/letsencrypt/certs/caturra.exactbytes.com/fullchain.pem +0 -56
- package/hl-tests/letsencrypt/certs/caturra.exactbytes.com/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/caturra.exactbytes.com/privkey.pem.bak +0 -27
- package/hl-tests/letsencrypt/certs/dash/.well-known/acme-challenge/abc +0 -1
- package/hl-tests/letsencrypt/certs/dash/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/dash.com/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/dash_/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/dev-cert.pem +0 -17
- package/hl-tests/letsencrypt/certs/dev-csr.pem +0 -13
- package/hl-tests/letsencrypt/certs/dev-key.pem +0 -15
- package/hl-tests/letsencrypt/certs/example.com/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/localhost/privkey.pem +0 -27
- package/hl-tests/letsencrypt/certs/renewal/caturra.exactbytes.com.conf +0 -67
- package/hl-tests/letsencrypt/certs/renewal/caturra.exactbytes.com.conf.bak +0 -68
- package/hl-tests/letsencrypt/proxy.js +0 -73
- package/hl-tests/paths.js +0 -19
- package/package-lock.json +0 -3269
- package/test/test_custom_resolver.js +0 -276
- package/test/test_hostheader.js +0 -141
- package/test/test_pathnames.js +0 -75
- package/test/test_register.js +0 -493
@@ -1,276 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var Promise = require('bluebird');
|
4
|
-
var Redbird = require('../');
|
5
|
-
var expect = require('chai').expect;
|
6
|
-
var _ = require('lodash');
|
7
|
-
|
8
|
-
var opts = {
|
9
|
-
bunyan: false,
|
10
|
-
port: 10000 + Math.ceil(Math.random() * 55535)
|
11
|
-
/* {
|
12
|
-
name: 'test',
|
13
|
-
streams: [{
|
14
|
-
path: '/dev/null',
|
15
|
-
}]
|
16
|
-
} */
|
17
|
-
};
|
18
|
-
|
19
|
-
|
20
|
-
describe("Custom Resolver", function(){
|
21
|
-
|
22
|
-
it("Should contain one resolver by default", function () {
|
23
|
-
|
24
|
-
var redbird = Redbird(opts);
|
25
|
-
expect(redbird.resolvers).to.be.an('array');
|
26
|
-
expect(redbird.resolvers.length).to.be.eq(1);
|
27
|
-
expect(redbird.resolvers[0]).to.be.eq(redbird._defaultResolver);
|
28
|
-
|
29
|
-
redbird.close();
|
30
|
-
});
|
31
|
-
|
32
|
-
it("Should register resolver with right priority", function(){
|
33
|
-
var resolver = function () {
|
34
|
-
return 'http://127.0.0.1:8080';
|
35
|
-
};
|
36
|
-
|
37
|
-
resolver.priority = 1;
|
38
|
-
|
39
|
-
var options = _.extend({
|
40
|
-
resolvers: resolver
|
41
|
-
}, opts);
|
42
|
-
|
43
|
-
var redbird = Redbird(options);
|
44
|
-
|
45
|
-
expect(redbird.resolvers.length).to.be.eq(2);
|
46
|
-
expect(redbird.resolvers[0]).to.be.eql(resolver);
|
47
|
-
|
48
|
-
redbird.close();
|
49
|
-
|
50
|
-
|
51
|
-
// test when an array is sent in as resolvers.
|
52
|
-
options.resolvers = [resolver];
|
53
|
-
redbird = new Redbird(options);
|
54
|
-
expect(redbird.resolvers.length).to.be.eq(2);
|
55
|
-
expect(redbird.resolvers[0]).to.be.eql(resolver);
|
56
|
-
redbird.close();
|
57
|
-
|
58
|
-
resolver.priority = -1;
|
59
|
-
redbird = new Redbird(options);
|
60
|
-
expect(redbird.resolvers.length).to.be.eq(2);
|
61
|
-
expect(redbird.resolvers[1]).to.be.eql(resolver);
|
62
|
-
redbird.close();
|
63
|
-
|
64
|
-
|
65
|
-
// test when invalid resolver is added
|
66
|
-
options.resolvers = {};
|
67
|
-
expect(function () {
|
68
|
-
new Redbird(options)
|
69
|
-
}).to.throw(Error);
|
70
|
-
|
71
|
-
|
72
|
-
});
|
73
|
-
|
74
|
-
|
75
|
-
it('Should add and remove resolver after launch', function () {
|
76
|
-
|
77
|
-
var resolver = function () {};
|
78
|
-
resolver.priority = 1;
|
79
|
-
|
80
|
-
var redbird = Redbird(opts);
|
81
|
-
redbird.addResolver(resolver);
|
82
|
-
expect(redbird.resolvers.length).to.be.eq(2);
|
83
|
-
expect(redbird.resolvers[0]).to.be.eq(resolver);
|
84
|
-
|
85
|
-
redbird.addResolver(resolver);
|
86
|
-
expect(redbird.resolvers.length, 'Only allows uniques.').to.be.eq(2);
|
87
|
-
|
88
|
-
|
89
|
-
redbird.removeResolver(resolver);
|
90
|
-
expect(redbird.resolvers.length).to.be.eq(1);
|
91
|
-
expect(redbird.resolvers[0]).to.be.eq(redbird._defaultResolver);
|
92
|
-
|
93
|
-
redbird.close();
|
94
|
-
|
95
|
-
});
|
96
|
-
|
97
|
-
|
98
|
-
it('Should properly convert and cache route to routeObject', function () {
|
99
|
-
|
100
|
-
var builder = Redbird.buildRoute;
|
101
|
-
|
102
|
-
// invalid input
|
103
|
-
expect(builder(function () {})).to.be.null;
|
104
|
-
expect(builder([])).to.be.null;
|
105
|
-
expect(builder(2016)).to.be.null;
|
106
|
-
|
107
|
-
var testRoute = {urls: [], path: '/'};
|
108
|
-
var testRouteResult = builder(testRoute);
|
109
|
-
expect(testRouteResult, 'For route in the default format').to.be.eq(testRoute);
|
110
|
-
expect(testRouteResult.isResolved).to.be.undefined;
|
111
|
-
|
112
|
-
|
113
|
-
// case string:
|
114
|
-
var testString = 'http://127.0.0.1:8888';
|
115
|
-
var result = builder(testString);
|
116
|
-
expect(result.path).to.be.eq('/');
|
117
|
-
expect(result.urls).to.be.an('array');
|
118
|
-
expect(result.urls.length).to.be.eq(1);
|
119
|
-
expect(result.urls[0].hostname).to.be.eq('127.0.0.1');
|
120
|
-
expect(result.isResolved).to.be.true;
|
121
|
-
|
122
|
-
|
123
|
-
var result2 = builder(testString);
|
124
|
-
expect(result2).to.be.eq(result);
|
125
|
-
|
126
|
-
// case with object
|
127
|
-
|
128
|
-
var testObject_1= {path:'/api', url: 'http://127.0.0.1'},
|
129
|
-
testObjectResult_1 = builder(testObject_1);
|
130
|
-
|
131
|
-
expect(testObjectResult_1.path).to.be.eq('/api');
|
132
|
-
expect(testObjectResult_1.urls).to.be.an('array');
|
133
|
-
expect(testObjectResult_1.urls.length).to.be.eq(1);
|
134
|
-
expect(testObjectResult_1.urls[0].hostname).to.be.eq('127.0.0.1');
|
135
|
-
expect(testObjectResult_1.isResolved).to.be.true;
|
136
|
-
|
137
|
-
|
138
|
-
// test object caching.
|
139
|
-
var testObjectResult_2 = builder(testObject_1);
|
140
|
-
expect(testObjectResult_1).to.be.eq(testObjectResult_2);
|
141
|
-
|
142
|
-
var testObject_2= {url: ['http://127.0.0.1', 'http://123.1.1.1']}
|
143
|
-
var testResult2 = builder(testObject_2);
|
144
|
-
expect(testResult2.urls).to.not.be.undefined;
|
145
|
-
expect(testResult2.urls.length).to.be.eq(testObject_2.url.length);
|
146
|
-
expect(testResult2.urls[0].hostname).to.be.eq('127.0.0.1');
|
147
|
-
expect(testResult2.urls[1].hostname).to.be.eq('123.1.1.1');
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
});
|
152
|
-
|
153
|
-
it("Should resolve properly as expected", function () {
|
154
|
-
|
155
|
-
var proxy = new Redbird(opts), resolver = function (host, url) {
|
156
|
-
return url.match(/\/ignore/i) ? null : 'http://172.12.0.1/home'
|
157
|
-
}, result;
|
158
|
-
|
159
|
-
resolver.priority = 1;
|
160
|
-
|
161
|
-
proxy.register('mysite.example.com', 'http://127.0.0.1:9999');
|
162
|
-
proxy.addResolver(resolver);
|
163
|
-
// must match the resolver
|
164
|
-
return proxy.resolve('randomsite.example.com', '/anywhere')
|
165
|
-
.then(function (result) {
|
166
|
-
expect(result).to.not.be.null;
|
167
|
-
expect(result).to.not.be.undefined;
|
168
|
-
expect(result.urls.length).to.be.above(0);
|
169
|
-
expect(result.urls[0].hostname).to.be.eq('172.12.0.1');
|
170
|
-
|
171
|
-
// expect route to match resolver even though it matches registered address
|
172
|
-
return proxy.resolve('mysite.example.com', '/somewhere');
|
173
|
-
})
|
174
|
-
.then(function (result) {
|
175
|
-
expect(result.urls[0].hostname).to.be.eq('172.12.0.1');
|
176
|
-
|
177
|
-
// use default resolver, as custom resolver should ignore input.
|
178
|
-
return proxy.resolve('mysite.example.com', '/ignore');
|
179
|
-
})
|
180
|
-
.then(function (result) {
|
181
|
-
expect(result.urls[0].hostname).to.be.eq('127.0.0.1');
|
182
|
-
|
183
|
-
// make custom resolver low priority and test.
|
184
|
-
// result should match default resolver
|
185
|
-
resolver.priority = -1;
|
186
|
-
proxy.addResolver(resolver);
|
187
|
-
return proxy.resolve('mysite.example.com', '/somewhere');
|
188
|
-
})
|
189
|
-
.then(function (result) {
|
190
|
-
expect(result.urls[0].hostname).to.be.eq('127.0.0.1');
|
191
|
-
|
192
|
-
// both custom and default resolvers should ignore
|
193
|
-
return proxy.resolve('somesite.example.com', '/ignore');
|
194
|
-
})
|
195
|
-
.then(function (result) {
|
196
|
-
expect(result).to.be.undefined;
|
197
|
-
proxy.removeResolver(resolver);
|
198
|
-
|
199
|
-
// for path-based routing
|
200
|
-
// when resolver path doesn't match that of url, skip
|
201
|
-
|
202
|
-
resolver = function () {
|
203
|
-
return {
|
204
|
-
path: '/notme',
|
205
|
-
url: 'http://172.12.0.1/home'
|
206
|
-
}
|
207
|
-
};
|
208
|
-
resolver.priority = 1;
|
209
|
-
proxy.addResolver(resolver);
|
210
|
-
|
211
|
-
return proxy.resolve('somesite.example.com', '/notme');
|
212
|
-
})
|
213
|
-
.then(function (result) {
|
214
|
-
expect(result).to.not.be.undefined;
|
215
|
-
expect(result.urls[0].hostname).to.be.eq('172.12.0.1');
|
216
|
-
|
217
|
-
return proxy.resolve('somesite.example.com', '/notme/somewhere');
|
218
|
-
})
|
219
|
-
.then(function (result) {
|
220
|
-
expect(result.urls[0].hostname).to.be.eq('172.12.0.1');
|
221
|
-
|
222
|
-
return proxy.resolve('somesite.example.com', '/itsme/somewhere');
|
223
|
-
})
|
224
|
-
.then(function (result) {
|
225
|
-
expect(result).to.be.undefined;
|
226
|
-
proxy.close();
|
227
|
-
});
|
228
|
-
});
|
229
|
-
it("Should resolve array properly as expected", function () {
|
230
|
-
|
231
|
-
var proxy = new Redbird(opts);
|
232
|
-
|
233
|
-
var firstResolver = function (host, url) {
|
234
|
-
if (url.endsWith('/first-resolver')) {
|
235
|
-
return 'http://first-resolver/';
|
236
|
-
}
|
237
|
-
};
|
238
|
-
firstResolver.priority = 2;
|
239
|
-
|
240
|
-
var secondResolver = function (host, url) {
|
241
|
-
return new Promise(function(resolve, reject) {
|
242
|
-
if (url.endsWith('/second-resolver')) {
|
243
|
-
resolve('http://second-resolver/');
|
244
|
-
} else {
|
245
|
-
resolve(null);
|
246
|
-
}
|
247
|
-
});
|
248
|
-
};
|
249
|
-
secondResolver.priority = 1;
|
250
|
-
|
251
|
-
proxy.resolvers = []; // remove the defaultResolver
|
252
|
-
proxy.addResolver(firstResolver);
|
253
|
-
proxy.addResolver(secondResolver);
|
254
|
-
|
255
|
-
const cases = [
|
256
|
-
proxy.resolve('mysite.example.com', '/first-resolver')
|
257
|
-
.then(function(result) {
|
258
|
-
expect(result.urls.length).to.be.above(0);
|
259
|
-
expect(result.urls[0].hostname).to.be.eq('first-resolver');
|
260
|
-
}),
|
261
|
-
proxy.resolve('mysite.example.com', '/second-resolver')
|
262
|
-
.then(function(result) {
|
263
|
-
expect(result.urls.length).to.be.above(0);
|
264
|
-
expect(result.urls[0].hostname).to.be.eq('second-resolver');
|
265
|
-
})
|
266
|
-
];
|
267
|
-
|
268
|
-
return Promise.all(cases).then(
|
269
|
-
() => proxy.close(),
|
270
|
-
err => {
|
271
|
-
proxy.close();
|
272
|
-
throw err;
|
273
|
-
}
|
274
|
-
);
|
275
|
-
});
|
276
|
-
});
|
package/test/test_hostheader.js
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var Redbird = require('../');
|
4
|
-
var Promise = require('bluebird');
|
5
|
-
var http = require('http');
|
6
|
-
var expect = require('chai').expect;
|
7
|
-
|
8
|
-
var TEST_PORT = 54674
|
9
|
-
var PROXY_PORT = 53433
|
10
|
-
|
11
|
-
var opts = {
|
12
|
-
port: PROXY_PORT,
|
13
|
-
bunyan: false
|
14
|
-
}
|
15
|
-
|
16
|
-
describe("Target with a hostname", function(){
|
17
|
-
|
18
|
-
it("Should have the host header passed to the target", function(done){
|
19
|
-
var redbird = Redbird(opts);
|
20
|
-
|
21
|
-
expect(redbird.routing).to.be.an("object");
|
22
|
-
|
23
|
-
redbird.register('127.0.0.1', '127.0.0.1.xip.io:'+TEST_PORT, {
|
24
|
-
useTargetHostHeader: true
|
25
|
-
});
|
26
|
-
|
27
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
28
|
-
|
29
|
-
testServer().then(function(req){
|
30
|
-
expect(req.headers['host']).to.be.eql('127.0.0.1.xip.io:'+TEST_PORT)
|
31
|
-
})
|
32
|
-
|
33
|
-
http.get('http://127.0.0.1:'+PROXY_PORT, function(res) {
|
34
|
-
redbird.close();
|
35
|
-
done();
|
36
|
-
});
|
37
|
-
|
38
|
-
})
|
39
|
-
|
40
|
-
it("Should not have the host header passed to the target", function(done){
|
41
|
-
var redbird = Redbird(opts);
|
42
|
-
|
43
|
-
expect(redbird.routing).to.be.an("object");
|
44
|
-
|
45
|
-
redbird.register('127.0.0.1', '127.0.0.1.xip.io:'+TEST_PORT);
|
46
|
-
|
47
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
48
|
-
|
49
|
-
testServer().then(function(req){
|
50
|
-
expect(req.headers['host']).to.be.eql('127.0.0.1:'+PROXY_PORT)
|
51
|
-
})
|
52
|
-
|
53
|
-
http.get('http://127.0.0.1:'+PROXY_PORT, function(res) {
|
54
|
-
redbird.close();
|
55
|
-
done();
|
56
|
-
});
|
57
|
-
|
58
|
-
})
|
59
|
-
|
60
|
-
it("Should return 404 after route is unregister", function(done){
|
61
|
-
var redbird = Redbird(opts);
|
62
|
-
|
63
|
-
expect(redbird.routing).to.be.an("object");
|
64
|
-
|
65
|
-
redbird.register('127.0.0.1', '127.0.0.1.xip.io:'+TEST_PORT);
|
66
|
-
redbird.unregister('127.0.0.1', '127.0.0.1.xip.io:'+TEST_PORT);
|
67
|
-
|
68
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
69
|
-
|
70
|
-
testServer().then(function(req){
|
71
|
-
expect(req.headers['host']).to.be.eql('127.0.0.1:'+PROXY_PORT)
|
72
|
-
})
|
73
|
-
|
74
|
-
http.get('http://127.0.0.1:'+PROXY_PORT, function(res) {
|
75
|
-
expect(res.statusCode).to.be.eql(404);
|
76
|
-
|
77
|
-
redbird.close();
|
78
|
-
done();
|
79
|
-
});
|
80
|
-
|
81
|
-
})
|
82
|
-
|
83
|
-
it("Should return 502 after route with no backend", function(done){
|
84
|
-
var redbird = Redbird(opts);
|
85
|
-
|
86
|
-
expect(redbird.routing).to.be.an("object");
|
87
|
-
|
88
|
-
redbird.register('127.0.0.1', '127.0.0.1.xip.io:502');
|
89
|
-
|
90
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
91
|
-
|
92
|
-
http.get('http://127.0.0.1:'+PROXY_PORT, function(res) {
|
93
|
-
expect(res.statusCode).to.be.eql(502);
|
94
|
-
|
95
|
-
redbird.close();
|
96
|
-
done();
|
97
|
-
});
|
98
|
-
})
|
99
|
-
})
|
100
|
-
|
101
|
-
describe("Request with forwarded host header", function () {
|
102
|
-
it("should prefer forwarded hostname if desired", function () {
|
103
|
-
var redbird = Redbird({
|
104
|
-
bunyan: false,
|
105
|
-
preferForwardedHost: true
|
106
|
-
});
|
107
|
-
|
108
|
-
expect(redbird.routing).to.be.an("object");
|
109
|
-
var req = { headers: {host: '127.0.0.1', "x-forwarded-host": "subdomain.example.com"} }
|
110
|
-
|
111
|
-
var source = redbird._getSource(req);
|
112
|
-
expect(source).to.be.eql('subdomain.example.com')
|
113
|
-
|
114
|
-
redbird.close();
|
115
|
-
});
|
116
|
-
|
117
|
-
it("should use original host if not further specified", function () {
|
118
|
-
var redbird = Redbird(opts);
|
119
|
-
|
120
|
-
expect(redbird.routing).to.be.an("object");
|
121
|
-
var req = { headers: { host: '127.0.0.1', "x-forwarded-host": "subdomain.example.com"} }
|
122
|
-
|
123
|
-
var source = redbird._getSource(req);
|
124
|
-
expect(source).to.be.eql('127.0.0.1')
|
125
|
-
|
126
|
-
redbird.close();
|
127
|
-
});
|
128
|
-
});
|
129
|
-
|
130
|
-
function testServer(){
|
131
|
-
return new Promise(function(resolve, reject){
|
132
|
-
var server = http.createServer(function(req, res){
|
133
|
-
res.write("");
|
134
|
-
res.end();
|
135
|
-
resolve(req);
|
136
|
-
server.close();
|
137
|
-
});
|
138
|
-
|
139
|
-
server.listen(TEST_PORT);
|
140
|
-
})
|
141
|
-
}
|
package/test/test_pathnames.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var Redbird = require('../');
|
4
|
-
var Promise = require('bluebird');
|
5
|
-
var http = require('http');
|
6
|
-
var expect = require('chai').expect;
|
7
|
-
|
8
|
-
var TEST_PORT = 54673
|
9
|
-
var PROXY_PORT = 53432
|
10
|
-
|
11
|
-
var opts = {
|
12
|
-
port: PROXY_PORT,
|
13
|
-
bunyan: false /* {
|
14
|
-
name: 'test',
|
15
|
-
streams: [{
|
16
|
-
path: '/dev/null',
|
17
|
-
}]
|
18
|
-
} */
|
19
|
-
}
|
20
|
-
|
21
|
-
describe("Target with pathnames", function(){
|
22
|
-
|
23
|
-
it("Should be proxyed to target with pathname and source pathname concatenated", function(done){
|
24
|
-
var redbird = Redbird(opts);
|
25
|
-
|
26
|
-
expect(redbird.routing).to.be.an("object");
|
27
|
-
|
28
|
-
redbird.register('127.0.0.1', '127.0.0.1:'+TEST_PORT+'/foo/bar/qux');
|
29
|
-
|
30
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
31
|
-
|
32
|
-
testServer().then(function(req){
|
33
|
-
expect(req.url).to.be.eql('/foo/bar/qux/a/b/c')
|
34
|
-
})
|
35
|
-
|
36
|
-
http.get('http://127.0.0.1:'+PROXY_PORT+'/a/b/c', function(res) {
|
37
|
-
redbird.close();
|
38
|
-
done();
|
39
|
-
});
|
40
|
-
|
41
|
-
})
|
42
|
-
|
43
|
-
it("Should be proxyed to target with pathname and source pathname concatenated case 2", function(done){
|
44
|
-
var redbird = new Redbird(opts);
|
45
|
-
|
46
|
-
expect(redbird.routing).to.be.an("object");
|
47
|
-
|
48
|
-
redbird.register('127.0.0.1/path', '127.0.0.1:'+TEST_PORT+'/foo/bar/qux');
|
49
|
-
|
50
|
-
expect(redbird.routing).to.have.property("127.0.0.1");
|
51
|
-
|
52
|
-
testServer().then(function(req){
|
53
|
-
expect(req.url).to.be.eql('/foo/bar/qux/a/b/c')
|
54
|
-
})
|
55
|
-
|
56
|
-
http.get('http://127.0.0.1:'+PROXY_PORT+'/path/a/b/c', function(err, res) {
|
57
|
-
redbird.close();
|
58
|
-
done();
|
59
|
-
});
|
60
|
-
|
61
|
-
})
|
62
|
-
})
|
63
|
-
|
64
|
-
|
65
|
-
function testServer(){
|
66
|
-
return new Promise(function(resolve, reject){
|
67
|
-
var server = http.createServer(function(req, res){
|
68
|
-
res.write("");
|
69
|
-
res.end();
|
70
|
-
resolve(req);
|
71
|
-
server.close();
|
72
|
-
});
|
73
|
-
server.listen(TEST_PORT);
|
74
|
-
})
|
75
|
-
}
|