Skip to content

Commit f83fb14

Browse files
authored
fix(proxy): if the proxy is http, edit the request url (#366)
- clean up - move int and proxy test to async / await. closes #359
1 parent e3a3a6c commit f83fb14

File tree

4 files changed

+62
-69
lines changed

4 files changed

+62
-69
lines changed

lib/provider/chromedriver.spec-proxy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('chromedriver', () => {
4949
done();
5050
}
5151
const chromeDriver = new ChromeDriver({
52-
ignoreSSL: true,
5352
osType: 'Darwin',
5453
osArch: 'x64',
5554
outDir: tmpDir,

lib/provider/utils/http_utils.spec-int.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const fooArrayUrl = httpBaseUrl + '/spec/support/files/foo_array.json';
1919
const fooXmlUrl = httpBaseUrl + '/spec/support/files/foo.xml';
2020
const barZipSize = 171;
2121

22-
describe('http_utils', () => {
23-
const origTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
24-
let proc: childProcess.ChildProcess;
22+
const origTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
23+
let proc: childProcess.ChildProcess;
2524

25+
describe('http_utils', () => {
26+
2627
beforeAll(() => {
2728
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
2829
});
@@ -41,9 +42,6 @@ describe('http_utils', () => {
4142

4243
try {
4344
fs.mkdirSync(tmpDir);
44-
} catch (err) {
45-
}
46-
try {
4745
fs.unlinkSync(fileName);
4846
} catch (err) {
4947
}
@@ -63,30 +61,27 @@ describe('http_utils', () => {
6361
});
6462

6563
describe('requestBinary', () => {
66-
it('should download the file if no file exists or ' +
67-
'the content lenght is different',
68-
(done) => {
69-
requestBinary(binaryUrl, {fileName, fileSize: 0})
70-
.then((result) => {
71-
expect(result).toBeTruthy();
72-
expect(fs.statSync(fileName).size).toBe(barZipSize);
73-
done();
74-
})
75-
.catch(err => {
76-
done.fail(err);
77-
});
78-
});
64+
it('should download the file if no file exists or the content lenght ' +
65+
'is different', async () => {
66+
try {
67+
const result = await requestBinary(
68+
binaryUrl, {fileName, fileSize: 0});
69+
expect(result).toBeTruthy();
70+
expect(fs.statSync(fileName).size).toBe(barZipSize);
71+
} catch (err) {
72+
fail(err);
73+
}
74+
});
7975

80-
it('should not download the file if the file exists', (done) => {
81-
requestBinary(binaryUrl, {fileName, fileSize: barZipSize})
82-
.then((result) => {
83-
expect(result).toBeFalsy();
84-
expect(fs.statSync(fileName).size).toBe(barZipSize);
85-
done();
86-
})
87-
.catch(err => {
88-
done.fail(err);
89-
});
76+
it('should not download the file if the file exists', async () => {
77+
try {
78+
const result = await requestBinary(
79+
binaryUrl, {fileName, fileSize: barZipSize});
80+
expect(result).toBeFalsy();
81+
expect(fs.statSync(fileName).size).toBe(barZipSize);
82+
} catch (err) {
83+
fail(err);
84+
}
9085
});
9186
});
9287

lib/provider/utils/http_utils.spec-proxy.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ log.setLevel('debug');
1414

1515
const tmpDir = path.resolve(os.tmpdir(), 'test');
1616
const fileName = path.resolve(tmpDir, 'bar.zip');
17+
const ignoreSSL = true;
1718
const binaryUrl = proxyBaseUrl + '/spec/support/files/bar.zip';
1819
const fooJsonUrl = proxyBaseUrl + '/spec/support/files/foo_json.json';
1920
const fooArrayUrl = proxyBaseUrl + '/spec/support/files/foo_array.json';
@@ -22,31 +23,29 @@ const barZipSize = 171;
2223
const headers = {
2324
'host': httpBaseUrl
2425
};
26+
const origTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
27+
let httpProc: childProcess.ChildProcess;
28+
let proxyProc: childProcess.ChildProcess;
2529

26-
describe('binary_utils', () => {
27-
const origTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
28-
let httpProc: childProcess.ChildProcess;
29-
let proxyProc: childProcess.ChildProcess;
30-
31-
beforeAll((done) => {
30+
describe('binary_utils', () => {
31+
beforeAll(async () => {
3232
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
3333
httpProc = spawnProcess('node', ['dist/spec/server/http_server.js']);
3434
log.debug('http-server: ' + httpProc.pid);
3535
proxyProc = spawnProcess('node', ['dist/spec/server/proxy_server.js']);
3636
log.debug('proxy-server: ' + proxyProc.pid);
37-
setTimeout(done, 3000);
37+
await new Promise(resolve => {
38+
setTimeout(resolve, 3000);
39+
});
3840

3941
try {
4042
fs.mkdirSync(tmpDir);
41-
} catch (err) {
42-
}
43-
try {
4443
fs.unlinkSync(fileName);
4544
} catch (err) {
4645
}
4746
});
4847

49-
afterAll((done) => {
48+
afterAll(async () => {
5049
try {
5150
fs.unlinkSync(fileName);
5251
fs.rmdirSync(tmpDir);
@@ -55,48 +54,48 @@ describe('binary_utils', () => {
5554

5655
process.kill(httpProc.pid);
5756
process.kill(proxyProc.pid);
58-
setTimeout(done, 5000);
57+
await new Promise(resolve => {
58+
setTimeout(resolve, 5000);
59+
});
5960
jasmine.DEFAULT_TIMEOUT_INTERVAL = origTimeout;
6061
});
6162

6263
describe('requestBinary', () => {
63-
it('should download the file if no file exists or ' +
64-
'the content lenght is different',
65-
(done) => {
66-
requestBinary(binaryUrl, {fileName, fileSize: 0, headers})
67-
.then((result) => {
68-
expect(result).toBeTruthy();
69-
expect(fs.statSync(fileName).size).toBe(barZipSize);
70-
done();
71-
})
72-
.catch(err => {
73-
done.fail(err);
74-
});
75-
});
64+
it('should download the file if no file exists or the content lenght ' +
65+
'is different', async () => {
66+
try {
67+
const result = await requestBinary(
68+
binaryUrl, {fileName, fileSize: 0, headers, ignoreSSL});
69+
expect(result).toBeTruthy();
70+
expect(fs.statSync(fileName).size).toBe(barZipSize);
71+
} catch (err) {
72+
fail(err);
73+
}
74+
});
7675

77-
it('should not download the file if the file exists', (done) => {
78-
requestBinary(binaryUrl, {fileName, fileSize: barZipSize, headers})
79-
.then((result) => {
80-
expect(result).toBeFalsy();
81-
expect(fs.statSync(fileName).size).toBe(barZipSize);
82-
done();
83-
})
84-
.catch(err => {
85-
done.fail(err);
86-
});
76+
it('should not download the file if the file exists', async () => {
77+
try {
78+
const result = await requestBinary(
79+
binaryUrl, {fileName, fileSize: barZipSize, headers,
80+
ignoreSSL});
81+
expect(result).toBeFalsy();
82+
expect(fs.statSync(fileName).size).toBe(barZipSize);
83+
} catch (err) {
84+
fail(err);
85+
}
8786
});
8887
});
8988

9089
describe('requestBody', () => {
9190
it('should download a json object file', async () => {
92-
const foo = await requestBody(fooJsonUrl, {headers});
91+
const foo = await requestBody(fooJsonUrl, {headers, ignoreSSL});
9392
const fooJson = JSON.parse(foo);
9493
expect(fooJson['foo']).toBe('abc');
9594
expect(fooJson['bar']).toBe(123);
9695
});
9796

9897
it('should download a json array file', async () => {
99-
const foo = await requestBody(fooArrayUrl, {headers});
98+
const foo = await requestBody(fooArrayUrl, {headers, ignoreSSL});
10099
const fooJson = JSON.parse(foo);
101100
expect(fooJson.length).toBe(3);
102101
expect(fooJson[0]['foo']).toBe('abc');
@@ -105,7 +104,7 @@ describe('binary_utils', () => {
105104
});
106105

107106
it('should get the xml file', async () => {
108-
const text = await requestBody(fooXmlUrl, {headers});
107+
const text = await requestBody(fooXmlUrl, {headers, ignoreSSL});
109108
expect(text.length).toBeGreaterThan(0);
110109
});
111110
});

lib/provider/utils/http_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function optionsProxy(
8282
optProxy: string): RequestOptionsValue {
8383
if (optProxy) {
8484
options.proxy = resolveProxy(requestUrl, optProxy);
85-
if (url.parse(requestUrl).protocol === 'https:') {
85+
if (url.parse(options.proxy).protocol === 'http:') {
8686
options.url = requestUrl.replace('https:', 'http:');
8787
}
8888
}

0 commit comments

Comments
 (0)