Skip to content

Commit 8eadc41

Browse files
committed
WIP
1 parent 4195519 commit 8eadc41

File tree

8 files changed

+1051
-67
lines changed

8 files changed

+1051
-67
lines changed

package-lock.json

Lines changed: 530 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/devtools-proxy-support/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@
6464
"chai": "^4.3.6",
6565
"depcheck": "^1.4.1",
6666
"duplexpair": "^1.0.2",
67+
"electron": "^31.2.1",
6768
"eslint": "^7.25.0",
6869
"gen-esm-wrapper": "^1.1.0",
6970
"mocha": "^8.4.0",
7071
"nyc": "^15.1.0",
7172
"prettier": "^2.3.2",
7273
"sinon": "^9.2.3",
73-
"typescript": "^5.0.4"
74+
"typescript": "^5.0.4",
75+
"xvfb-maybe": "^0.2.1"
7476
}
7577
}

packages/devtools-proxy-support/src/agent.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('createAgent', function () {
9393
});
9494

9595
context('http proxy', function () {
96-
it('can connect to a http proxy without auth', async function () {
96+
it('can connect to an http proxy without auth', async function () {
9797
const res = await get(
9898
'http://example.com/hello',
9999
createAgent({ proxy: `http://127.0.0.1:${setup.httpProxyPort}` })
@@ -104,7 +104,7 @@ describe('createAgent', function () {
104104
]);
105105
});
106106

107-
it('can connect to a http proxy with successful auth', async function () {
107+
it('can connect to an http proxy with successful auth', async function () {
108108
setup.authHandler = sinon.stub().returns(true);
109109

110110
const res = await get(
@@ -120,7 +120,7 @@ describe('createAgent', function () {
120120
expect(setup.authHandler).to.have.been.calledOnceWith('foo', 'bar');
121121
});
122122

123-
it('fails to connect to a http proxy with unsuccessful auth', async function () {
123+
it('fails to connect to an http proxy with unsuccessful auth', async function () {
124124
setup.authHandler = sinon.stub().returns(false);
125125

126126
const res = await get(
@@ -134,7 +134,7 @@ describe('createAgent', function () {
134134
});
135135

136136
context('https/connect proxy', function () {
137-
it('can connect to a https proxy without auth', async function () {
137+
it('can connect to an https proxy without auth', async function () {
138138
const res = await get(
139139
'https://example.com/hello',
140140
createAgent({ proxy: `http://127.0.0.1:${setup.httpsProxyPort}` })
@@ -145,7 +145,7 @@ describe('createAgent', function () {
145145
]);
146146
});
147147

148-
it('can connect to a https proxy with successful auth', async function () {
148+
it('can connect to an https proxy with successful auth', async function () {
149149
setup.authHandler = sinon.stub().returns(true);
150150

151151
const res = await get(
@@ -161,7 +161,7 @@ describe('createAgent', function () {
161161
expect(setup.authHandler).to.have.been.calledOnceWith('foo', 'bar');
162162
});
163163

164-
it('fails to connect to a https proxy with unsuccessful auth', async function () {
164+
it('fails to connect to an https proxy with unsuccessful auth', async function () {
165165
setup.authHandler = sinon.stub().returns(false);
166166

167167
const res = await get(

packages/devtools-proxy-support/src/fetch.spec.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('createFetch', function () {
1515
});
1616

1717
context('HTTP calls', function () {
18+
let fetch: ReturnType<typeof createFetch>;
1819
let setup: HTTPServerProxyTestSetup;
1920

2021
beforeEach(async function () {
@@ -24,6 +25,7 @@ describe('createFetch', function () {
2425

2526
afterEach(async function () {
2627
await setup.teardown();
28+
fetch?.agent?.destroy?.();
2729
});
2830

2931
it('provides a node-fetch-like HTTP functionality', async function () {
@@ -34,7 +36,7 @@ describe('createFetch', function () {
3436
});
3537

3638
it('makes use of SSH proxy support when instructed to do so', async function () {
37-
const fetch = createFetch({
39+
fetch = createFetch({
3840
proxy: `ssh://[email protected]:${setup.sshProxyPort}`,
3941
});
4042
const response = await fetch(
@@ -49,42 +51,58 @@ describe('createFetch', function () {
4951
srcPort: 0,
5052
},
5153
]);
52-
fetch.agent?.destroy?.();
5354
});
5455

5556
it('makes use of HTTP proxy support when instructed to do so', async function () {
56-
const fetch = createFetch({
57+
fetch = createFetch({
5758
proxy: `http://127.0.0.1:${setup.httpProxyPort}`,
5859
});
5960
const response = await fetch(
6061
`http://localhost:${setup.httpServerPort}/test`
6162
);
6263
expect(await response.text()).to.equal('OK /test');
63-
fetch.agent?.destroy?.();
6464
});
6565

6666
it('makes use of HTTPS proxy support when instructed to do so', async function () {
67-
const fetch = createFetch({
67+
fetch = createFetch({
6868
proxy: `http://127.0.0.1:${setup.httpsProxyPort}`,
6969
ca: setup.tlsOptions.ca,
7070
});
7171
const response = await fetch(
7272
`https://localhost:${setup.httpsServerPort}/test`
7373
);
7474
expect(await response.text()).to.equal('OK /test');
75-
fetch.agent?.destroy?.();
7675
});
7776

7877
it('makes use of Socks5 proxy support when instructed to do so', async function () {
7978
setup.socks5AuthNone();
80-
const fetch = createFetch({
79+
fetch = createFetch({
8180
proxy: `socks5://127.0.0.1:${setup.socks5ProxyPort}`,
8281
});
8382
const response = await fetch(
8483
`http://localhost:${setup.httpServerPort}/test`
8584
);
8685
expect(await response.text()).to.equal('OK /test');
87-
fetch.agent?.destroy?.();
86+
});
87+
88+
it('makes use of PAC-based proxy support when instructed to do so', async function () {
89+
setup.socks5AuthNone();
90+
fetch = createFetch({
91+
proxy: `pac+http://127.0.0.1:${setup.httpServerPort}/pac`,
92+
});
93+
const response = await fetch(
94+
`http://localhost:${setup.httpsServerPort}/test`
95+
);
96+
expect(await response.text()).to.equal('OK /test');
97+
98+
try {
99+
await fetch(`http://pac-invalidproxy/test`);
100+
expect.fail('missed exception');
101+
} catch (err) {
102+
expect(err.message).to.include(
103+
'Failed to establish a socket connection to proxies: ["SOCKS5 127.0.0.1:1"]'
104+
);
105+
}
88106
});
89107
});
90108
});

0 commit comments

Comments
 (0)