Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Decode file name on upload value lists and fix bug with removing value list (#111838) #112056

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/server/services/lists/delete_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const deleteList = async ({
await esClient.delete({
id,
index: listIndex,
refresh: false,
refresh: 'wait_for',
});
return list;
}
Expand Down