Skip to content

Commit d255c5c

Browse files
committed
Merge branch '2.4-develop' into combined-pr
2 parents 10d6e70 + 3835860 commit d255c5c

File tree

10 files changed

+78
-11
lines changed

10 files changed

+78
-11
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AwsS3StorefrontCaptchaOnCustomerLoginTest" extends="StorefrontCaptchaOnCustomerLoginTest">
12+
<annotations>
13+
<features value="Captcha"/>
14+
<stories value="Login with Customer Account + Captcha"/>
15+
<title value="AWS S3 Captcha customer login page test"/>
16+
<description value="Check CAPTCHA on Storefront Login Page."/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-39491" />
19+
<group value="remote_storage_aws_s3"/>
20+
</annotations>
21+
<before>
22+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage"/>
23+
</before>
24+
<after>
25+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage"/>
26+
</after>
27+
</test>
28+
</tests>

app/code/Magento/AwsS3/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "magento/module-aws-s-3",
2+
"name": "magento/module-aws-s3",
33
"description": "N/A",
44
"config": {
55
"sort-packages": true

app/code/Magento/Captcha/Helper/Data.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public function getFonts()
150150
*/
151151
public function getImgDir($website = null)
152152
{
153-
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
153+
// Captcha images are not re-used and should be stored only locally.
154+
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA, Filesystem\DriverPool::FILE);
154155
$captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
155156
$mediaDir->create($captchaDir);
156157
return $mediaDir->getAbsolutePath($captchaDir) . '/';

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ private function getAlreadyExistedImage(array $imageRow, string $columnImage, st
19651965
if (filter_var($columnImage, FILTER_VALIDATE_URL)) {
19661966
$hash = $this->getFileHash($columnImage);
19671967
} else {
1968-
$path = $importDir . DS . $columnImage;
1968+
$path = $importDir . DIRECTORY_SEPARATOR . $columnImage;
19691969
$hash = $this->isFileExists($path) ? $this->getFileHash($path) : '';
19701970
}
19711971

@@ -1991,7 +1991,7 @@ function ($exists, $file) use ($hash) {
19911991
private function addImageHashes(array &$images): void
19921992
{
19931993
$productMediaPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)
1994-
->getAbsolutePath(DS . 'catalog' . DS . 'product');
1994+
->getAbsolutePath(DIRECTORY_SEPARATOR . 'catalog' . DIRECTORY_SEPARATOR . 'product');
19951995

19961996
foreach ($images as $storeId => $skus) {
19971997
foreach ($skus as $sku => $files) {
@@ -2188,7 +2188,7 @@ private function getImportDir(): string
21882188
$dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH];
21892189

21902190
return empty($this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR])
2191-
? $dirAddon . DS . $this->_mediaDirectory->getRelativePath('import')
2191+
? $dirAddon . DIRECTORY_SEPARATOR . $this->_mediaDirectory->getRelativePath('import')
21922192
: $this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR];
21932193
}
21942194

app/code/Magento/MediaStorage/App/Media.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ public function launch(): ResponseInterface
187187
$this->mediaDirectoryPath = $config->getMediaDirectory();
188188
$allowedResources = $config->getAllowedResources();
189189
$isAllowed = $this->isAllowed;
190-
if (!$isAllowed($this->relativeFileName, $allowedResources)) {
190+
$fileAbsolutePath = $this->directoryPub->getAbsolutePath($this->relativeFileName);
191+
$fileRelativePath = str_replace(rtrim($this->mediaDirectoryPath, '/') . '/', '', $fileAbsolutePath);
192+
if (!$isAllowed($fileRelativePath, $allowedResources)) {
191193
throw new LogicException('The path is not allowed: ' . $this->relativeFileName);
192194
}
193195
}

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
118118
->method('getAbsolutePath')
119119
->with(null)
120120
->willReturn(self::MEDIA_DIRECTORY);
121-
$this->directoryPubMock->expects(self::once())
121+
$this->directoryPubMock->expects(self::exactly(2))
122122
->method('getAbsolutePath')
123123
->with(self::RELATIVE_FILE_PATH)
124124
->willReturn($filePath);
@@ -154,7 +154,7 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized(): void
154154
->method('isReadable')
155155
->with(self::RELATIVE_FILE_PATH)
156156
->willReturn(true);
157-
$this->directoryPubMock->expects(self::once())
157+
$this->directoryPubMock->expects(self::exactly(2))
158158
->method('getAbsolutePath')
159159
->with(self::RELATIVE_FILE_PATH)
160160
->willReturn($filePath);
@@ -214,10 +214,15 @@ public function testCatchException(bool $isDeveloper, int $setBodyCalls): void
214214

215215
public function testExceptionWhenIsAllowedReturnsFalse(): void
216216
{
217+
$filePath = '/absolute/path/to/test/file.png';
217218
$this->directoryMediaMock->expects(self::once())
218219
->method('getAbsolutePath')
219220
->with(null)
220221
->willReturn(self::MEDIA_DIRECTORY);
222+
$this->directoryPubMock->expects(self::once())
223+
->method('getAbsolutePath')
224+
->with(self::RELATIVE_FILE_PATH)
225+
->willReturn($filePath);
221226
$this->configMock->expects(self::once())
222227
->method('save');
223228

app/code/Magento/RemoteStorage/Driver/Cache/CacheFactory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
namespace Magento\RemoteStorage\Driver\Cache;
99

10+
use League\Flysystem\Adapter\Local;
1011
use League\Flysystem\Cached\CacheInterface;
1112
use League\Flysystem\Cached\Storage\Memory;
1213
use League\Flysystem\Cached\Storage\Predis;
14+
use League\Flysystem\Cached\Storage\Adapter;
15+
use Magento\Framework\App\Filesystem\DirectoryList;
16+
use Magento\Framework\Filesystem;
1317
use Magento\RemoteStorage\Driver\DriverException;
18+
use Magento\RemoteStorage\Driver\DriverPool;
1419
use Predis\Client;
1520

1621
/**
@@ -20,14 +25,32 @@ class CacheFactory
2025
{
2126
public const ADAPTER_PREDIS = 'predis';
2227
public const ADAPTER_MEMORY = 'memory';
28+
public const ADAPTER_LOCAL = 'local';
2329

2430
private const CACHE_KEY = 'storage';
31+
private const CACHE_FILE = 'storage_cache.json';
2532

2633
/**
2734
* Cache for 30 days.
2835
*/
2936
private const CACHE_EXPIRATION = 30 * 86400;
3037

38+
/**
39+
* @var string
40+
*/
41+
private $localCacheRoot;
42+
43+
/**
44+
* @param Filesystem $filesystem
45+
*/
46+
public function __construct(Filesystem $filesystem)
47+
{
48+
$this->localCacheRoot = $filesystem->getDirectoryRead(
49+
DirectoryList::VAR_DIR,
50+
DriverPool::FILE
51+
)->getAbsolutePath();
52+
}
53+
3154
/**
3255
* Create cache adapter.
3356
*
@@ -47,6 +70,8 @@ public function create(string $adapter, array $config = []): CacheInterface
4770
return new Predis(new Client($config), self::CACHE_KEY, self::CACHE_EXPIRATION);
4871
case self::ADAPTER_MEMORY:
4972
return new Memory();
73+
case self::ADAPTER_LOCAL:
74+
return new Adapter(new Local($this->localCacheRoot), self::CACHE_FILE, self::CACHE_EXPIRATION);
5075
}
5176

5277
throw new DriverException(__('Cache adapter %1 is not supported', $adapter));

app/code/Magento/RemoteStorage/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
</arguments>
3232
</virtualType>
3333
<virtualType name="fullRemoteFilesystem" type="Magento\RemoteStorage\Filesystem" />
34+
<virtualType name="stdFilesystem" type="Magento\Framework\Filesystem" />
3435
<preference for="Magento\Framework\Filesystem" type="customRemoteFilesystem"/>
36+
<type name="Magento\RemoteStorage\Driver\Cache\CacheFactory">
37+
<arguments>
38+
<argument name="filesystem" xsi:type="object">stdFilesystem</argument>
39+
</arguments>
40+
</type>
3541
<type name="Magento\Framework\Filesystem\Directory\TargetDirectory">
3642
<arguments>
3743
<argument name="filesystem" xsi:type="object">fullRemoteFilesystem</argument>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
"tinymce/tinymce": "3.4.7",
328328
"magento/module-tinymce-3": "*",
329329
"magento/module-csp": "*",
330-
"magento/module-aws-s-3": "*",
330+
"magento/module-aws-s3": "*",
331331
"magento/module-remote-storage": "*"
332332
},
333333
"conflict": {

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ImportWithSharedImagesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function updateUploader(): void
202202
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
203203
$destDir = $rootDirectory->getRelativePath(
204204
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
205-
. DS . $this->mediaConfig->getBaseMediaPath()
205+
. DIRECTORY_SEPARATOR . $this->mediaConfig->getBaseMediaPath()
206206
);
207207
$tmpDir = $rootDirectory->getRelativePath(
208208
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
@@ -226,7 +226,7 @@ private function moveImages(string $fileName): void
226226
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
227227
);
228228
$fixtureDir = realpath(__DIR__ . '/../../_files');
229-
$tmpFilePath = $rootDirectory->getAbsolutePath($tmpDir . DS . $fileName);
229+
$tmpFilePath = $rootDirectory->getAbsolutePath($tmpDir . DIRECTORY_SEPARATOR . $fileName);
230230
$this->fileDriver->createDirectory($tmpDir);
231231
$rootDirectory->getDriver()->copy(
232232
$fixtureDir . DIRECTORY_SEPARATOR . $fileName,

0 commit comments

Comments
 (0)