mirror of https://github.com/portainer/portainer
fix(TLS): remove file type validation [EE-3672] (#7280)
parent
985eef6987
commit
b040aa1e78
|
@ -22,22 +22,3 @@ export function withFileSize(fileValidation: FileSchema, maxSize: number) {
|
||||||
return file.size <= maxSize;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import {
|
import { file, withFileSize } from '@/portainer/helpers/yup-file-validation';
|
||||||
file,
|
|
||||||
withFileSize,
|
|
||||||
withFileType,
|
|
||||||
} from '@/portainer/helpers/yup-file-validation';
|
|
||||||
|
|
||||||
import { FileUploadField } from '@@/form-components/FileUpload';
|
import { FileUploadField } from '@@/form-components/FileUpload';
|
||||||
import { SwitchField } from '@@/form-components/SwitchField';
|
import { SwitchField } from '@@/form-components/SwitchField';
|
||||||
|
@ -83,16 +79,9 @@ export function TLSFieldset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 5_242_880; // 5MB
|
const MAX_FILE_SIZE = 5_242_880; // 5MB
|
||||||
const ALLOWED_FILE_TYPES = [
|
|
||||||
'application/x-x509-ca-cert',
|
|
||||||
'application/x-pem-file',
|
|
||||||
];
|
|
||||||
|
|
||||||
function certValidation() {
|
function certValidation() {
|
||||||
return withFileType(
|
return withFileSize(file(), MAX_FILE_SIZE).when(['tls', 'skipVerify'], {
|
||||||
withFileSize(file(), MAX_FILE_SIZE),
|
|
||||||
ALLOWED_FILE_TYPES
|
|
||||||
).when(['tls', 'skipVerify'], {
|
|
||||||
is: (tls: boolean, skipVerify: boolean) => tls && !skipVerify,
|
is: (tls: boolean, skipVerify: boolean) => tls && !skipVerify,
|
||||||
then: (schema) => schema.required('File is required'),
|
then: (schema) => schema.required('File is required'),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue