diff --git a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts index c3856fde9b2c3..78098fde59827 100644 --- a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts +++ b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts @@ -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', () => { diff --git a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts index 89a6bdbc77878..edd78e350054d 100644 --- a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts +++ b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts @@ -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, diff --git a/x-pack/plugins/lists/server/services/lists/delete_list.test.ts b/x-pack/plugins/lists/server/services/lists/delete_list.test.ts index 9ceecbc299bab..f379fd977f51a 100644 --- a/x-pack/plugins/lists/server/services/lists/delete_list.test.ts +++ b/x-pack/plugins/lists/server/services/lists/delete_list.test.ts @@ -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); }); diff --git a/x-pack/plugins/lists/server/services/lists/delete_list.ts b/x-pack/plugins/lists/server/services/lists/delete_list.ts index b9a55e107ab76..517723fc227de 100644 --- a/x-pack/plugins/lists/server/services/lists/delete_list.ts +++ b/x-pack/plugins/lists/server/services/lists/delete_list.ts @@ -42,7 +42,7 @@ export const deleteList = async ({ await esClient.delete({ id, index: listIndex, - refresh: false, + refresh: 'wait_for', }); return list; }