forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyServerModule.js
More file actions
92 lines (84 loc) · 2.3 KB
/
proxyServerModule.js
File metadata and controls
92 lines (84 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* test for rule replaceOption rule
*
*/
const ip = require('ip');
const AnyProxy = require('../../proxy');
const { proxyGet, directGet } = require('../util/HttpUtil.js');
const Server = require('../server/server.js');
const OUT_BOUND_IP = ip.address();
describe('AnyProxy.proxyServer basic test', () => {
it('should successfully start a proxy server', done => {
const options = {
port: 8001,
rule: null,
webInterface: {
enable: true,
webPort: 8002
},
throttle: 10000,
forceProxyHttps: false,
silent: false
};
const proxyServer = new AnyProxy.ProxyServer(options);
proxyServer.on('ready', () => {
proxyServer.close();
done();
});
proxyServer.on('error', done.fail);
proxyServer.start();
});
});
describe('AnyProxy.proxyServer high order test', () => {
let proxyServer;
let serverInstance;
beforeAll(done => {
// jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
serverInstance = new Server();
const options = {
port: 8001,
rule: null,
webInterface: {
enable: true,
webPort: 8002,
},
throttle: 10000,
forceProxyHttps: false,
silent: false
};
proxyServer = new AnyProxy.ProxyServer(options);
proxyServer.on('ready', done);
proxyServer.start();
});
afterAll(() => {
proxyServer && proxyServer.close();
serverInstance && serverInstance.close();
});
it('should work as expected for domain host', done => {
// test if proxy server works
proxyGet('https://www.tmall.com', {}, {})
.then(res => {
expect(res && res.statusCode && res.statusCode === 200 && res.body.length > 300).toBe(true);
done();
})
.catch(done)
});
it('should work as expected for ip host', done => {
// test if proxy server works
proxyGet(`https://${OUT_BOUND_IP}:3001/test`, {}, {})
.then(res => {
expect(res && res.statusCode && res.statusCode === 200).toBe(true);
done();
})
.catch(done)
});
it('should start webinterface correctly', done => {
// test web interface
directGet('http://127.0.0.1:8002', {}, {})
.then(res => {
expect(res && res.statusCode && res.statusCode === 200 && res.body.length > 300).toBe(true);
done();
})
.catch(done)
});
});