mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Decode file name on upload value lists and fix bug with removing value list (#111838)
* Decode fileName when creating a list * Return wait_for for delete list item * Return back import * Update x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts Co-authored-by: Ryland Herrick <ryalnd@gmail.com> * Use i18n for message Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
This commit is contained in:
parent
d38d756153
commit
43ea2930cc
4 changed files with 26 additions and 6 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
import { createListIfItDoesNotExist } from '../lists/create_list_if_it_does_not_exist';
|
||||
|
||||
import {
|
||||
LinesResult,
|
||||
|
@ -23,6 +24,10 @@ jest.mock('./create_list_items_bulk', () => ({
|
|||
createListItemsBulk: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../lists/create_list_if_it_does_not_exist', () => ({
|
||||
createListIfItDoesNotExist: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('write_lines_to_bulk_list_items', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -61,6 +66,17 @@ describe('write_lines_to_bulk_list_items', () => {
|
|||
expect.objectContaining({ value: ['127.0.0.1', '127.0.0.2'] })
|
||||
);
|
||||
});
|
||||
|
||||
it('creates a list with a decoded file name', async () => {
|
||||
const options = getImportListItemsToStreamOptionsMock();
|
||||
const promise = importListItemsToStream({ ...options, listId: undefined });
|
||||
options.stream.push(`--\nContent-Disposition: attachment; filename="%22Filename%22.txt"`);
|
||||
options.stream.push(null);
|
||||
await promise;
|
||||
expect(createListIfItDoesNotExist).toBeCalledWith(
|
||||
expect.objectContaining({ id: `"Filename".txt`, name: `"Filename".txt` })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('writeBufferToItems', () => {
|
||||
|
|
|
@ -17,6 +17,7 @@ import type {
|
|||
Type,
|
||||
} from '@kbn/securitysolution-io-ts-list-types';
|
||||
import { Version } from '@kbn/securitysolution-io-ts-types';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { createListIfItDoesNotExist } from '../lists/create_list_if_it_does_not_exist';
|
||||
import { ConfigType } from '../../config';
|
||||
|
@ -59,17 +60,20 @@ export const importListItemsToStream = ({
|
|||
let list: ListSchema | null = null;
|
||||
readBuffer.on('fileName', async (fileNameEmitted: string) => {
|
||||
readBuffer.pause();
|
||||
fileName = fileNameEmitted;
|
||||
fileName = decodeURIComponent(fileNameEmitted);
|
||||
if (listId == null) {
|
||||
list = await createListIfItDoesNotExist({
|
||||
description: `File uploaded from file system of ${fileNameEmitted}`,
|
||||
description: i18n.translate('xpack.lists.services.items.fileUploadFromFileSystem', {
|
||||
defaultMessage: 'File uploaded from file system of {fileName}',
|
||||
values: { fileName },
|
||||
}),
|
||||
deserializer,
|
||||
esClient,
|
||||
id: fileNameEmitted,
|
||||
id: fileName,
|
||||
immutable: false,
|
||||
listIndex,
|
||||
meta,
|
||||
name: fileNameEmitted,
|
||||
name: fileName,
|
||||
serializer,
|
||||
type,
|
||||
user,
|
||||
|
|
|
@ -61,7 +61,7 @@ describe('delete_list', () => {
|
|||
const deleteQuery = {
|
||||
id: LIST_ID,
|
||||
index: LIST_INDEX,
|
||||
refresh: false,
|
||||
refresh: 'wait_for',
|
||||
};
|
||||
expect(options.esClient.delete).toHaveBeenNthCalledWith(1, deleteQuery);
|
||||
});
|
||||
|
|
|
@ -42,7 +42,7 @@ export const deleteList = async ({
|
|||
await esClient.delete({
|
||||
id,
|
||||
index: listIndex,
|
||||
refresh: false,
|
||||
refresh: 'wait_for',
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue