fix: switch to mojo proxy resolver (3-1-x) (#15813)

This commit is contained in:
Robo 2018-11-27 05:08:33 +05:30 committed by Michelle Tilley
commit 4abf55801f
65 changed files with 1838 additions and 1797 deletions

View file

@ -471,24 +471,63 @@ describe('session module', () => {
})
describe('ses.setProxy(options, callback)', () => {
let server = null
let customSession = null
beforeEach(() => {
customSession = session.fromPartition('proxyconfig')
})
afterEach(() => {
if (server) {
server.close()
}
if (customSession) {
customSession.destroy()
}
})
it('allows configuring proxy settings', (done) => {
const config = {proxyRules: 'http=myproxy:80'}
session.defaultSession.setProxy(config, () => {
session.defaultSession.resolveProxy('http://localhost', (proxy) => {
assert.equal(proxy, 'PROXY myproxy:80')
const config = { proxyRules: 'http=myproxy:80' }
customSession.setProxy(config, () => {
customSession.resolveProxy('http://localhost', (proxy) => {
assert.strictEqual(proxy, 'PROXY myproxy:80')
done()
})
})
})
it('allows configuring proxy settings with pacScript', (done) => {
server = http.createServer((req, res) => {
const pac = `
function FindProxyForURL(url, host) {
return "PROXY myproxy:8132";
}
`
res.writeHead(200, {
'Content-Type': 'application/x-ns-proxy-autoconfig'
})
res.end(pac)
})
server.listen(0, '127.0.0.1', () => {
const config = { pacScript: `http://127.0.0.1:${server.address().port}` }
customSession.setProxy(config, () => {
customSession.resolveProxy('http://localhost', (proxy) => {
assert.strictEqual(proxy, 'PROXY myproxy:8132')
done()
})
})
})
})
it('allows bypassing proxy settings', (done) => {
const config = {
proxyRules: 'http=myproxy:80',
proxyBypassRules: '<local>'
}
session.defaultSession.setProxy(config, () => {
session.defaultSession.resolveProxy('http://localhost', (proxy) => {
assert.equal(proxy, 'DIRECT')
customSession.setProxy(config, () => {
customSession.resolveProxy('http://localhost', (proxy) => {
assert.strictEqual(proxy, 'DIRECT')
done()
})
})