Skip to content

Commit 52c6912

Browse files
committed
Tidy up PAC tests slightly to fully confirm proxying
1 parent 6f3795a commit 52c6912

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

test/integration/proxying/upstream-proxying.spec.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,22 +459,22 @@ nodeOnly(() => {
459459
keyPath: './test/fixtures/test-ca.key',
460460
certPath: './test/fixtures/test-ca.pem'
461461
};
462-
462+
463463
const intermediateProxy = getLocal({ https });
464-
464+
465465
beforeEach(async () => {
466466
server = getLocal({ https });
467467
await server.start();
468468

469469
await intermediateProxy.start();
470-
470+
471471
process.env = _.merge({}, process.env, server.proxyEnv);
472472
});
473-
473+
474474
afterEach(async () => {
475475
await intermediateProxy.stop();
476476
});
477-
477+
478478
it("should forward traffic to intermediateProxy using PAC file", async () => {
479479
const pacFile = `function FindProxyForURL(url, host) { return "PROXY ${url.parse(intermediateProxy.url).host}"; }`;
480480
await remoteServer.forGet('/proxy-all').thenReply(200, pacFile);
@@ -485,43 +485,56 @@ nodeOnly(() => {
485485
proxyUrl: `pac+${remoteServer.url}/proxy-all`
486486
}
487487
});
488-
488+
489489
await intermediateProxy.forAnyRequest().thenPassThrough({
490490
ignoreHostHttpsErrors: true,
491491
beforeRequest: (req) => {
492492
expect(req.url).to.equal('https://example.com/');
493+
return {
494+
response: {
495+
statusCode: 200,
496+
body: 'Proxied'
497+
}
498+
};
493499
}
494500
});
495-
496-
// make request
497-
await request.get('https://example.com/');
501+
502+
// make a request that hits the proxy based on PAC file
503+
expect(await request.get('https://example.com/')).to.equal('Proxied');
498504
});
499-
505+
500506
it("should bypass intermediateProxy using PAC file", async () => {
501-
const pacFile = `function FindProxyForURL(url, host) { if (host.endsWith(".org")) return "DIRECT"; return "PROXY ${url.parse(intermediateProxy.url).host}"; }`;
507+
const pacFile = `function FindProxyForURL(url, host) { if (host.endsWith(".com")) { return "PROXY ${url.parse(intermediateProxy.url).host}"; } else { return "DIRECT"; } }`;
502508
await remoteServer.forGet('/proxy-bypass').thenReply(200, pacFile);
509+
await remoteServer.forGet('/remote-response').thenReply(200, 'Remote response');
503510

504511
await server.forAnyRequest().thenPassThrough({
505512
ignoreHostHttpsErrors: true,
506513
proxyConfig: {
507514
proxyUrl: `pac+${remoteServer.url}/proxy-bypass`
508515
}
509516
});
510-
517+
511518
await intermediateProxy.forAnyRequest().thenPassThrough({
512519
ignoreHostHttpsErrors: true,
513520
beforeRequest: (req) => {
514521
expect(req.url).to.not.equal('https://example.org/');
522+
return {
523+
response: {
524+
statusCode: 200,
525+
body: 'Proxied'
526+
}
527+
};
515528
}
516529
});
517-
530+
518531
// make a request that hits the proxy based on PAC file
519-
await request.get('https://example.com/');
532+
expect(await request.get('https://example.com/')).to.equal('Proxied');
520533

521534
// make a request that bypasses proxy based on PAC file
522-
await request.get('https://example.org/');
535+
expect(await request.get(remoteServer.urlFor('/remote-response'))).to.equal('Remote response');
523536
});
524-
537+
525538
it("should fallback to intermediateProxy using PAC file", async () => {
526539
const pacFile = `function FindProxyForURL(url, host) { return "PROXY invalid-proxy:8080; PROXY ${url.parse(intermediateProxy.url).host};"; }`;
527540
await remoteServer.forGet('/proxy-fallback').thenReply(200, pacFile);
@@ -532,16 +545,22 @@ nodeOnly(() => {
532545
proxyUrl: `pac+${remoteServer.url}/proxy-fallback`
533546
}
534547
});
535-
548+
536549
await intermediateProxy.forAnyRequest().thenPassThrough({
537550
ignoreHostHttpsErrors: true,
538551
beforeRequest: (req) => {
539552
expect(req.url).to.equal('https://example.com/');
553+
return {
554+
response: {
555+
statusCode: 200,
556+
body: 'Proxied'
557+
}
558+
};
540559
}
541560
});
542-
543-
// make a request
544-
await request.get('https://example.com/');
561+
562+
// make a request that hits the proxy based on PAC file
563+
expect(await request.get('https://example.com/')).to.equal('Proxied');
545564
});
546565
});
547566

0 commit comments

Comments
 (0)