From b040aa1e789dc63195abedb15ef301cfada6d1d9 Mon Sep 17 00:00:00 2001 From: itsconquest Date: Thu, 21 Jul 2022 16:25:23 +1200 Subject: [PATCH] fix(TLS): remove file type validation [EE-3672] (#7280) --- app/portainer/helpers/yup-file-validation.ts | 19 ------------------- .../WizardDocker/APITab/TLSFieldset.tsx | 15 ++------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/app/portainer/helpers/yup-file-validation.ts b/app/portainer/helpers/yup-file-validation.ts index f1c782c96..2073d9ed0 100644 --- a/app/portainer/helpers/yup-file-validation.ts +++ b/app/portainer/helpers/yup-file-validation.ts @@ -22,22 +22,3 @@ export function withFileSize(fileValidation: FileSchema, maxSize: number) { return file.size <= maxSize; } } - -export function withFileType( - fileValidation: FileSchema, - fileTypes: File['type'][] -) { - return fileValidation.test( - 'file-type', - 'Selected file has unsupported format.', - validateFileType - ); - - function validateFileType(file?: File) { - if (!file) { - return true; - } - - return fileTypes.includes(file.type); - } -} diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/APITab/TLSFieldset.tsx b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/APITab/TLSFieldset.tsx index 990e4d849..6f38c3b86 100644 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/APITab/TLSFieldset.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/APITab/TLSFieldset.tsx @@ -1,10 +1,6 @@ import { useFormikContext } from 'formik'; -import { - file, - withFileSize, - withFileType, -} from '@/portainer/helpers/yup-file-validation'; +import { file, withFileSize } from '@/portainer/helpers/yup-file-validation'; import { FileUploadField } from '@@/form-components/FileUpload'; import { SwitchField } from '@@/form-components/SwitchField'; @@ -83,16 +79,9 @@ export function TLSFieldset() { } const MAX_FILE_SIZE = 5_242_880; // 5MB -const ALLOWED_FILE_TYPES = [ - 'application/x-x509-ca-cert', - 'application/x-pem-file', -]; function certValidation() { - return withFileType( - withFileSize(file(), MAX_FILE_SIZE), - ALLOWED_FILE_TYPES - ).when(['tls', 'skipVerify'], { + return withFileSize(file(), MAX_FILE_SIZE).when(['tls', 'skipVerify'], { is: (tls: boolean, skipVerify: boolean) => tls && !skipVerify, then: (schema) => schema.required('File is required'), });