Skip to content

Commit 01dd6b5

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento/magento2ce into PR-01-21
2 parents a6e0f75 + ad0ba79 commit 01dd6b5

File tree

261 files changed

+5600
-808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+5600
-808
lines changed

app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function execute()
3434
/** @var $export \Magento\ImportExport\Model\Export */
3535
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3636
$export->setData($data);
37-
$export->filterAttributeCollection(
38-
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
37+
$attrFilterBlock->prepareCollection(
38+
$export->filterAttributeCollection($export->getEntityAttributeCollection())
3939
);
4040
return $resultLayout;
4141
} catch (\Exception $e) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AwsS3\Test\Mftf\Helper;
9+
10+
use Psr\Log\LoggerInterface;
11+
12+
/**
13+
* Mocked logger for using the AwsS3 driver in testing
14+
*
15+
* Ignores most log messages but throws errors on error/critical/emergency logs so tests will fail
16+
*/
17+
class MockTestLogger implements LoggerInterface {
18+
19+
public function emergency($message, array $context = array())
20+
{
21+
throw new \Exception($message);
22+
}
23+
24+
public function alert($message, array $context = array())
25+
{
26+
// noop
27+
}
28+
29+
public function critical($message, array $context = array())
30+
{
31+
throw new \Exception($message);
32+
}
33+
34+
public function error($message, array $context = array())
35+
{
36+
throw new \Exception($message);
37+
}
38+
39+
public function warning($message, array $context = array())
40+
{
41+
// noop
42+
}
43+
44+
public function notice($message, array $context = array())
45+
{
46+
// noop
47+
}
48+
49+
public function info($message, array $context = array())
50+
{
51+
// noop
52+
}
53+
54+
public function debug($message, array $context = array())
55+
{
56+
// noop
57+
}
58+
59+
public function log($level, $message, array $context = array())
60+
{
61+
// noop
62+
}
63+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AwsS3\Test\Mftf\Helper;
9+
10+
use Aws\S3\S3Client;
11+
use Codeception\Lib\ModuleContainer;
12+
use League\Flysystem\AwsS3v3\AwsS3Adapter;
13+
use Magento\AwsS3\Driver\AwsS3;
14+
use Magento\FunctionalTestingFramework\Helper\Helper;
15+
use Magento\Framework\Filesystem\DriverInterface;
16+
17+
/**
18+
* Class for MFTF helpers for doing file assertions using S3.
19+
*/
20+
class S3FileAssertions extends Helper
21+
{
22+
/**
23+
* @var DriverInterface $driver
24+
*/
25+
private $driver;
26+
27+
/**
28+
* Call the parent constructor then create the AwsS3 driver from environment variables
29+
*
30+
* @param ModuleContainer $moduleContainer
31+
* @param array|null $config
32+
* @return void
33+
*/
34+
public function __construct(ModuleContainer $moduleContainer, ?array $config = null)
35+
{
36+
parent::__construct($moduleContainer, $config);
37+
38+
$region = getenv('REMOTE_STORAGE_AWSS3_REGION');
39+
$prefix = getenv('REMOTE_STORAGE_AWSS3_PREFIX');
40+
$bucket = getenv('REMOTE_STORAGE_AWSS3_BUCKET');
41+
$accessKey = getenv('REMOTE_STORAGE_AWSS3_ACCESS_KEY');
42+
$secretKey = getenv('REMOTE_STORAGE_AWSS3_SECRET_KEY');
43+
44+
$config = [
45+
'version' => 'latest',
46+
'credentials' => [
47+
'key' => $accessKey,
48+
'secret' => $secretKey
49+
],
50+
'bucket' => $bucket,
51+
'region' => $region
52+
];
53+
54+
if (empty($config['credentials']['key']) || empty($config['credentials']['secret'])) {
55+
unset($config['credentials']);
56+
}
57+
58+
$client = new S3Client($config);
59+
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);
60+
$objectUrl = $client->getObjectUrl($adapter->getBucket(), $adapter->applyPathPrefix('.'));
61+
$s3Driver = new AwsS3($adapter, new MockTestLogger(), $objectUrl);
62+
63+
$this->driver = $s3Driver;
64+
}
65+
66+
/**
67+
* Create a file in the S3 bucket
68+
*
69+
* @param string $filePath
70+
* @param string $text
71+
* @return void
72+
*
73+
* @throws \Magento\Framework\Exception\FileSystemException
74+
*/
75+
public function createTextFile($filePath, $text): void
76+
{
77+
$this->driver->filePutContents($filePath, $text);
78+
}
79+
80+
/**
81+
* Delete a file from the S3 bucket if it exists
82+
*
83+
* @param string $filePath
84+
* @return void
85+
*
86+
* @throws \Magento\Framework\Exception\FileSystemException
87+
*/
88+
public function deleteFileIfExists($filePath): void
89+
{
90+
if ($this->driver->isExists($filePath)) {
91+
$this->driver->deleteFile($filePath);
92+
}
93+
}
94+
95+
/**
96+
* Assert a file exists on the remote storage system
97+
*
98+
* @param string $filePath
99+
* @param string $message
100+
* @return void
101+
*
102+
* @throws \Magento\Framework\Exception\FileSystemException
103+
*/
104+
public function assertFileExists($filePath, $message = ''): void
105+
{
106+
$this->assertTrue($this->driver->isExists($filePath), $message);
107+
}
108+
109+
/**
110+
* Assert a file does not exist on the remote storage system
111+
*
112+
* @param string $filePath
113+
* @param string $message
114+
* @return void
115+
*
116+
* @throws \Magento\Framework\Exception\FileSystemException
117+
*/
118+
public function assertFileDoesNotExist($filePath, $message = ''): void
119+
{
120+
$this->assertFalse($this->driver->isExists($filePath), $message);
121+
}
122+
123+
/**
124+
* Assert a file on the remote storage system has no contents
125+
*
126+
* @param string $filePath
127+
* @param string $message
128+
* @return void
129+
*
130+
* @throws \Magento\Framework\Exception\FileSystemException
131+
*/
132+
public function assertFileEmpty($filePath, $message = ""): void
133+
{
134+
$this->assertEmpty($this->driver->fileGetContents($filePath), $message);
135+
}
136+
137+
/**
138+
* Assert a file on the remote storage system is not empty
139+
*
140+
* @param string $filePath
141+
* @param string $message
142+
* @return void
143+
*
144+
* @throws \Magento\Framework\Exception\FileSystemException
145+
*/
146+
public function assertFileNotEmpty($filePath, $message = ""): void
147+
{
148+
$this->assertNotEmpty($this->driver->fileGetContents($filePath), $message);
149+
}
150+
151+
/**
152+
* Assert a file on the remote storage system contains a given string
153+
*
154+
* @param string $filePath
155+
* @param string $text
156+
* @param string $message
157+
* @return void
158+
*
159+
* @throws \Magento\Framework\Exception\FileSystemException
160+
*/
161+
public function assertFileContainsString($filePath, $text, $message = ""): void
162+
{
163+
$this->assertStringContainsString($text, $this->driver->fileGetContents($filePath), $message);
164+
}
165+
166+
/**
167+
* Assert a file on the remote storage system does not contain a given string
168+
*
169+
* @param string $filePath
170+
* @param string $text
171+
* @param string $message
172+
* @return void
173+
*
174+
* @throws \Magento\Framework\Exception\FileSystemException
175+
*/
176+
public function assertFileDoesNotContain($filePath, $text, $message = ""): void
177+
{
178+
$this->assertStringNotContainsString($text, $this->driver->fileGetContents($filePath), $message);
179+
}
180+
}

app/code/Magento/Backend/App/Action/Plugin/Authentication.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ protected function _redirectIfNeededAfterLogin(\Magento\Framework\App\RequestInt
225225

226226
// Checks, whether secret key is required for admin access or request uri is explicitly set
227227
if ($this->_url->useSecretKey()) {
228-
$requestUri = $this->_url->getUrl('*/*/*', ['_current' => true]);
228+
$requestParts = explode('/', trim($request->getRequestUri(), '/'), 2);
229+
$requestUri = $this->_url->getUrl(array_pop($requestParts));
229230
} elseif ($request) {
230231
$requestUri = $request->getRequestUri();
231232
}

app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ public function execute()
4949
}
5050

5151
$requestUrl = $this->getRequest()->getUri();
52-
$backendUrl = $this->getUrl('*');
53-
// redirect according to rewrite rule
54-
if ($requestUrl != $backendUrl) {
55-
return $this->getRedirect($backendUrl);
52+
if (!$requestUrl->isValid()) {
53+
return $this->getRedirect($this->getUrl('*'));
5654
}
55+
5756
return $this->resultPageFactory->create();
5857
}
5958

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
/**
11+
* Class Composite validates if urlKey doesn't matches frontName or restricted words(endpoint names)
12+
*/
13+
class CompositeUrlKey implements UrlKeyValidatorInterface
14+
{
15+
/**
16+
* @var UrlKeyValidatorInterface[]
17+
*/
18+
private $validators;
19+
20+
/**
21+
* @param array $validators
22+
*/
23+
public function __construct(
24+
array $validators = []
25+
) {
26+
$this->validators = $validators;
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function validate(string $urlKey): array
33+
{
34+
$errors = [];
35+
foreach ($this->validators as $validator) {
36+
$errors[] = $validator->validate($urlKey);
37+
}
38+
39+
return array_merge([], ...$errors);
40+
}
41+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
use Magento\Backend\App\Area\FrontNameResolver;
11+
12+
/**
13+
* Class FrontName validates if urlKey doesn't matches frontName
14+
*/
15+
class FrontName implements UrlKeyValidatorInterface
16+
{
17+
/**
18+
* @var FrontNameResolver
19+
*/
20+
private $frontNameResolver;
21+
22+
/**
23+
* @param FrontNameResolver $frontNameResolver
24+
*/
25+
public function __construct(
26+
FrontNameResolver $frontNameResolver
27+
) {
28+
$this->frontNameResolver = $frontNameResolver;
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function validate(string $urlKey): array
35+
{
36+
$errors = [];
37+
$frontName = $this->frontNameResolver->getFrontName();
38+
if ($urlKey == $frontName) {
39+
$errors[] = __(
40+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
41+
$urlKey,
42+
$frontName
43+
);
44+
}
45+
46+
return $errors;
47+
}
48+
}

0 commit comments

Comments
 (0)