Skip to content

Commit 9a35dad

Browse files
authored
Merge pull request #6252 from magento-tsg/2.3.7-develop-pr150
[Condor] Fixes for 2.3 (pr150) (2.3.7-develop)
2 parents 970d67a + 29999a4 commit 9a35dad

File tree

6 files changed

+123
-38
lines changed

6 files changed

+123
-38
lines changed

app/code/Magento/Catalog/view/base/web/js/product/name.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,33 @@
55

66
define([
77
'Magento_Ui/js/grid/columns/column',
8-
'Magento_Catalog/js/product/list/column-status-validator'
9-
], function (Column, columnStatusValidator) {
8+
'Magento_Catalog/js/product/list/column-status-validator',
9+
'escaper'
10+
], function (Column, columnStatusValidator, escaper) {
1011
'use strict';
1112

1213
return Column.extend({
14+
defaults: {
15+
allowedTags: ['div', 'span', 'b', 'strong', 'i', 'em', 'u', 'a']
16+
},
17+
1318
/**
1419
* Depends on this option, product name can be shown or hide. Depends on backend configuration
1520
*
1621
* @returns {Boolean}
1722
*/
1823
isAllowed: function () {
1924
return columnStatusValidator.isValid(this.source(), 'name', 'show_attributes');
25+
},
26+
27+
/**
28+
* Name column.
29+
*
30+
* @param {String} label
31+
* @returns {String}
32+
*/
33+
getNameUnsanitizedHtml: function (label) {
34+
return escaper.escapeHtml(label, this.allowedTags);
2035
}
2136
});
2237
});

app/code/Magento/Catalog/view/base/web/template/product/name.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
-->
77
<strong if="isAllowed()"
88
class="product-item-name">
9-
<a attr="href: $row().url" html="$col.getLabel($row())"/>
9+
<a attr="href: $row().url" html="getNameUnsanitizedHtml($col.getLabel($row()))"/>
1010
</strong>

app/code/Magento/CustomerGraphQl/Model/Context/AddUserInfoToContext.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function execute(ContextParametersInterface $contextParameters): ContextP
6060
*/
6161
private function isCustomer(?int $customerId, ?int $customerType): bool
6262
{
63-
return !empty($customerId) && !empty($customerType) && $customerType !== UserContextInterface::USER_TYPE_GUEST;
63+
return !empty($customerId)
64+
&& !empty($customerType)
65+
&& $customerType === UserContextInterface::USER_TYPE_CUSTOMER;
6466
}
6567
}

app/code/Magento/Multishipping/view/frontend/templates/checkout/billing.phtml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
$methodsCount = count($methods);
7373
$methodsForms = $block->hasFormTemplates() ? $block->getFormTemplates(): [];
7474

75-
foreach ($methods as $_method) :
75+
foreach ($methods as $_method):
7676
$code = $_method->getCode();
7777
$checked = $block->getSelectedMethodCode() === $code;
7878

@@ -82,7 +82,7 @@
8282
?>
8383
<div data-bind="scope: 'payment_method_<?= $block->escapeHtml($code);?>'">
8484
<dt class="item-title">
85-
<?php if ($methodsCount > 1) : ?>
85+
<?php if ($methodsCount > 1): ?>
8686
<input type="radio"
8787
id="p_method_<?= $block->escapeHtml($code); ?>"
8888
value="<?= $block->escapeHtmlAttr($code); ?>"
@@ -93,11 +93,11 @@
9393
checked: isChecked,
9494
click: selectPaymentMethod,
9595
visible: isRadioButtonVisible()"
96-
<?php if ($checked) : ?>
96+
<?php if ($checked): ?>
9797
checked="checked"
9898
<?php endif; ?>
9999
class="radio"/>
100-
<?php else : ?>
100+
<?php else: ?>
101101
<input type="radio"
102102
id="p_method_<?= $block->escapeHtml($code); ?>"
103103
value="<?= $block->escapeHtmlAttr($code); ?>"
@@ -112,7 +112,7 @@
112112
<?= $block->escapeHtml($_method->getTitle()) ?>
113113
</label>
114114
</dt>
115-
<?php if ($html = $block->getChildHtml('payment.method.' . $code)) : ?>
115+
<?php if ($html = $block->getChildHtml('payment.method.' . $code)): ?>
116116
<dd class="item-content <?= $checked ? '' : 'no-display'; ?>">
117117
<?= /* @noEscape */ $html; ?>
118118
</dd>
@@ -171,20 +171,20 @@
171171
'domReady!'
172172
], function(quote, $) {
173173
quote.billingAddress({
174-
city: '<?= /* @noEscape */ $block->getAddress()->getCity() ?>',
175-
company: '<?= /* @noEscape */ $block->getAddress()->getCompany(); ?>',
176-
countryId: '<?= /* @noEscape */ $block->getAddress()->getCountryId(); ?>',
177-
customerAddressId: '<?= /* @noEscape */ $block->getAddress()->getCustomerAddressId(); ?>',
178-
customerId: '<?= /* @noEscape */ $block->getAddress()->getCustomerId(); ?>',
179-
fax: '<?= /* @noEscape */ $block->getAddress()->getFax(); ?>',
180-
firstname: '<?= /* @noEscape */ $block->getAddress()->getFirstname(); ?>',
181-
lastname: '<?= /* @noEscape */ $block->getAddress()->getLastname(); ?>',
182-
postcode: '<?= /* @noEscape */ $block->getAddress()->getPostcode(); ?>',
183-
regionId: '<?= /* @noEscape */ $block->getAddress()->getRegionId(); ?>',
184-
regionCode: '<?= /* @noEscape */ $block->getAddress()->getRegionCode() ?>',
185-
region: '<?= /* @noEscape */ $block->getAddress()->getRegion(); ?>',
174+
city: '<?= $block->escapeJs($block->getAddress()->getCity()); ?>',
175+
company: '<?= $block->escapeJs($block->getAddress()->getCompany()); ?>',
176+
countryId: '<?= $block->escapeJs($block->getAddress()->getCountryId()); ?>',
177+
customerAddressId: '<?= $block->escapeJs($block->getAddress()->getCustomerAddressId()); ?>',
178+
customerId: '<?= $block->escapeJs($block->getAddress()->getCustomerId()); ?>',
179+
fax: '<?= $block->escapeJs($block->getAddress()->getFax()); ?>',
180+
firstname: '<?= $block->escapeJs($block->getAddress()->getFirstname()); ?>',
181+
lastname: '<?= $block->escapeJs($block->getAddress()->getLastname()); ?>',
182+
postcode: '<?= $block->escapeJs($block->getAddress()->getPostcode()); ?>',
183+
regionId: '<?= $block->escapeJs($block->getAddress()->getRegionId()); ?>',
184+
regionCode: '<?= $block->escapeJs($block->getAddress()->getRegionCode()); ?>',
185+
region: '<?= $block->escapeJs($block->getAddress()->getRegion()); ?>',
186186
street: <?= /* @noEscape */ json_encode($block->getAddress()->getStreet()); ?>,
187-
telephone: '<?= /* @noEscape */ $block->getAddress()->getTelephone(); ?>'
187+
telephone: '<?= $block->escapeJs($block->getAddress()->getTelephone()); ?>'
188188
});
189189
});
190190
//]]>

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Exception;
11+
use Magento\Customer\Api\AccountManagementInterface;
1012
use Magento\Customer\Api\CustomerRepositoryInterface;
1113
use Magento\Customer\Model\CustomerAuthUpdate;
1214
use Magento\Customer\Model\CustomerRegistry;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\Integration\Api\AdminTokenServiceInterface;
1317
use Magento\Integration\Api\CustomerTokenServiceInterface;
1418
use Magento\TestFramework\Helper\Bootstrap;
19+
use Magento\TestFramework\Bootstrap as TestBootstrap;
1520
use Magento\TestFramework\TestCase\GraphQlAbstract;
1621

22+
/**
23+
* GraphQl tests for @see \Magento\CustomerGraphQl\Model\Customer\GetCustomer.
24+
*/
1725
class GetCustomerTest extends GraphQlAbstract
1826
{
1927
/**
@@ -36,14 +44,23 @@ class GetCustomerTest extends GraphQlAbstract
3644
*/
3745
private $customerRepository;
3846

47+
/**
48+
* @var ObjectManagerInterface
49+
*/
50+
private $objectManager;
51+
52+
/**
53+
* @inheridoc
54+
*/
3955
protected function setUp(): void
4056
{
4157
parent::setUp();
4258

43-
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
44-
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
45-
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
46-
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
59+
$this->objectManager = Bootstrap::getObjectManager();
60+
$this->customerTokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
61+
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
62+
$this->customerAuthUpdate = $this->objectManager->get(CustomerAuthUpdate::class);
63+
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
4764
}
4865

4966
/**
@@ -71,18 +88,19 @@ public function testGetCustomer()
7188
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
7289
);
7390

74-
$this->assertEquals(null, $response['customer']['id']);
91+
$this->assertNull($response['customer']['id']);
7592
$this->assertEquals('John', $response['customer']['firstname']);
7693
$this->assertEquals('Smith', $response['customer']['lastname']);
7794
$this->assertEquals($currentEmail, $response['customer']['email']);
7895
}
7996

8097
/**
81-
* @expectedException \Exception
82-
* @expectedExceptionMessage The current customer isn't authorized.
8398
*/
8499
public function testGetCustomerIfUserIsNotAuthorized()
85100
{
101+
$this->expectException(Exception::class);
102+
$this->expectExceptionMessage('The current customer isn\'t authorized.');
103+
86104
$query = <<<QUERY
87105
query {
88106
customer {
@@ -95,17 +113,49 @@ public function testGetCustomerIfUserIsNotAuthorized()
95113
$this->graphQlQuery($query);
96114
}
97115

116+
/**
117+
* @magentoApiDataFixture Magento/User/_files/user_with_role.php
118+
* @return void
119+
*/
120+
public function testGetCustomerIfUserHasWrongType(): void
121+
{
122+
/** @var $adminTokenService AdminTokenServiceInterface */
123+
$adminTokenService = $this->objectManager->get(AdminTokenServiceInterface::class);
124+
$adminToken = $adminTokenService->createAdminAccessToken('adminUser', TestBootstrap::ADMIN_PASSWORD);
125+
126+
$this->expectException(Exception::class);
127+
$this->expectExceptionMessage('The current customer isn\'t authorized.');
128+
129+
$query = <<<QUERY
130+
query {
131+
customer {
132+
firstname
133+
lastname
134+
email
135+
}
136+
}
137+
QUERY;
138+
$this->graphQlQuery(
139+
$query,
140+
[],
141+
'',
142+
['Authorization' => 'Bearer ' . $adminToken]
143+
);
144+
}
145+
98146
/**
99147
* @magentoApiDataFixture Magento/Customer/_files/customer.php
100-
* @expectedException \Exception
101-
* @expectedExceptionMessage The account is locked.
102148
*/
103149
public function testGetCustomerIfAccountIsLocked()
104150
{
105-
$this->lockCustomer(1);
106-
107151
$currentEmail = 'customer@example.com';
108152
$currentPassword = 'password';
153+
$customer = $this->customerRepository->get($currentEmail);
154+
155+
$this->lockCustomer((int)$customer->getId());
156+
157+
$this->expectException(Exception::class);
158+
$this->expectExceptionMessage('The account is locked.');
109159

110160
$query = <<<QUERY
111161
query {
@@ -125,18 +175,19 @@ public function testGetCustomerIfAccountIsLocked()
125175
}
126176

127177
/**
128-
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
178+
* @magentoConfigFixture customer/create_account/confirm 1
129179
* @magentoApiDataFixture Magento/Customer/_files/customer.php
130-
* @expectedExceptionMessage This account isn't confirmed. Verify and try again.
180+
*
131181
*/
132182
public function testAccountIsNotConfirmed()
133183
{
184+
$this->expectExceptionMessage("This account isn't confirmed. Verify and try again.");
134185
$customerEmail = 'customer@example.com';
135186
$currentPassword = 'password';
187+
$customer = $this->customerRepository->get($customerEmail);
136188
$headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword);
137-
$customer = $this->customerRepository->getById(1)->setConfirmation(
138-
\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
139-
);
189+
$customer = $this->customerRepository->getById((int)$customer->getId())
190+
->setConfirmation(AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED);
140191
$this->customerRepository->save($customer);
141192
$query = <<<QUERY
142193
query {
@@ -158,6 +209,7 @@ public function testAccountIsNotConfirmed()
158209
private function getCustomerAuthHeaders(string $email, string $password): array
159210
{
160211
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password);
212+
161213
return ['Authorization' => 'Bearer ' . $customerToken];
162214
}
163215

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\User\Model\User;
10+
11+
/** @var $model \Magento\User\Model\User */
12+
$model = Bootstrap::getObjectManager()->create(User::class);
13+
$user = $model->loadByUsername('adminUser');
14+
if ($user->getId()) {
15+
$model->delete();
16+
}

0 commit comments

Comments
 (0)