mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
use jest for CI
This commit is contained in:
50
test/web/curlUtil.spec.js
Normal file
50
test/web/curlUtil.spec.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const { curlify } = require('../../web/src/common/curlUtil');
|
||||
|
||||
describe('Test the curlify function', () => {
|
||||
it('request with headers', () => {
|
||||
const requestDetail = {
|
||||
method: 'POST',
|
||||
url: 'https://localhost:3001/test',
|
||||
reqHeader: {
|
||||
'via-proxy': 'true',
|
||||
},
|
||||
};
|
||||
const result = 'curl \'https://localhost:3001/test\' -X POST -H \'via-proxy: true\'';
|
||||
expect(curlify(requestDetail)).toBe(result);
|
||||
});
|
||||
|
||||
it('request with JSON body', () => {
|
||||
const requestDetail = {
|
||||
method: 'POST',
|
||||
url: 'https://localhost:3001/test',
|
||||
reqHeader: {
|
||||
'content-type': 'application/json; charset=utf-8',
|
||||
},
|
||||
reqBody: '{"action":1,"method":"test"}',
|
||||
};
|
||||
const result = `curl '${requestDetail.url}' -X POST -H 'content-type: application/json; charset=utf-8' -d '${requestDetail.reqBody}'`;
|
||||
expect(curlify(requestDetail)).toBe(result);
|
||||
});
|
||||
|
||||
it('accpet gzip encoding with compressed flag', () => {
|
||||
const requestDetail = {
|
||||
method: 'GET',
|
||||
url: 'https://localhost:3001/test',
|
||||
reqHeader: {
|
||||
Host: 'localhost',
|
||||
'Accept-Encoding': 'gzip',
|
||||
},
|
||||
};
|
||||
const result = 'curl \'https://localhost:3001/test\' -H \'Host: localhost\' -H \'Accept-Encoding: gzip\' --compressed';
|
||||
expect(curlify(requestDetail)).toBe(result);
|
||||
});
|
||||
|
||||
it('escape url character', () => {
|
||||
const requestDetail = {
|
||||
method: 'GET',
|
||||
url: 'https://localhost:3001/test?a[]=1',
|
||||
};
|
||||
const result = 'curl \'https://localhost:3001/test?a\\[\\]=1\'';
|
||||
expect(curlify(requestDetail)).toBe(result);
|
||||
});
|
||||
});
|
||||
27
test/web/webInterface.spec.js
Normal file
27
test/web/webInterface.spec.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const WebInterface = require('../../lib/webInterface.js');
|
||||
const Recorder = require('../../lib/recorder');
|
||||
const urllib = require('urllib');
|
||||
|
||||
describe('WebInterface server', () => {
|
||||
let webServer = null;
|
||||
const webHost = 'http://127.0.0.1:8002'
|
||||
|
||||
beforeAll(async () => {
|
||||
const recorder = new Recorder();
|
||||
webServer = new WebInterface({
|
||||
webPort: 8002,
|
||||
}, recorder);
|
||||
await webServer.start();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await webServer.close();
|
||||
});
|
||||
|
||||
it('should response qrcode string in /getQrCode', async () => {
|
||||
const response = await urllib.request(`${webHost}/api/getQrCode`);
|
||||
const body = JSON.parse(response.res.data);
|
||||
expect(body.qrImgDom).toMatch('<img src="data:image/');
|
||||
expect(body.url).toBe(`${webHost}/downloadCrt`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user