Skip to content

Commit 554ce92

Browse files
authored
Merge branch '2.4-develop' into more-informative-xml-error-message
2 parents 6394ae7 + a047c76 commit 554ce92

File tree

524 files changed

+18006
-4914
lines changed

Some content is hidden

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

524 files changed

+18006
-4914
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Authorization\Model;
10+
11+
use Magento\Framework\App\Backpressure\ContextInterface;
12+
use Magento\Framework\App\Backpressure\IdentityProviderInterface;
13+
use Magento\Framework\Exception\RuntimeException;
14+
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
15+
16+
/**
17+
* Utilizes UserContext for backpressure identity
18+
*/
19+
class IdentityProvider implements IdentityProviderInterface
20+
{
21+
/**
22+
* User context identity type map
23+
*/
24+
private const USER_CONTEXT_IDENTITY_TYPE_MAP = [
25+
UserContextInterface::USER_TYPE_CUSTOMER => ContextInterface::IDENTITY_TYPE_CUSTOMER,
26+
UserContextInterface::USER_TYPE_ADMIN => ContextInterface::IDENTITY_TYPE_ADMIN
27+
];
28+
29+
/**
30+
* @var UserContextInterface
31+
*/
32+
private UserContextInterface $userContext;
33+
34+
/**
35+
* @var RemoteAddress
36+
*/
37+
private RemoteAddress $remoteAddress;
38+
39+
/**
40+
* @param UserContextInterface $userContext
41+
* @param RemoteAddress $remoteAddress
42+
*/
43+
public function __construct(UserContextInterface $userContext, RemoteAddress $remoteAddress)
44+
{
45+
$this->userContext = $userContext;
46+
$this->remoteAddress = $remoteAddress;
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*
52+
* @throws RuntimeException
53+
*/
54+
public function fetchIdentityType(): int
55+
{
56+
if (!$this->userContext->getUserId()) {
57+
return ContextInterface::IDENTITY_TYPE_IP;
58+
}
59+
60+
$userType = $this->userContext->getUserType();
61+
if (isset(self::USER_CONTEXT_IDENTITY_TYPE_MAP[$userType])) {
62+
return self::USER_CONTEXT_IDENTITY_TYPE_MAP[$userType];
63+
}
64+
65+
throw new RuntimeException(__('User type not defined'));
66+
}
67+
68+
/**
69+
* @inheritDoc
70+
*
71+
* @throws RuntimeException
72+
*/
73+
public function fetchIdentity(): string
74+
{
75+
$userId = $this->userContext->getUserId();
76+
if ($userId) {
77+
return (string)$userId;
78+
}
79+
80+
$address = $this->remoteAddress->getRemoteAddress();
81+
if (!$address) {
82+
throw new RuntimeException(__('Failed to extract remote address'));
83+
}
84+
85+
return $address;
86+
}
87+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Authorization\Test\Unit\Model;
10+
11+
use Magento\Authorization\Model\IdentityProvider;
12+
use Magento\Authorization\Model\UserContextInterface;
13+
use Magento\Framework\App\Backpressure\ContextInterface;
14+
use Magento\Framework\Exception\RuntimeException;
15+
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Tests the IdentityProvider class
21+
*/
22+
class IdentityProviderTest extends TestCase
23+
{
24+
/**
25+
* @var UserContextInterface|MockObject
26+
*/
27+
private $userContext;
28+
29+
/**
30+
* @var RemoteAddress|MockObject
31+
*/
32+
private $remoteAddress;
33+
34+
/**
35+
* @var IdentityProvider
36+
*/
37+
private $model;
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
protected function setUp(): void
43+
{
44+
parent::setUp();
45+
46+
$this->userContext = $this->createMock(UserContextInterface::class);
47+
$this->remoteAddress = $this->createMock(RemoteAddress::class);
48+
$this->model = new IdentityProvider($this->userContext, $this->remoteAddress);
49+
}
50+
51+
/**
52+
* Cases for identity provider.
53+
*
54+
* @return array
55+
*/
56+
public function getIdentityCases(): array
57+
{
58+
return [
59+
'empty-user-context' => [null, null, '127.0.0.1', ContextInterface::IDENTITY_TYPE_IP, '127.0.0.1'],
60+
'guest-user-context' => [
61+
UserContextInterface::USER_TYPE_GUEST,
62+
null,
63+
'127.0.0.1',
64+
ContextInterface::IDENTITY_TYPE_IP,
65+
'127.0.0.1'
66+
],
67+
'admin-user-context' => [
68+
UserContextInterface::USER_TYPE_ADMIN,
69+
42,
70+
'127.0.0.1',
71+
ContextInterface::IDENTITY_TYPE_ADMIN,
72+
'42'
73+
],
74+
'customer-user-context' => [
75+
UserContextInterface::USER_TYPE_CUSTOMER,
76+
42,
77+
'127.0.0.1',
78+
ContextInterface::IDENTITY_TYPE_CUSTOMER,
79+
'42'
80+
],
81+
];
82+
}
83+
84+
/**
85+
* Verify identity provider.
86+
*
87+
* @param int|null $userType
88+
* @param int|null $userId
89+
* @param string $remoteAddr
90+
* @param int $expectedType
91+
* @param string $expectedIdentity
92+
* @return void
93+
* @dataProvider getIdentityCases
94+
*/
95+
public function testFetchIdentity(
96+
?int $userType,
97+
?int $userId,
98+
string $remoteAddr,
99+
int $expectedType,
100+
string $expectedIdentity
101+
): void {
102+
$this->userContext->method('getUserType')->willReturn($userType);
103+
$this->userContext->method('getUserId')->willReturn($userId);
104+
$this->remoteAddress->method('getRemoteAddress')->willReturn($remoteAddr);
105+
106+
$this->assertEquals($expectedType, $this->model->fetchIdentityType());
107+
$this->assertEquals($expectedIdentity, $this->model->fetchIdentity());
108+
}
109+
110+
/**
111+
* Tests fetching an identity type when user type can't be defined
112+
*/
113+
public function testFetchIdentityTypeUserTypeNotDefined()
114+
{
115+
$this->userContext->method('getUserId')->willReturn(2);
116+
$this->userContext->method('getUserType')->willReturn(null);
117+
$this->expectException(RuntimeException::class);
118+
$this->expectExceptionMessage(__('User type not defined')->getText());
119+
$this->model->fetchIdentityType();
120+
}
121+
122+
/**
123+
* Tests fetching an identity when user address can't be extracted
124+
*/
125+
public function testFetchIdentityFailedToExtractRemoteAddress()
126+
{
127+
$this->userContext->method('getUserId')->willReturn(null);
128+
$this->remoteAddress->method('getRemoteAddress')->willReturn(false);
129+
$this->expectException(RuntimeException::class);
130+
$this->expectExceptionMessage(__('Failed to extract remote address')->getText());
131+
$this->model->fetchIdentity();
132+
}
133+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
</arguments>
2525
</type>
2626
<preference for="Magento\Authorization\Model\UserContextInterface" type="Magento\Authorization\Model\CompositeUserContext"/>
27+
<preference for="Magento\Framework\App\Backpressure\IdentityProviderInterface"
28+
type="Magento\Authorization\Model\IdentityProvider"/>
2729
</config>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
"We can't find the role for the user you wanted.","We can't find the role for the user you wanted."
22
"Something went wrong while compiling a list of allowed resources. You can find out more in the exceptions log.","Something went wrong while compiling a list of allowed resources. You can find out more in the exceptions log."
3+
"User type not defined","User type not defined"
4+
"Failed to extract remote address","Failed to extract remote address"

app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Block\System\Store\Grid\Render;
77

8+
use Magento\Framework\DataObject;
9+
810
/**
911
* Store render group
1012
*
@@ -13,9 +15,9 @@
1315
class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1416
{
1517
/**
16-
* {@inheritdoc}
18+
* @inheritDoc
1719
*/
18-
public function render(\Magento\Framework\DataObject $row)
20+
public function render(DataObject $row)
1921
{
2022
if (!$row->getData($this->getColumn()->getIndex())) {
2123
return null;
@@ -28,6 +30,6 @@ public function render(\Magento\Framework\DataObject $row)
2830
'">' .
2931
$this->escapeHtml($row->getData($this->getColumn()->getIndex())) .
3032
'</a><br />'
31-
. '(' . __('Code') . ': ' . $row->getGroupCode() . ')';
33+
. '(' . __('Code') . ': ' . $this->escapeHtml($row->getGroupCode()) . ')';
3234
}
3335
}

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,10 +1067,11 @@ public function getCsv()
10671067
$data = [];
10681068
foreach ($this->getColumns() as $column) {
10691069
if (!$column->getIsSystem()) {
1070+
$exportField = (string)$column->getRowFieldExport($item);
10701071
$data[] = '"' . str_replace(
10711072
['"', '\\'],
10721073
['""', '\\\\'],
1073-
$column->getRowFieldExport($item) ?: ''
1074+
$exportField ?: ''
10741075
) . '"';
10751076
}
10761077
}

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,10 @@
349349
<field id="transport">smtp</field>
350350
</depends>
351351
</field>
352-
<field id="password" translate="label comment" type="password" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
352+
<field id="password" translate="label comment" type="obscure" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
353353
<label>Password</label>
354-
<comment>Username</comment>
354+
<comment>Password</comment>
355+
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
355356
<depends>
356357
<field id="transport">smtp</field>
357358
</depends>

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class Bundle extends AbstractView
3636
protected $options;
3737

3838
/**
39-
* Catalog product
40-
*
4139
* @var \Magento\Catalog\Helper\Product
4240
*/
4341
protected $catalogProduct;
@@ -405,7 +403,7 @@ private function getConfigData(Product $product, array $options)
405403
*/
406404
private function processOptions(string $optionId, array $options, DataObject $preConfiguredValues)
407405
{
408-
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
406+
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/{$optionId}") ?? [];
409407
$selections = $options[$optionId]['selections'];
410408
array_walk(
411409
$selections,

0 commit comments

Comments
 (0)