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

Bug 1894374: prevent prevent loading by type #7099

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,12 @@ const templatesResource: WatchK8sResource = {
enum uploadErrorType {
MISSING = 'missing',
ALLOCATE = 'allocate',
TYPE = 'type',
CERT = 'cert',
}

const uploadErrorMessage = {
[uploadErrorType.MISSING]: 'File input is missing',
[uploadErrorType.ALLOCATE]: 'Could not create persistent volume claim',
[uploadErrorType.TYPE]: (
<>
<p>
The format of the file you are uploading is not supported. Please use one of the supported
formats
</p>
<p>
<ExternalLink
text="Learn more about supported formats"
href={CDI_UPLOAD_SUPPORTED_TYPES_URL}
/>
</p>
</>
),
[uploadErrorType.CERT]: (uploadProxy) => (
<>
It seems that your browser does not trust the certificate of the upload proxy. Please{' '}
Expand Down Expand Up @@ -471,6 +456,7 @@ export const UploadPVCPage: React.FC<UploadPVCPageProps> = (props) => {
const [disableFormSubmit, setDisableFormSubmit] = React.useState(false);
const [fileValue, setFileValue] = React.useState<File>(null);
const [fileName, setFileName] = React.useState('');
const [fileNameExtension, setFileNameExtension] = React.useState('');
const [isFileRejected, setIsFileRejected] = React.useState(false);
const [error, setError] = React.useState<string>('');
const [isAllocating, setIsAllocating] = React.useState(false);
Expand All @@ -490,8 +476,6 @@ export const UploadPVCPage: React.FC<UploadPVCPageProps> = (props) => {
e.preventDefault();
if (!fileName) {
setError(uploadErrorType.MISSING);
} else if (isFileRejected) {
setError(uploadErrorType.TYPE);
} else {
// checking valid certificate for proxy
setCheckingCertificate(true);
Expand Down Expand Up @@ -529,6 +513,9 @@ export const UploadPVCPage: React.FC<UploadPVCPageProps> = (props) => {
const handleFileChange = (value, filename) => {
setFileName(filename);
setFileValue(value);

setFileNameExtension(/[.][^.]+$/.exec(filename)?.toString());
setIsFileRejected(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is isFileRejected true? @yaacov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is set by the UploadPVCForm when file extension is unexpected, but is not reset back on field clear, this line reset it back when the offending file is cleared but no new file is selected.

setError('');
};

Expand Down Expand Up @@ -574,6 +561,24 @@ export const UploadPVCPage: React.FC<UploadPVCPageProps> = (props) => {
inProgress={!loadedTemplates || !loadedPvcs || isCheckingCertificate}
errorMessage={errorMessage}
>
{isFileRejected && (
<Alert variant="warning" isInline title="File type extension">
<p>
Based on the file extension it seems like you are trying to upload a file which is
not supported (
{fileNameExtension
? `detected file extension is '${fileNameExtension}'`
: 'no file extention detected'}
).
</p>
<p>
<ExternalLink
text="Learn more about supported formats"
href={CDI_UPLOAD_SUPPORTED_TYPES_URL}
/>
</p>
</Alert>
)}
<ActionGroup className="pf-c-form">
<Button
isDisabled={disableFormSubmit || isCheckingCertificate}
Expand Down