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

Function testWrapper

test/spec_rule/rule_replace_request_data_spec.js:15–120  ·  view source on GitHub ↗
(protocol)

Source from the content-addressed store, hash-verified

13testWrapper('https');
14
15function testWrapper(protocol) {
16 describe('Rule replaceRequestData should be working in :' + protocol, () => {
17 let proxyServer;
18 let serverInstance;
19
20 beforeAll((done) => {
21 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
22 printLog('Start server for rule_replace_request_data_spec');
23
24 serverInstance = new Server();
25 proxyServer = ProxyServerUtil.proxyServerWithRule(rule);
26
27 setTimeout(() => {
28 done();
29 }, 2000);
30 });
31
32 afterAll(() => {
33 serverInstance && serverInstance.close();
34 proxyServer && proxyServer.close();
35 printLog('Close server for rule_replace_request_data_spec');
36 });
37
38 it('Should replace the request data in proxy if the assertion is true', done => {
39 const url = generateUrl(protocol, '/test/getuser');
40 const userName = 'username_test';
41 const param = {
42 username: userName
43 };
44
45 proxyPost(url, param)
46 .then(proxyRes => {
47 expect(proxyRes.statusCode).toEqual(200);
48 expect(proxyRes.body).toEqual('body_post_getuser');
49 const proxyRequest = serverInstance.getProxyRequestRecord(url);
50 const proxyReqBodyObj = JSON.parse(proxyRequest.body.toString());
51
52 expect(isViaProxy(proxyRequest)).toBe(true);
53
54 expect(proxyReqBodyObj.username).toEqual(userName);
55 expect(proxyReqBodyObj.authToken).toEqual('auth_token_inrule');
56
57 directPost(url, param)
58 .then(directRes => {
59 expect(directRes.statusCode).toEqual(200);
60 expect(directRes.body).toEqual(proxyRes.body);
61
62
63 const directRequest = serverInstance.getRequestRecord(url);
64 const directReqBodyObj = JSON.parse(directRequest.body.toString());
65 expect(isViaProxy(directRequest)).toBe(false);
66
67 expect(directReqBodyObj.username).toEqual(userName);
68 expect(directReqBodyObj.authToken).toBeUndefined();
69 done();
70 })
71 .catch(error => {
72 console.error('error happened in direct post: ', error);

Calls 7

generateUrlFunction · 0.85
proxyPostFunction · 0.85
isViaProxyFunction · 0.85
directPostFunction · 0.85
isObjectEqualFunction · 0.85
printLogFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected