-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Adding files configuration fields (#154013)
Fixes: #151935 This PR allows the mime types and max file size for the files functionality within cases to be configured through the kibana.yml. We set the defaults maxSize to be 100 mb and if it is not set by the user we also restrict images to be 10 mb. If the `maxSize` is set by the user we use it for all mime types including images (or whatever the user has specified in `allowedMimeTypes`). The file service changes are just mocks to help with testing some of the configuration options. New fields ``` { files: { allowedMimeTypes: string[] maxSize: positive number (minimum 0) <-- exposed to the browser } } ``` ## Release Notes Cases added two configuration options to allow users to control which files mime types are allowed to be attached to cases and the approved max size of a file being upload. `xpack.cases.files.allowedMimeTypes` - An array of strings representing the allowed mime types to be attached to a case. `xpack.cases.files.maxSize` - A number representing the file size limit for files being attached to a case (in bytes).
- Loading branch information
1 parent
210a7eb
commit 234d48d
Showing
18 changed files
with
1,065 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { MAX_FILE_SIZE } from '../../common/constants'; | ||
import { createMockFilesSetup } from '@kbn/files-plugin/public/mocks'; | ||
import { registerCaseFileKinds } from '.'; | ||
import type { FilesConfig } from './types'; | ||
|
||
describe('ui files index', () => { | ||
describe('registerCaseFileKinds', () => { | ||
const mockFilesSetup = createMockFilesSetup(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('allowedMimeTypes', () => { | ||
const config: FilesConfig = { | ||
allowedMimeTypes: ['abc'], | ||
maxSize: undefined, | ||
}; | ||
|
||
beforeEach(() => { | ||
registerCaseFileKinds(config, mockFilesSetup); | ||
}); | ||
|
||
it('sets cases allowed mime types to abc', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[0][0].allowedMimeTypes).toEqual(['abc']); | ||
}); | ||
|
||
it('sets observability allowed mime types to abc', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[1][0].allowedMimeTypes).toEqual(['abc']); | ||
}); | ||
|
||
it('sets securitySolution allowed mime types to 100 mb', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[2][0].allowedMimeTypes).toEqual(['abc']); | ||
}); | ||
}); | ||
|
||
describe('max file size', () => { | ||
describe('default max file size', () => { | ||
const config: FilesConfig = { | ||
allowedMimeTypes: [], | ||
maxSize: undefined, | ||
}; | ||
|
||
beforeEach(() => { | ||
registerCaseFileKinds(config, mockFilesSetup); | ||
}); | ||
|
||
it('sets cases max file size to 100 mb', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[0][0].maxSizeBytes).toEqual( | ||
MAX_FILE_SIZE | ||
); | ||
}); | ||
|
||
it('sets observability max file size to 100 mb', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[1][0].maxSizeBytes).toEqual( | ||
MAX_FILE_SIZE | ||
); | ||
}); | ||
|
||
it('sets securitySolution max file size to 100 mb', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[2][0].maxSizeBytes).toEqual( | ||
MAX_FILE_SIZE | ||
); | ||
}); | ||
}); | ||
|
||
describe('custom file size', () => { | ||
const config: FilesConfig = { | ||
allowedMimeTypes: [], | ||
maxSize: 5, | ||
}; | ||
|
||
beforeEach(() => { | ||
registerCaseFileKinds(config, mockFilesSetup); | ||
}); | ||
|
||
it('sets cases max file size to 5', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[0][0].maxSizeBytes).toEqual(5); | ||
}); | ||
|
||
it('sets observability max file size to 5', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[1][0].maxSizeBytes).toEqual(5); | ||
}); | ||
|
||
it('sets securitySolution max file size to 5', () => { | ||
expect(mockFilesSetup.registerFileKind.mock.calls[2][0].maxSizeBytes).toEqual(5); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FileKindBrowser } from '@kbn/shared-ux-file-types'; | ||
import type { Owner } from '../../common/constants/types'; | ||
import type { CasesUiConfigType } from '../containers/types'; | ||
|
||
export type FilesConfig = CasesUiConfigType['files']; | ||
|
||
export type CaseFileKinds = Map<Owner, FileKindBrowser>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ConfigSchema } from './config'; | ||
|
||
describe('config validation', () => { | ||
describe('defaults', () => { | ||
it('sets the defaults correctly', () => { | ||
expect(ConfigSchema.validate({})).toMatchInlineSnapshot(` | ||
Object { | ||
"files": Object { | ||
"allowedMimeTypes": Array [ | ||
"image/aces", | ||
"image/apng", | ||
"image/avci", | ||
"image/avcs", | ||
"image/avif", | ||
"image/bmp", | ||
"image/cgm", | ||
"image/dicom-rle", | ||
"image/dpx", | ||
"image/emf", | ||
"image/example", | ||
"image/fits", | ||
"image/g3fax", | ||
"image/heic", | ||
"image/heic-sequence", | ||
"image/heif", | ||
"image/heif-sequence", | ||
"image/hej2k", | ||
"image/hsj2", | ||
"image/jls", | ||
"image/jp2", | ||
"image/jpeg", | ||
"image/jph", | ||
"image/jphc", | ||
"image/jpm", | ||
"image/jpx", | ||
"image/jxr", | ||
"image/jxrA", | ||
"image/jxrS", | ||
"image/jxs", | ||
"image/jxsc", | ||
"image/jxsi", | ||
"image/jxss", | ||
"image/ktx", | ||
"image/ktx2", | ||
"image/naplps", | ||
"image/png", | ||
"image/prs.btif", | ||
"image/prs.pti", | ||
"image/pwg-raster", | ||
"image/svg+xml", | ||
"image/t38", | ||
"image/tiff", | ||
"image/tiff-fx", | ||
"image/vnd.adobe.photoshop", | ||
"image/vnd.airzip.accelerator.azv", | ||
"image/vnd.cns.inf2", | ||
"image/vnd.dece.graphic", | ||
"image/vnd.djvu", | ||
"image/vnd.dwg", | ||
"image/vnd.dxf", | ||
"image/vnd.dvb.subtitle", | ||
"image/vnd.fastbidsheet", | ||
"image/vnd.fpx", | ||
"image/vnd.fst", | ||
"image/vnd.fujixerox.edmics-mmr", | ||
"image/vnd.fujixerox.edmics-rlc", | ||
"image/vnd.globalgraphics.pgb", | ||
"image/vnd.microsoft.icon", | ||
"image/vnd.mix", | ||
"image/vnd.ms-modi", | ||
"image/vnd.mozilla.apng", | ||
"image/vnd.net-fpx", | ||
"image/vnd.pco.b16", | ||
"image/vnd.radiance", | ||
"image/vnd.sealed.png", | ||
"image/vnd.sealedmedia.softseal.gif", | ||
"image/vnd.sealedmedia.softseal.jpg", | ||
"image/vnd.svf", | ||
"image/vnd.tencent.tap", | ||
"image/vnd.valve.source.texture", | ||
"image/vnd.wap.wbmp", | ||
"image/vnd.xiff", | ||
"image/vnd.zbrush.pcx", | ||
"image/webp", | ||
"image/wmf", | ||
"text/plain", | ||
"text/csv", | ||
"text/json", | ||
"application/json", | ||
"application/zip", | ||
"application/gzip", | ||
"application/x-bzip", | ||
"application/x-bzip2", | ||
"application/x-7z-compressed", | ||
"application/x-tar", | ||
"application/pdf", | ||
], | ||
}, | ||
"markdownPlugins": Object { | ||
"lens": true, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.