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

Prevent saving upload media files in root directory #25546

Merged
merged 3 commits into from
Nov 21, 2019
Merged

Prevent saving upload media files in root directory #25546

merged 3 commits into from
Nov 21, 2019

Conversation

kenboy
Copy link
Member

@kenboy kenboy commented Nov 10, 2019

Description (*)

If it is impossible to save pictures to the "media" directory, the save goes to the root directory

Manual testing scenarios (*)

  1. Make a ban on writing to the "pub/media/catalog/product" directory
  2. Start importing goods containing media information

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@kenboy kenboy requested a review from akaplya as a code owner November 10, 2019 09:56
@m2-assistant
Copy link

m2-assistant bot commented Nov 10, 2019

Hi @kenboy. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

Copy link
Contributor

@rogyar rogyar left a comment

Choose a reason for hiding this comment

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

Hi @kenboy. Thank you for your collaboration.
Could you provide a little bit more information regarding the main idea of your PR, please? From the PR title/description I see that the goal is to save files to the root (it would be great if you could clarify the "root" definition here since it's completely relative) if the media directory is not writable. However, I see that the following statement:

$destinationDir = "catalog/product";
$destinationPath = $dirAddon . '/' . $this->_mediaDirectory->getRelativePath($destinationDir);

stays unchanged. So, the destination path will be the same as previously. Could you clarify this part, please?

Thank you!

@ghost ghost assigned rogyar Nov 10, 2019
@kenboy
Copy link
Member Author

kenboy commented Nov 10, 2019

Hi @rogyar
When the path formed by the following statement:

$destinationDir = "catalog/product";
$destinationPath = $dirAddon . '/' . $this->_mediaDirectory->getRelativePath($destinationDir);

and not available for write, an exception is thrown:

if (!$this->_fileUploader->setDestDir($destinationPath)) {
  throw new LocalizedException(
    __('File directory \'%1\' is not writable.', $destinationPath)
  );
}

setting the "\Magento\CatalogImportExport\Model\Import\Uploader::$_destDir" properties does not occur, the object is not fully formed.

But since it is already stored in the property "\Magento\CatalogImportExport\Model\Import\Product::$_fileUploader", when the function is called again, an incomplete object is used.

@kenboy kenboy requested a review from rogyar November 12, 2019 16:52
@rogyar rogyar changed the title Save upload media files in root directory Prevent saving upload media files in root directory Nov 13, 2019
@rogyar
Copy link
Contributor

rogyar commented Nov 13, 2019

Hi @kenboy. Got it, now it makes sense, thank you!

May I kindly ask you to cover the proposed change by a simple unit test, please? The test will invoke getUploader() method a couple of times.
On the very first invocation, we mock throwing the "not writable" exception.
On the second invocation, we assert that the routine for uploader initialization is being executed (not skipped as in case of the current implementation with $this->_fileUploader === null).

Thank you!

@rogyar rogyar added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Nov 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @rogyar, thank you for the review.
ENGCOM-6297 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@kenboy thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@magento-engcom-team magento-engcom-team merged commit d8e1a71 into magento:2.3-develop Nov 21, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 21, 2019

Hi @kenboy, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.5 milestone Nov 21, 2019
@kenboy kenboy deleted the upload-media-files-fix branch November 30, 2019 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants