Skip to content

Commit

Permalink
Merge pull request #6667 from magento-tsg/2.4.3-develop-pr129
Browse files Browse the repository at this point in the history
[Condor] Fixes for 2.4 (pr129) (2.4.3-develop)
  • Loading branch information
zakdma authored Mar 8, 2021
2 parents 3a15828 + c6b6c10 commit 2f06a5d
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ public function execute()

$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
} catch (\Exception $e) {
} catch (LocalizedException $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
} catch (\Throwable $e) {
$result = ['error' => 'Something went wrong while saving the file(s).', 'errorcode' => 0];
}

/** @var \Magento\Framework\Controller\Result\Raw $response */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontRemoveFirstProductFromCompareActionGroup">
<annotations>
<description>Open Compare Products list and remove a product</description>
</annotations>

<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage"/>
<waitForElementVisible selector="{{StorefrontProductCompareMainSection.removeFirstItem}}" stepKey="waitForButton"/>
<click selector="{{StorefrontProductCompareMainSection.removeFirstItem}}" stepKey="clickOnButton"/>
<waitForElementVisible selector="{{ModalConfirmationSection.OkButton}}" stepKey="waitForModal"/>
<scrollTo selector="{{ModalConfirmationSection.OkButton}}" stepKey="scrollToModal"/>
<click selector="{{ModalConfirmationSection.OkButton}}" stepKey="ClickOkButton"/>
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<element name="ProductPriceByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//span[@class='price']" parameterized="true"/>
<element name="ProductImageByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//img[@class='product-image-photo']" parameterized="true"/>
<element name="ProductAttributeByCodeAndProductName" type="text" selector="//*[@id='product-comparison']//tr[.//th[./span[contains(text(), '{{var1}}')]]]//td[count(//*[@id='product-comparison']//tr//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var2}}')]]/preceding-sibling::td)+1]/div" parameterized="true"/>
<element name="removeFirstItem" type="button" selector="table.table-comparison a.delete"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPage">
<argument name="categoryName" value="$$category.name$$"/>
</actionGroup>

<actionGroup ref="StorefrontOpenAndCheckComparisionActionGroup" stepKey="navigateToComparePage"/>
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="navigateToComparePage"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForStorefrontProductComparePageLoad"/>

<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="seeProductInCompareList">
Expand All @@ -92,11 +91,13 @@
<argument name="categoryName" value="$$category.name$$"/>
</actionGroup>

<actionGroup ref="StorefrontClearCompareActionGroup" stepKey="clickClearAll"/>
<actionGroup ref="StorefrontRemoveFirstProductFromCompareActionGroup" stepKey="clickClearAll"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForConfirmPageLoad"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="confirmProdDelate"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForConfirmLoad"/>
<comment userInput="Add product to compare list fom Category page | Comment is kept to preserve the step key for backward compatibility" stepKey="addToCmpFromCategPage"/>
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="addToCmpFromCategPage">
<argument name="categoryName" value="$$category.name$$"/>
</actionGroup>

<actionGroup ref="StorefrontHoverProductOnCategoryPageActionGroup" stepKey="hoverOverProduct"/>

Expand All @@ -108,11 +109,11 @@
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="grabTextFromSuccessMessage2"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="assertSuccessMessage2"/>

<comment userInput="Check that product displays on add to compare widget | Comment is kept to preserve the step key for backward compatibility" stepKey="checkProdNameOnWidget"/>
<seeElement selector="{{StorefrontComparisonSidebarSection.ProductTitleByName($$product.name$$)}}" stepKey="seeProdNameOnCmpWidget"/>
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="checkProdNameOnWidget"/>
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="seeProdNameOnCmpWidget"/>

<comment userInput="See product in the compare page" stepKey="seeProductInComparePage"/>
<actionGroup ref="StorefrontOpenAndCheckComparisionActionGroup" stepKey="navigateToComparePage2"/>
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="navigateToComparePage2"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForStorefrontProductComparePageLoad2"/>

<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="seeProductInCompareList2">
Expand Down
59 changes: 59 additions & 0 deletions app/code/Magento/Customer/Model/Validator/Name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Model\Validator;

use Magento\Customer\Model\Customer;
use Magento\Framework\Validator\AbstractValidator;

/**
* Customer name fields validator.
*/
class Name extends AbstractValidator
{
private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'\s\d]){1,255}+/u';

/**
* Validate name fields.
*
* @param Customer $customer
* @return bool
*/
public function isValid($customer)
{
if (!$this->isValidName($customer->getFirstname())) {
parent::_addMessages([['firstname' => 'First Name is not valid!']]);
}

if (!$this->isValidName($customer->getLastname())) {
parent::_addMessages([['lastname' => 'Last Name is not valid!']]);
}

if (!$this->isValidName($customer->getMiddlename())) {
parent::_addMessages([['middlename' => 'Middle Name is not valid!']]);
}

return count($this->_messages) == 0;
}

/**
* Check if name field is valid.
*
* @param string|null $nameValue
* @return bool
*/
private function isValidName($nameValue)
{
if ($nameValue != null) {
if (preg_match(self::PATTERN_NAME, $nameValue, $matches)) {
return $matches[0] == $nameValue;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<before>
<createData entity="Simple_US_Customer" stepKey="createFirstCustomer"/>
<createData entity="Simple_US_Customer" stepKey="createSecondCustomer">
<field key="firstname">&quot;Jane Doe&quot;</field>
<field key="firstname">Jane Doe</field>
</createData>
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
</before>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
<test name="StorefrontVerifyNoXssInjectionOnUpdateCustomerInformationAddAddressTest">
<annotations>
<stories value="Update Customer Address"/>
<title value="[Security] Verify No XSS Injection on Update Customer Information Add Address"/>
<title value="DEPRECATED [Security] Verify No XSS Injection on Update Customer Information Add Address"/>
<description value="Test log in to Storefront and Verify No XSS Injection on Update Customer Information Add Address"/>
<testCaseId value="MC-10910"/>
<severity value="CRITICAL"/>
<group value="customer"/>
<group value="mtf_migrated"/>
<skip>
<issueId value="DEPRECATED">Test outdated</issueId>
</skip>
</annotations>

<before>
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Customer/etc/validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
<constraint alias="metadata_data_validator" class="Magento\Customer\Model\Metadata\Validator" />
</entity_constraints>
</rule>
<rule name="check_name">
<entity_constraints>
<constraint alias="name_validator" class="Magento\Customer\Model\Validator\Name" />
</entity_constraints>
</rule>
</rules>
<groups>
<group name="save">
<uses>
<use rule="check_eav"/>
<use rule="check_name"/>
</uses>
</group>
<group name="form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,204 @@ protected function _createCustomer(?array $additionalData = [])
$this->currentCustomerId[] = $customerData['id'];
return $customerData;
}

/**
* Test customer create with invalid name's.
*
* @param string $fieldName
* @param string $fieldValue
* @param string $expectedMessage
* @return void
*
* @dataProvider customerDataProvider
*/
public function testCreateCustomerWithInvalidCustomerFirstName(string $fieldName, string $fieldValue, string $expectedMessage): void
{
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
$this->customerHelper->createSampleCustomerDataObject(),
Customer::class
);
$customerData[$fieldName] = $fieldValue;

$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];

$requestData = ['customer' => $customerData];

try {
$this->_webApiCall($serviceInfo, $requestData);
$this->fail('Expected exception was not raised');
} catch (\SoapFault $e) {
$this->assertStringContainsString($expectedMessage, $e->getMessage());
} catch (\Exception $e) {
$errorObj = $this->processRestExceptionResult($e);
$this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
$this->assertEquals($expectedMessage, $errorObj['message']);
}
}

/**
* Invalid customer data provider
*
* @return array
*/
public function customerDataProvider(): array
{
return [
['firstname', 'Jane ☺ ', 'First Name is not valid!'],
['lastname', '☏ - Doe', 'Last Name is not valid!'],
['middlename', '⚐ $(date)', 'Middle Name is not valid!'],
[
'firstname',
str_repeat('खाना अच्छा है', 20),
'First Name is not valid!',
],
[
'lastname',
str_repeat('المغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول', 5),
'Last Name is not valid!',
],
];
}

/**
* Test customer create with ultibyte chanracters in name's.
*
* @param string $fieldName
* @param string $fieldValue
* @return void
*
* @dataProvider customerWithMultiByteDataProvider
*/
public function testCreateCustomerWithMultibyteCharacters(string $fieldName, string $fieldValue): void
{
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
$this->customerHelper->createSampleCustomerDataObject(),
Customer::class
);
$customerData[$fieldName] = $fieldValue;

$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];

$requestData = ['customer' => $customerData];

$response = $this->_webApiCall($serviceInfo, $requestData);

$this->assertNotNull($response);
$this->assertEquals($fieldValue, $response[$fieldName]);
}

/**
* Customer with multibyte characters data provider.
*
* @return array
*/
public function customerWithMultiByteDataProvider(): array
{
return [
[
'firstname',
str_repeat('हैखान', 51),
],
[
'lastname',
str_repeat('مغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول', 5),
],
];
}

/**
* Test customer create with valid name's.
*
* @param string $fieldName
* @param string $fieldValue
* @return void
*
* @dataProvider customerValidNameDataProvider
*/
public function testCreateCustomerWithValidName(string $fieldName, string $fieldValue): void
{
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
$this->customerHelper->createSampleCustomerDataObject(),
Customer::class
);
$customerData[$fieldName] = $fieldValue;

$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];

$requestData = ['customer' => $customerData];

$response = $this->_webApiCall($serviceInfo, $requestData);

$this->assertNotNull($response);
$this->assertEquals($fieldValue, $response[$fieldName]);
}

/**
* Customer valid name data provider.
*
* @return array
*/
public function customerValidNameDataProvider(): array
{
return [
[
'firstname',
'Anne-Marie',
],
[
'lastname',
'D\'Artagnan',
],
[
'lastname',
'Guðmundsdóttir',
],
[
'lastname',
'María José Carreño Quiñones',
],
[
'lastname',
'Q. Public',
],
[
'firstname',
'Elizabeth II',
],
[
'firstname',
'X Æ A-12 Musk',
],
];
}
}
Loading

0 comments on commit 2f06a5d

Please sign in to comment.