Skip to content

Commit e2d8773

Browse files
kibanamachinenkhristininrylnd
authored
Decode file name on upload value lists and fix bug with removing value list (#111838) (#112056)
* 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> Co-authored-by: Khristinin Nikita <nikita.khristinin@elastic.co> Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
1 parent bb0e065 commit e2d8773

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
9+
import { createListIfItDoesNotExist } from '../lists/create_list_if_it_does_not_exist';
910

1011
import {
1112
LinesResult,
@@ -23,6 +24,10 @@ jest.mock('./create_list_items_bulk', () => ({
2324
createListItemsBulk: jest.fn(),
2425
}));
2526

27+
jest.mock('../lists/create_list_if_it_does_not_exist', () => ({
28+
createListIfItDoesNotExist: jest.fn(),
29+
}));
30+
2631
describe('write_lines_to_bulk_list_items', () => {
2732
beforeEach(() => {
2833
jest.clearAllMocks();
@@ -61,6 +66,17 @@ describe('write_lines_to_bulk_list_items', () => {
6166
expect.objectContaining({ value: ['127.0.0.1', '127.0.0.2'] })
6267
);
6368
});
69+
70+
it('creates a list with a decoded file name', async () => {
71+
const options = getImportListItemsToStreamOptionsMock();
72+
const promise = importListItemsToStream({ ...options, listId: undefined });
73+
options.stream.push(`--\nContent-Disposition: attachment; filename="%22Filename%22.txt"`);
74+
options.stream.push(null);
75+
await promise;
76+
expect(createListIfItDoesNotExist).toBeCalledWith(
77+
expect.objectContaining({ id: `"Filename".txt`, name: `"Filename".txt` })
78+
);
79+
});
6480
});
6581

6682
describe('writeBufferToItems', () => {

x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
Type,
1818
} from '@kbn/securitysolution-io-ts-list-types';
1919
import { Version } from '@kbn/securitysolution-io-ts-types';
20+
import { i18n } from '@kbn/i18n';
2021

2122
import { createListIfItDoesNotExist } from '../lists/create_list_if_it_does_not_exist';
2223
import { ConfigType } from '../../config';
@@ -59,17 +60,20 @@ export const importListItemsToStream = ({
5960
let list: ListSchema | null = null;
6061
readBuffer.on('fileName', async (fileNameEmitted: string) => {
6162
readBuffer.pause();
62-
fileName = fileNameEmitted;
63+
fileName = decodeURIComponent(fileNameEmitted);
6364
if (listId == null) {
6465
list = await createListIfItDoesNotExist({
65-
description: `File uploaded from file system of ${fileNameEmitted}`,
66+
description: i18n.translate('xpack.lists.services.items.fileUploadFromFileSystem', {
67+
defaultMessage: 'File uploaded from file system of {fileName}',
68+
values: { fileName },
69+
}),
6670
deserializer,
6771
esClient,
68-
id: fileNameEmitted,
72+
id: fileName,
6973
immutable: false,
7074
listIndex,
7175
meta,
72-
name: fileNameEmitted,
76+
name: fileName,
7377
serializer,
7478
type,
7579
user,

x-pack/plugins/lists/server/services/lists/delete_list.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('delete_list', () => {
6161
const deleteQuery = {
6262
id: LIST_ID,
6363
index: LIST_INDEX,
64-
refresh: false,
64+
refresh: 'wait_for',
6565
};
6666
expect(options.esClient.delete).toHaveBeenNthCalledWith(1, deleteQuery);
6767
});

x-pack/plugins/lists/server/services/lists/delete_list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const deleteList = async ({
4242
await esClient.delete({
4343
id,
4444
index: listIndex,
45-
refresh: false,
45+
refresh: 'wait_for',
4646
});
4747
return list;
4848
}

0 commit comments

Comments
 (0)