diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/constants.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/constants.ts index c64128274aa3d..966068eb4c074 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/constants.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/constants.ts @@ -5,5 +5,11 @@ * 2.0. */ -export const SUPPORTED_FILE_TYPES = ['text/csv', 'text/plain', 'text/tab-separated-values']; +export const SUPPORTED_FILE_TYPES = [ + 'text/csv', + 'text/plain', + 'text/tab-separated-values', + '.tsv', // Useful for Windows when it can't recognise the file extension. + '.csv', // Useful for Windows when it can't recognise the file extension. +]; export const SUPPORTED_FILE_EXTENSIONS = ['CSV', 'TXT', 'TSV']; diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/hooks.test.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/hooks.test.ts index 675535365a0b0..a3b9a2e0ce24e 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/hooks.test.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/hooks.test.ts @@ -37,12 +37,13 @@ describe('useFileValidation', () => { test('should call onError when an error occurs', () => { const onErrorMock = jest.fn(); const onCompleteMock = jest.fn(); + const invalidFileType = 'invalid file type'; const { result } = renderHook( () => useFileValidation({ onError: onErrorMock, onComplete: onCompleteMock }), { wrapper: TestProviders } ); - result.current(new File([invalidLine], 'test.csv')); + result.current(new File([invalidLine], 'test.csv', { type: invalidFileType })); expect(onErrorMock).toHaveBeenCalled(); expect(onCompleteMock).not.toHaveBeenCalled(); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.test.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.test.ts index 4e742d4d92505..4a77e024528dd 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.test.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.test.ts @@ -56,6 +56,14 @@ describe('validateFile', () => { expect(result.valid).toBe(true); }); + it('should return valid if the mime type is empty (Windows)', () => { + const file = new File(['file content'], 'test.csv', { type: '' }); + + const result = validateFile(file, formatBytes); + + expect(result.valid).toBe(true); + }); + it('should return an error message if the file type is invalid', () => { const file = new File(['file content'], 'test.txt', { type: 'invalid-type' }); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.ts index 06018a2496768..6f8bd8fb816bf 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/validations.ts @@ -53,7 +53,10 @@ export const validateFile = ( file: File, formatBytes: (bytes: number) => string ): { valid: false; errorMessage: string; code: string } | { valid: true } => { - if (!SUPPORTED_FILE_TYPES.includes(file.type)) { + if ( + file.type !== '' && // file.type might be an empty string on windows + !SUPPORTED_FILE_TYPES.includes(file.type) + ) { return { valid: false, code: 'unsupported_file_type',