MCPcopy
hub / github.com/alibaba/anyproxy / testWrapper

Function testWrapper

test/spec_rule/rule_replace_request_protocol_spec.js:15–112  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13testWrapper();
14
15function testWrapper() {
16 describe('Rule replaceRequestProtocol should be working', () => {
17 let proxyServer;
18 let serverInstance;
19
20 beforeAll((done) => {
21 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
22 printLog('Start server for rule_replace_request_protocol');
23
24 serverInstance = new Server();
25
26 proxyServer = ProxyServerUtil.proxyServerWithRule(rule);
27
28 setTimeout(() => {
29 done();
30 }, 2000);
31 });
32
33 afterAll(() => {
34 serverInstance && serverInstance.close();
35 proxyServer && proxyServer.close();
36 printLog('Close server for rule_replace_request_protocol');
37 });
38
39 it('Should replace request protocol in PROXY https request', done => {
40 const url = generateUrl('https', '/test/normal_request1');
41 const httpUrl = url.replace('https', 'http');
42 const token = 'proxy_request1_token_' + Date.now();
43 proxyGet(url, {}, { token })
44 .then(proxyRes => {
45 expect(proxyRes.body).toEqual('body_normal_request1');
46
47 // there should be no https url be requested in proxy, it should be http request
48 expect(serverInstance.getProxyRequestRecord(url)).toBe(null);
49 const httpRecord = serverInstance.getProxyRequestRecord(httpUrl);
50 expect(httpRecord.headers.token).toEqual(token);
51 expect(httpRecord.headers['via-proxy']).toEqual('true');
52 done();
53 })
54 .catch(error => {
55 console.error('Error happened in proxy the https request: ', error);
56 done.fail('error happened in proxy the https request');
57 });
58 });
59
60 it('Should not replace protocol in PROXY http request', done => {
61 const url = generateUrl('http', '/test/normal_request2');
62 const token = 'proxy_request2_token_' + Date.now();
63 proxyGet(url, {}, { token })
64 .then(proxyRes => {
65 expect(proxyRes.body).toEqual('body_normal_request2');
66 const requestRecord = serverInstance.getProxyRequestRecord(url);
67 expect(requestRecord).not.toBe(null);
68 expect(requestRecord.headers.token).toEqual(token);
69 expect(requestRecord.headers['via-proxy']).toEqual('true');
70 done();
71 })
72 .catch(error => {

Calls 5

generateUrlFunction · 0.85
proxyGetFunction · 0.85
directGetFunction · 0.85
printLogFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected