mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-19 15:44:22 +00:00
fix: replace upload fixture image.png with a smaller upload.txt (#563)
This commit is contained in:
parent
5a1af37614
commit
78858bfb94
File diff suppressed because one or more lines are too long
@ -63,7 +63,7 @@ function doProxyWebSocket(url, headers = {}) {
|
|||||||
expect(body.data).toMatchSnapshot('data');
|
expect(body.data).toMatchSnapshot('data');
|
||||||
return body;
|
return body;
|
||||||
};
|
};
|
||||||
|
|
||||||
it('GET', async () => {
|
it('GET', async () => {
|
||||||
const url = `${protocol}://httpbin.org/get`;
|
const url = `${protocol}://httpbin.org/get`;
|
||||||
const getParam = {
|
const getParam = {
|
||||||
@ -71,25 +71,25 @@ function doProxyWebSocket(url, headers = {}) {
|
|||||||
};
|
};
|
||||||
await basicProxyRequest(proxyHost, 'GET', url, {}, getParam).then(assertProxyRes);
|
await basicProxyRequest(proxyHost, 'GET', url, {}, getParam).then(assertProxyRes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('POST body and header', async () => {
|
it('POST body and header', async () => {
|
||||||
const url = `${protocol}://httpbin.org/post`;
|
const url = `${protocol}://httpbin.org/post`;
|
||||||
const payloadStream = fs.createReadStream(path.resolve(__dirname, './fixtures/image.png'));
|
const payloadStream = fs.createReadStream(path.resolve(__dirname, './fixtures/upload.txt'));
|
||||||
|
|
||||||
const postHeaders = {
|
const postHeaders = {
|
||||||
anyproxy_header: 'header_value',
|
anyproxy_header: 'header_value',
|
||||||
};
|
};
|
||||||
|
|
||||||
const body = await basicProxyRequest(proxyHost, 'POST', url, postHeaders, {}, payloadStream).then(assertProxyRes);
|
const body = await basicProxyRequest(proxyHost, 'POST', url, postHeaders, {}, payloadStream).then(assertProxyRes);
|
||||||
expect(body.headers['Anyproxy-Header']).toBe(postHeaders.anyproxy_header);
|
expect(body.headers['Anyproxy-Header']).toBe(postHeaders.anyproxy_header);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PUT', async () => {
|
it('PUT', async () => {
|
||||||
const url = `${protocol}://httpbin.org/put`;
|
const url = `${protocol}://httpbin.org/put`;
|
||||||
const payloadStream = fs.createReadStream(path.resolve(__dirname, './fixtures/image.png'));
|
const payloadStream = fs.createReadStream(path.resolve(__dirname, './fixtures/upload.txt'));
|
||||||
await basicProxyRequest(proxyHost, 'PUT', url, {}, undefined, payloadStream).then(assertProxyRes);
|
await basicProxyRequest(proxyHost, 'PUT', url, {}, undefined, payloadStream).then(assertProxyRes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('DELETE', async () => {
|
it('DELETE', async () => {
|
||||||
const url = `${protocol}://httpbin.org/delete`;
|
const url = `${protocol}://httpbin.org/delete`;
|
||||||
const param = {
|
const param = {
|
||||||
@ -97,7 +97,7 @@ function doProxyWebSocket(url, headers = {}) {
|
|||||||
};
|
};
|
||||||
await basicProxyRequest(proxyHost, 'DELETE', url, {}, param).then(assertProxyRes);
|
await basicProxyRequest(proxyHost, 'DELETE', url, {}, param).then(assertProxyRes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PATCH', async () => {
|
it('PATCH', async () => {
|
||||||
const url = `${protocol}://httpbin.org/patch`;
|
const url = `${protocol}://httpbin.org/patch`;
|
||||||
await basicProxyRequest(proxyHost, 'PATCH', url).then(assertProxyRes);
|
await basicProxyRequest(proxyHost, 'PATCH', url).then(assertProxyRes);
|
||||||
@ -111,7 +111,7 @@ function doProxyWebSocket(url, headers = {}) {
|
|||||||
ws.on('open', () => {
|
ws.on('open', () => {
|
||||||
ws.send(wsMsg);
|
ws.send(wsMsg);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('message', (msg) => {
|
ws.on('message', (msg) => {
|
||||||
expect(msg).toBe(wsMsg);
|
expect(msg).toBe(wsMsg);
|
||||||
ws.close();
|
ws.close();
|
||||||
|
BIN
test/fixtures/image.png
vendored
BIN
test/fixtures/image.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 7.0 KiB |
1
test/fixtures/upload.txt
vendored
Normal file
1
test/fixtures/upload.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
@ -34,11 +34,11 @@ describe('Rule beforeDealHttpsRequest', () => {
|
|||||||
});
|
});
|
||||||
it('Should replace the https request body', async () => {
|
it('Should replace the https request body', async () => {
|
||||||
const url = 'https://httpbin.org/put';
|
const url = 'https://httpbin.org/put';
|
||||||
const payloadStream = fs.createReadStream(path.resolve(__dirname, '../fixtures/image.png'));
|
const payloadStream = fs.createReadStream(path.resolve(__dirname, '../fixtures/upload.txt'));
|
||||||
const postHeaders = {
|
const postHeaders = {
|
||||||
anyproxy_header: 'header_value',
|
anyproxy_header: 'header_value',
|
||||||
};
|
};
|
||||||
|
|
||||||
await basicProxyRequest(proxyHost, 'PUT', url, postHeaders, {}, payloadStream).then((result) => {
|
await basicProxyRequest(proxyHost, 'PUT', url, postHeaders, {}, payloadStream).then((result) => {
|
||||||
const proxyRes = result.response;
|
const proxyRes = result.response;
|
||||||
const body = JSON.parse(result.body);
|
const body = JSON.parse(result.body);
|
||||||
|
@ -58,11 +58,11 @@ describe('Rule replaceRequestData', () => {
|
|||||||
|
|
||||||
it('should replace the request data in proxy if the assertion is true', async () => {
|
it('should replace the request data in proxy if the assertion is true', async () => {
|
||||||
const url = 'http://httpbin.org/post';
|
const url = 'http://httpbin.org/post';
|
||||||
const payloadStream = fs.createReadStream(path.resolve(__dirname, '../fixtures/image.png'));
|
const payloadStream = fs.createReadStream(path.resolve(__dirname, '../fixtures/upload.txt'));
|
||||||
const postHeaders = {
|
const postHeaders = {
|
||||||
anyproxy_header: 'header_value',
|
anyproxy_header: 'header_value',
|
||||||
};
|
};
|
||||||
|
|
||||||
await basicProxyRequest(proxyHost, 'POST', url, postHeaders, {}, payloadStream).then((result) => {
|
await basicProxyRequest(proxyHost, 'POST', url, postHeaders, {}, payloadStream).then((result) => {
|
||||||
const proxyRes = result.response;
|
const proxyRes = result.response;
|
||||||
const body = JSON.parse(result.body);
|
const body = JSON.parse(result.body);
|
||||||
@ -73,7 +73,7 @@ describe('Rule replaceRequestData', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should respond content specified in rule', async () => {
|
it('should respond content specified in rule', async () => {
|
||||||
const url = 'http://httpbin.org/status/302';
|
const url = 'http://httpbin.org/status/302';
|
||||||
await basicProxyRequest(proxyHost, 'GET', url).then((result) => {
|
await basicProxyRequest(proxyHost, 'GET', url).then((result) => {
|
||||||
const proxyRes = result.response;
|
const proxyRes = result.response;
|
||||||
const body = result.body;
|
const body = result.body;
|
||||||
@ -84,7 +84,7 @@ describe('Rule replaceRequestData', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should replace protocol and url', async () => {
|
it('should replace protocol and url', async () => {
|
||||||
const url = 'http://domain_not_exists.anyproxy.io/should_be_replaced';
|
const url = 'http://domain_not_exists.anyproxy.io/should_be_replaced';
|
||||||
await basicProxyRequest(proxyHost, 'GET', url).then((result) => {
|
await basicProxyRequest(proxyHost, 'GET', url).then((result) => {
|
||||||
const proxyRes = result.response;
|
const proxyRes = result.response;
|
||||||
expect(proxyRes.statusCode).toBe(302);
|
expect(proxyRes.statusCode).toBe(302);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user