Skip to content

Commit b6f9c0f

Browse files
committed
test: add tests
1 parent 61ada86 commit b6f9c0f

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

test/test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var url = require('url');
7+
var https = require('https');
8+
var assert = require('assert');
9+
var HttpsProxyAgent = require('../');
10+
11+
describe('HttpsProxyAgent', function () {
12+
13+
this.slow(5000);
14+
this.timeout(10000);
15+
16+
var link = process.env.LINK || 'https://graph.facebook.com/tootallnate';
17+
18+
it('should throw an Error if no "proxy" is given', function () {
19+
assert.throws(function () {
20+
new HttpsProxyAgent();
21+
});
22+
});
23+
24+
it('should work over an HTTP proxy', function (done) {
25+
var proxy = process.env.HTTP_PROXY || process.env.http_proxy || 'http://10.1.10.200:3128';
26+
var agent = new HttpsProxyAgent(proxy);
27+
28+
var opts = url.parse(link);
29+
opts.agent = agent;
30+
31+
https.get(opts, function (res) {
32+
var data = '';
33+
res.setEncoding('utf8');
34+
res.on('data', function (b) {
35+
data += b;
36+
});
37+
res.on('end', function () {
38+
data = JSON.parse(data);
39+
assert.equal('tootallnate', data.username);
40+
done();
41+
});
42+
});
43+
});
44+
45+
it('should work over an HTTPS proxy', function (done) {
46+
var proxy = process.env.HTTPS_PROXY || process.env.https_proxy || 'https://10.1.10.200:3130';
47+
proxy = url.parse(proxy);
48+
proxy.rejectUnauthorized = false;
49+
var agent = new HttpsProxyAgent(proxy);
50+
51+
var opts = url.parse(link);
52+
opts.agent = agent;
53+
opts.rejectUnauthorized = false;
54+
55+
https.get(opts, function (res) {
56+
var data = '';
57+
res.setEncoding('utf8');
58+
res.on('data', function (b) {
59+
data += b;
60+
});
61+
res.on('end', function () {
62+
data = JSON.parse(data);
63+
assert.equal('tootallnate', data.username);
64+
done();
65+
});
66+
});
67+
});
68+
69+
});

0 commit comments

Comments
 (0)