From b81b8007cabf2df892c32d1b92959f7934911f73 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:42:23 +0200 Subject: [PATCH 001/148] Update validation.xml --- app/code/Magento/Customer/etc/validation.xml | 41 +++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/etc/validation.xml b/app/code/Magento/Customer/etc/validation.xml index 7fd6cfeb79472..5f8539660d2cc 100644 --- a/app/code/Magento/Customer/etc/validation.xml +++ b/app/code/Magento/Customer/etc/validation.xml @@ -23,12 +23,30 @@ + + + + + + + + + + + + + + + + + + @@ -38,7 +56,6 @@ - @@ -51,9 +68,14 @@ - + - + + + + + + @@ -61,9 +83,14 @@ - + - + + + + + + @@ -72,9 +99,11 @@ + + + - From 766c50704479cd996ac014a9ab6a770282be2389 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:46:50 +0200 Subject: [PATCH 002/148] Update system.xml --- .../Magento/Security/etc/adminhtml/system.xml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/app/code/Magento/Security/etc/adminhtml/system.xml b/app/code/Magento/Security/etc/adminhtml/system.xml index a31e1b1949b1a..478e1c2663682 100644 --- a/app/code/Magento/Security/etc/adminhtml/system.xml +++ b/app/code/Magento/Security/etc/adminhtml/system.xml @@ -58,6 +58,66 @@ Limit the maximum session size in bytes. Use 0 to disable. + + + + + Magento\Config\Model\Config\Source\Yesno + Activate the extended field pattern function. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for city fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for name fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for telephone fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for street fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for e-mail fields. + + + + + 1 + + Enter one E-Mail or Host per line for banned validation. + + + + Magento\Config\Model\Config\Source\Yesno + Activate the extended pattern function to limit code injection. + +
From 69bd507e8c6a1e91d72c41d33bf61e41510eb13d Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:47:54 +0200 Subject: [PATCH 003/148] Create CityValidator.php --- .../Model/Validator/Pattern/CityValidator.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php new file mode 100644 index 0000000000000..2e7b0d721dbc2 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php @@ -0,0 +1,111 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and city validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + // Check if the global security pattern validation is enabled + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Check if the specific city validation is enabled + $isCityValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_CITY_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Return true only if both are enabled + return $isGlobalPatternEnabled && $isCityValidationEnabled; + } + + /** + * Validate the city value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return true; + } + + return preg_match(self::PATTERN_CITY, trim($value)) === 1; + } +} From 6085f20b79752e1684cb59f45846cc495c73f0ff Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:48:15 +0200 Subject: [PATCH 004/148] Create EmailAddressValidator.php --- .../Pattern/EmailAddressValidator.php | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php new file mode 100644 index 0000000000000..b37f43623ec91 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php @@ -0,0 +1,138 @@ +scopeConfig = $scopeConfig; + $this->emailValidator = $emailValidator; + } + + /** + * Check if both the global security pattern and email validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isEmailValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_EMAIL_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isEmailValidationEnabled; + } + + /** + * Validate an email address. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return false; + } + + if (!preg_match(self::PATTERN_EMAIL, trim($value))) { + return false; + } + + return $this->emailValidator->isValid($value); + } + + /** + * Check if the email address or its domain is blacklisted. + * + * @param string|null $emailValue + * @return bool + */ + public function isBlacklist(?string $emailValue): bool + { + if ($emailValue === null || $emailValue === '' || !is_string($emailValue)) { + return false; + } + + if ($this->blacklistArray === null) { + $blacklist = $this->scopeConfig->getValue(self::XML_PATH_SECURITY_PATTERN_MAIL_BLACKLIST); + $this->blacklistArray = !empty($blacklist) ? preg_split('/[\r\n,]+/', $blacklist) : []; + } + + $emailHost = substr(strrchr($emailValue, "@"), 1); + + return in_array($emailValue, $this->blacklistArray) || in_array($emailHost, $this->blacklistArray); + } +} From 7aec8a03aa7859cf99ebefdb0213f98ee993ef0a Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:48:42 +0200 Subject: [PATCH 005/148] Create ForbiddenValidator.php --- .../Validator/Pattern/ForbiddenValidator.php | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php new file mode 100644 index 0000000000000..39ea156551524 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php @@ -0,0 +1,129 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if forbidden patterns validation is enabled. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_CODE_INJECTION_ENABLED, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * Returns an array of forbidden patterns. + * + * @return string[] + */ + public function getPatterns(): array + { + return [ + '/{{.*}}/', + '/<\?=/', + '/<\?php/', + '/shell_exec/', + '/eval\(/', + '/\${IFS%/', + '/\bcurl\b/', + ]; + } + + /** + * Validates the given field value against forbidden patterns. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if (!$this->isValidationEnabled()) { + return true; + } + + return $this->validatePattern($value); + } + + /** + * Recursively validate data against forbidden patterns. + * + * @param mixed $data + * @return bool + */ + public function validateDataRecursively($data): bool + { + if (is_array($data)) { + foreach ($data as $value) { + if (!$this->validateDataRecursively($value)) { + return false; + } + } + } else { + return $this->isValid($data); + } + + return true; + } + + /** + * Validates the field value against forbidden patterns. + * + * @param mixed $value + * @return bool + */ + private function validatePattern(mixed $value): bool + { + if (!is_string($value) || trim($value) === '') { + return true; + } + + foreach ($this->getPatterns() as $pattern) { + if (preg_match($pattern, trim($value))) { + return false; + } + } + + if (preg_match('/base64_decode\(/', $value)) { + $decodedValue = base64_decode($value); + return $this->validatePattern($decodedValue); + } + + return true; + } +} From 34078fe4239473dca455d5efd2f243b55ba7ba81 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:49:06 +0200 Subject: [PATCH 006/148] Create NameValidator.php --- .../Model/Validator/Pattern/NameValidator.php | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php new file mode 100644 index 0000000000000..85fdb82d1da15 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php @@ -0,0 +1,112 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and name validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + // Check if the global security pattern validation is enabled + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Check if the specific name validation is enabled + $isNameValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Return true only if both are enabled + return $isGlobalPatternEnabled && $isNameValidationEnabled; + } + + /** + * Validate the name value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return true; + } + + return preg_match(self::PATTERN_NAME, trim($value)) === 1; + } +} From d85296833f66c4ea13c0591c11fc8b08de7d87fd Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:49:28 +0200 Subject: [PATCH 007/148] Create StreetValidator.php --- .../Validator/Pattern/StreetValidator.php | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php new file mode 100644 index 0000000000000..4a441f8e4cfb7 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php @@ -0,0 +1,145 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and street validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isStreetValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_STREET_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isStreetValidationEnabled; + } + + /** + * Validate a street address string or an array of street address strings. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if (!$this->isValidationEnabled()) { + return true; // Skip validation if globally disabled + } + + if (is_array($value)) { + foreach ($value as $streetValue) { + if (!$this->validateSingleStreet($streetValue)) { + return false; + } + } + } else { + if (!$this->validateSingleStreet($value)) { + return false; + } + } + + return true; + } + + /** + * Validate a single street address string. + * + * @param mixed $streetValue + * @return bool + */ + private function validateSingleStreet($streetValue): bool + { + return $this->isValidStreet($streetValue); + } + + /** + * Check if the street field is valid. + * + * @param mixed $streetValue + * @return bool + */ + private function isValidStreet(mixed $streetValue): bool + { + if ($streetValue === null || $streetValue === '' || !is_string($streetValue)) { + return true; + } + + return preg_match(self::PATTERN_STREET, trim($streetValue)) === 1; + } +} From f385efcc560d76345b6a9fa3e3f754c9b3ead77b Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:49:50 +0200 Subject: [PATCH 008/148] Create TelephoneValidator.php --- .../Validator/Pattern/TelephoneValidator.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php new file mode 100644 index 0000000000000..5bcda3ae19430 --- /dev/null +++ b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php @@ -0,0 +1,107 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and telephone validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + // Check if the global security pattern validation is enabled + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Check if the specific telephone validation is enabled + $isTelephoneValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_TELEPHONE_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Return true only if both are enabled + return $isGlobalPatternEnabled && $isTelephoneValidationEnabled; + } + + /** + * Validate the telephone value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '') { + return true; + } + + return preg_match(self::PATTERN_TELEPHONE, trim($value)) === 1; + } +} From 0da78a19faa5d46b5be24867cca5ea38535fda2e Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:50:52 +0200 Subject: [PATCH 009/148] Update CityTest.php --- .../Test/Unit/Model/Validator/CityTest.php | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 9c15427154fea..475d22061accb 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -7,79 +7,99 @@ namespace Magento\Customer\Test\Unit\Model\Validator; +use Magento\Customer\Model\Address; use Magento\Customer\Model\Validator\City; -use Magento\Customer\Model\Customer; +use Magento\Security\Model\Validator\Pattern\CityValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * Customer city validator tests + * City validator tests */ class CityTest extends TestCase { /** - * @var City + * @var CityValidator|MockObject */ - private City $nameValidator; + private MockObject $cityValidatorMock; /** - * @var Customer|MockObject + * @var Address|MockObject */ - private MockObject $customerMock; + private MockObject $addressMock; + + /** + * @var City + */ + private City $cityValidator; /** * @return void */ protected function setUp(): void { - $this->nameValidator = new City; - $this->customerMock = $this - ->getMockBuilder(Customer::class) - ->disableOriginalConstructor() - ->addMethods(['getCity']) - ->getMock(); + $this->cityValidatorMock = $this->createMock(CityValidator::class); + $this->addressMock = $this->createMock(Address::class); + $this->cityValidator = new City($this->cityValidatorMock); } /** - * Test for allowed apostrophe and other punctuation characters in customer names + * Test for allowed punctuation characters in city names * * @param string $city * @param string $message * @return void - * @dataProvider expectedPunctuationInNamesDataProvider + * @dataProvider expectedPunctuationInCityDataProvider */ - public function testValidateCorrectPunctuationInNames( + public function testValidateCorrectPunctuationInCities( string $city, string $message ) { - $this->customerMock->expects($this->once())->method('getCity')->willReturn($city); + $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); + $this->cityValidatorMock->expects($this->once())->method('isValid')->with($city)->willReturn(true); - $isValid = $this->nameValidator->isValid($this->customerMock); + $isValid = $this->cityValidator->isValid($this->addressMock); $this->assertTrue($isValid, $message); } /** * @return array */ - public function expectedPunctuationInNamesDataProvider(): array + public function expectedPunctuationInCityDataProvider(): array { return [ + [ + 'city' => 'New York', + 'message' => 'Spaces must be allowed in city names' + ], + [ + 'city' => 'São Paulo', + 'message' => 'Accented characters and spaces must be allowed in city names' + ], + [ + 'city' => 'St. Louis', + 'message' => 'Periods and spaces must be allowed in city names' + ], [ 'city' => 'Москва', - 'message' => 'Unicode letters must be allowed in city' + 'message' => 'Unicode letters must be allowed in city names' ], [ - 'city' => 'Мо́сква', - 'message' => 'Unicode marks must be allowed in city' + 'city' => 'Moscow \'', + 'message' => 'Apostrophe characters must be allowed in city names' ], [ - 'city' => ' Moscow \'', - 'message' => 'Apostrophe characters must be allowed in city' + 'city' => 'St.-Pierre', + 'message' => 'Hyphens must be allowed in city names' ], [ - 'city' => ' Moscow Moscow', - 'message' => 'Whitespace characters must be allowed in city' - ] + 'city' => 'Offenbach (Main)', + 'message' => 'Parentheses must be allowed in city names' + ], + [ + 'city' => 'Rome: The Eternal City', + 'message' => 'Colons must be allowed in city names' + ], ]; } } From 7c0e834ce2584d612e19067e694c3c2343a4f1be Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:51:07 +0200 Subject: [PATCH 010/148] Update NameTest.php --- .../Test/Unit/Model/Validator/NameTest.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 5033774d54494..2ea517a948299 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -7,8 +7,9 @@ namespace Magento\Customer\Test\Unit\Model\Validator; -use Magento\Customer\Model\Validator\Name; use Magento\Customer\Model\Customer; +use Magento\Customer\Model\Validator\Name; +use Magento\Security\Model\Validator\Pattern\NameValidator as PatternNameValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -17,6 +18,11 @@ */ class NameTest extends TestCase { + /** + * @var PatternNameValidator|MockObject + */ + private MockObject $patternNameValidatorMock; + /** * @var Name */ @@ -32,16 +38,17 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Name; + $this->patternNameValidatorMock = $this->createMock(PatternNameValidator::class); + $this->nameValidator = new Name($this->patternNameValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->addMethods(['getFirstname', 'getLastname', 'getMiddlename']) + ->addMethods(['getFirstname', 'getMiddlename', 'getLastname']) ->getMock(); } /** - * Test for allowed apostrophe and other punctuation characters in customer names + * Test for allowed punctuation characters in customer names * * @param string $firstName * @param string $middleName @@ -60,6 +67,11 @@ public function testValidateCorrectPunctuationInNames( $this->customerMock->expects($this->once())->method('getMiddlename')->willReturn($middleName); $this->customerMock->expects($this->once())->method('getLastname')->willReturn($lastName); + $this->patternNameValidatorMock->expects($this->exactly(3)) + ->method('isValid') + ->withConsecutive([$firstName], [$middleName], [$lastName]) + ->willReturn(true); + $isValid = $this->nameValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } @@ -73,25 +85,25 @@ public function expectedPunctuationInNamesDataProvider(): array [ 'firstName' => 'John', 'middleName' => '', - 'lastNameName' => 'O’Doe', + 'lastName' => 'O’Doe', 'message' => 'Inclined apostrophe must be allowed in names (iOS Smart Punctuation compatibility)' ], [ 'firstName' => 'John', 'middleName' => '', - 'lastNameName' => 'O\'Doe', + 'lastName' => 'O\'Doe', 'message' => 'Legacy straight apostrophe must be allowed in names' ], [ 'firstName' => 'John', 'middleName' => '', - 'lastNameName' => 'O`Doe', + 'lastName' => 'O`Doe', 'message' => 'Grave accent back quote character must be allowed in names' ], [ 'firstName' => 'John & Smith', 'middleName' => '', - 'lastNameName' => 'O`Doe', + 'lastName' => 'O`Doe', 'message' => 'Special character ampersand(&) must be allowed in names' ] ]; From 1a99616e60c81d62f1f5b74eaeab407b2e61a63d Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:51:21 +0200 Subject: [PATCH 011/148] Update StreetTest.php --- .../Test/Unit/Model/Validator/StreetTest.php | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 6d40bec460b3e..d9d50be5169af 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -8,6 +8,7 @@ namespace Magento\Customer\Test\Unit\Model\Validator; use Magento\Customer\Model\Validator\Street; +use Magento\Security\Model\Validator\Pattern\StreetValidator as PatternStreetValidator; use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -17,10 +18,15 @@ */ class StreetTest extends TestCase { + /** + * @var PatternStreetValidator|MockObject + */ + private MockObject $patternStreetValidatorMock; + /** * @var Street */ - private Street $nameValidator; + private Street $streetValidator; /** * @var Customer|MockObject @@ -32,7 +38,8 @@ class StreetTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Street; + $this->patternStreetValidatorMock = $this->createMock(PatternStreetValidator::class); + $this->streetValidator = new Street($this->patternStreetValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() @@ -41,27 +48,34 @@ protected function setUp(): void } /** - * Test for allowed apostrophe and other punctuation characters in customer names + * Test for allowed characters in street addresses * * @param array $street * @param string $message * @return void - * @dataProvider expectedPunctuationInNamesDataProvider + * @dataProvider expectedPunctuationInStreetDataProvider */ - public function testValidateCorrectPunctuationInNames( + public function testValidateCorrectPunctuationInStreet( array $street, string $message - ) { + ): void { $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); - $isValid = $this->nameValidator->isValid($this->customerMock); + $this->patternStreetValidatorMock->expects($this->exactly(count($street))) + ->method('isValid') + ->withConsecutive(...array_map(fn($s) => [$s], $street)) + ->willReturn(true); + + $isValid = $this->streetValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } /** + * Data provider for valid street names + * * @return array */ - public function expectedPunctuationInNamesDataProvider(): array + public function expectedPunctuationInStreetDataProvider(): array { return [ [ @@ -102,7 +116,7 @@ public function expectedPunctuationInNamesDataProvider(): array 'O`Connell Street', '321 Birch Boulevard ’Willow Retreat’' ], - 'message' => 'quotes must be allowed in street' + 'message' => 'Quotes must be allowed in street' ], [ 'street' => [ @@ -127,6 +141,14 @@ public function expectedPunctuationInNamesDataProvider(): array '876 Elm Way' ], 'message' => 'Digits must be allowed in street' + ], + [ + 'street' => [ + '1234 Elm St. [Apartment 5]', + 'Main St. (Suite 200)', + '456 Pine St. [Unit 10]' + ], + 'message' => 'Square brackets and parentheses must be allowed in street' ] ]; } From 725f570ac96ae2e15aafa160581c3f72f9c90188 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:51:34 +0200 Subject: [PATCH 012/148] Update TelephoneTest.php --- .../Unit/Model/Validator/TelephoneTest.php | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index 47a9d6da18831..14ca88bd8b7fd 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -8,6 +8,7 @@ namespace Magento\Customer\Test\Unit\Model\Validator; use Magento\Customer\Model\Validator\Telephone; +use Magento\Security\Model\Validator\Pattern\TelephoneValidator as PatternTelephoneValidator; use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -17,10 +18,15 @@ */ class TelephoneTest extends TestCase { + /** + * @var PatternTelephoneValidator|MockObject + */ + private MockObject $patternTelephoneValidatorMock; + /** * @var Telephone */ - private Telephone $nameValidator; + private Telephone $telephoneValidator; /** * @var Customer|MockObject @@ -32,53 +38,61 @@ class TelephoneTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Telephone; + $this->patternTelephoneValidatorMock = $this->createMock(PatternTelephoneValidator::class); + $this->telephoneValidator = new Telephone($this->patternTelephoneValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->addMethods(['getTelephone']) + ->addMethods(['getTelephone', 'getFax']) ->getMock(); } /** - * Test for allowed apostrophe and other punctuation characters in customer names + * Test for allowed punctuation characters in customer telephone numbers * * @param string $telephone + * @param string $fax * @param string $message * @return void - * @dataProvider expectedPunctuationInNamesDataProvider + * @dataProvider expectedPunctuationInTelephoneDataProvider */ - public function testValidateCorrectPunctuationInNames( + public function testValidateCorrectPunctuationInTelephone( string $telephone, + string $fax, string $message - ) { + ): void { $this->customerMock->expects($this->once())->method('getTelephone')->willReturn($telephone); + $this->customerMock->expects($this->once())->method('getFax')->willReturn($fax); - $isValid = $this->nameValidator->isValid($this->customerMock); + $this->patternTelephoneValidatorMock->expects($this->exactly(2)) + ->method('isValid') + ->withConsecutive([$telephone], [$fax]) + ->willReturn(true); + + $isValid = $this->telephoneValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } /** * @return array */ - public function expectedPunctuationInNamesDataProvider(): array + public function expectedPunctuationInTelephoneDataProvider(): array { return [ [ 'telephone' => '(1)99887766', - 'message' => 'parentheses must be allowed in telephone' + 'fax' => '123456789', + 'message' => 'Parentheses must be allowed in telephone, and digits must be allowed in fax.' ], [ 'telephone' => '+6255554444', - 'message' => 'plus sign be allowed in telephone' + 'fax' => '123 456 789', + 'message' => 'Plus sign must be allowed in telephone, and spaces must be allowed in fax.' ], [ 'telephone' => '555-555-555', - 'message' => 'hyphen must be allowed in telephone' - ], - [ - 'telephone' => '123456789', - 'message' => 'Digits (numbers) must be allowed in telephone' + 'fax' => '123/456/789', + 'message' => 'Hyphen must be allowed in telephone, and forward slashes must be allowed in fax.' ] ]; } From 50ea5a7b585cfbef7d2e3b97aabacb0be0bd23c6 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:52:50 +0200 Subject: [PATCH 013/148] Update City.php --- .../Magento/Customer/Model/Validator/City.php | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 0b53551dfd88f..79b3d79c4f3d7 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -1,14 +1,11 @@ cityValidator = $cityValidator; + } /** - * Validate city fields. + * Validate city field. * - * @param Customer $customer + * @param Customer $entity * @return bool */ - public function isValid($customer) + public function isValid($entity): bool { - if (!$this->isValidCity($customer->getCity())) { - parent::_addMessages([[ - 'city' => "Invalid City. Please use A-Z, a-z, 0-9, -, ', spaces" - ]]); + if (!$this->cityValidator->isValidationEnabled()) { + return true; + } + + $cityField = $entity->getCity(); + if (empty($cityField)) { + return true; + } + + if (!$this->validateCityField('City', $cityField)) { + parent::_addMessages([ + __('%1 is not valid! Allowed characters: %2', 'City', $this->cityValidator->allowedCharsDescription) + ]); } return count($this->_messages) == 0; } /** - * Check if city field is valid. + * Validate the city field. * + * @param string $fieldName * @param string|null $cityValue * @return bool */ - private function isValidCity($cityValue) + private function validateCityField(string $fieldName, ?string $cityValue): bool { - if ($cityValue != null) { - if (preg_match(self::PATTERN_CITY, $cityValue, $matches)) { - return $matches[0] == $cityValue; - } - } - - return true; + return $this->cityValidator->isValid($cityValue); } } From 90bdb2bc410f770ac9433fc744f2f633031803d3 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:53:31 +0200 Subject: [PATCH 014/148] Update Name.php --- .../Magento/Customer/Model/Validator/Name.php | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 75d460358970c..2d6c9c31417fc 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -1,21 +1,31 @@ nameValidator = $nameValidator; + } /** * Validate name fields. @@ -23,37 +33,38 @@ class Name extends AbstractValidator * @param Customer $customer * @return bool */ - public function isValid($customer) + public function isValid($customer): bool { - if (!$this->isValidName($customer->getFirstname())) { - parent::_addMessages([['firstname' => 'First Name is not valid!']]); + if (!$this->nameValidator->isValidationEnabled()) { + return true; } - if (!$this->isValidName($customer->getLastname())) { - parent::_addMessages([['lastname' => 'Last Name is not valid!']]); - } + $nameFields = [ + 'Firstname' => $customer->getFirstname(), + 'Lastname' => $customer->getLastname(), + 'Middlename' => $customer->getMiddlename() + ]; - if (!$this->isValidName($customer->getMiddlename())) { - parent::_addMessages([['middlename' => 'Middle Name is not valid!']]); + foreach ($nameFields as $fieldName => $fieldValue) { + if (!empty($fieldValue) && !$this->isValidName($fieldName, $fieldValue)) { + parent::_addMessages([ + __('%1 is not valid! Allowed characters: %2', $fieldName, $this->nameValidator->allowedCharsDescription) + ]); + } } return count($this->_messages) == 0; } /** - * Check if name field is valid. + * Check if name field is valid using the NameValidator. * + * @param string $fieldName * @param string|null $nameValue * @return bool */ - private function isValidName($nameValue) + private function isValidName(string $fieldName, ?string $nameValue): bool { - if ($nameValue != null) { - if (preg_match(self::PATTERN_NAME, $nameValue, $matches)) { - return $matches[0] == $nameValue; - } - } - - return true; + return $this->nameValidator->isValid($nameValue); } } From e3888f7cebaa13f35dac63ac00fec783a09bdfdb Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:53:51 +0200 Subject: [PATCH 015/148] Update Street.php --- .../Customer/Model/Validator/Street.php | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index 7de57d0ed32ef..167ff31b7c240 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -1,14 +1,11 @@ streetValidator = $streetValidator; + } /** - * Validate street fields. + * Validate street field. * * @param Customer $customer * @return bool */ - public function isValid($customer) + public function isValid($customer): bool { - foreach ($customer->getStreet() as $street) { - if (!$this->isValidStreet($street)) { - parent::_addMessages([[ - 'street' => "Invalid Street Address. Please use A-Z, a-z, 0-9, , - . ' ’ ` & spaces" - ]]); + if (!$this->streetValidator->isValidationEnabled()) { + return true; + } + + $streets = $customer->getStreet(); + if (empty($streets)) { + return true; + } + + // Prüfen, ob "street" ein Array ist und jede Zeile validieren + foreach ($streets as $street) { + if (!$this->validateStreetField('Street', $street)) { + parent::_addMessages([ + 'street' => __('Street is not valid! Allowed characters: %1', $this->streetValidator->allowedCharsDescription) + ]); } } @@ -50,19 +57,14 @@ public function isValid($customer) } /** - * Check if street field is valid. + * Validate the street field. * + * @param string $fieldName * @param string|null $streetValue * @return bool */ - private function isValidStreet($streetValue) + private function validateStreetField(string $fieldName, ?string $streetValue): bool { - if ($streetValue != null) { - if (preg_match(self::PATTERN_STREET, $streetValue, $matches)) { - return $matches[0] == $streetValue; - } - } - - return true; + return $this->streetValidator->isValid($streetValue); } } From 8e4abb443e94fb937f2b852a5a4477c94c9254cd Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:54:05 +0200 Subject: [PATCH 016/148] Update Telephone.php --- .../Customer/Model/Validator/Telephone.php | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index 0c85cb51f7e3d..76f995615401f 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -1,14 +1,11 @@ telephoneValidator = $telephoneValidator; + } + /** * Validate telephone fields. * * @param Customer $customer * @return bool */ - public function isValid($customer) + public function isValid($customer): bool { - if (!$this->isValidTelephone($customer->getTelephone())) { - parent::_addMessages([[ - 'telephone' => "Invalid Phone Number. Please use 0-9, +, -, (, ) and space." - ]]); + if (!$this->telephoneValidator->isValidationEnabled()) { + return true; + } + + $telephoneFields = [ + 'Phone Number' => $customer->getTelephone(), + 'Fax Number' => $customer->getFax() + ]; + + foreach ($telephoneFields as $fieldName => $fieldValue) { + if (!empty($fieldValue) && !$this->validateTelephoneField($fieldName, $fieldValue)) { + parent::_addMessages([ + __('%1 is not valid! Allowed characters: %2', $fieldName, $this->telephoneValidator->allowedCharsDescription) + ]); + } } return count($this->_messages) == 0; } /** - * Check if telephone field is valid. + * Validate a single telephone field. * - * @param string|null $telephoneValue + * @param string $fieldName + * @param mixed $telephoneValue * @return bool */ - private function isValidTelephone($telephoneValue) + private function validateTelephoneField(string $fieldName, mixed $telephoneValue): bool { - if ($telephoneValue != null) { - if (preg_match(self::PATTERN_TELEPHONE, (string) $telephoneValue, $matches)) { - return $matches[0] == $telephoneValue; - } - } - - return true; + return $this->telephoneValidator->isValid($telephoneValue); } } From 5d77af39f60b8e66b003ef6c45c43ceb9a350f17 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:54:28 +0200 Subject: [PATCH 017/148] Create ForbiddenPattern.php --- .../Model/Validator/ForbiddenPattern.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php diff --git a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php new file mode 100644 index 0000000000000..bd9c3d38fbe57 --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php @@ -0,0 +1,62 @@ +forbiddenValidator = $forbiddenValidator; + } + + /** + * Validate EAV data fields against forbidden patterns. + * + * @param mixed $customer + * @return bool + * @throws LocalizedException + */ + public function isValid($customer): bool + { + if (!$this->forbiddenValidator->isValidationEnabled()) { + return true; + } + + $customerData = $customer->getData(); + if (empty($customerData)) { + return true; + } + + $isValid = $this->forbiddenValidator->validateDataRecursively($customerData); + + if (!$isValid) { + parent::_addMessages([ + __('Fraud Protection: Forbidden pattern detected in customer data') + ]); + } + + return count($this->_messages) == 0; + } +} From c7d5611569c995a0b46f4e6365dc290744b920b1 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:54:49 +0200 Subject: [PATCH 018/148] Create Email.php --- .../Customer/Model/Validator/Email.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Email.php diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php new file mode 100644 index 0000000000000..3edefd83086ae --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -0,0 +1,90 @@ +emailValidator = $emailValidator; + } + + /** + * Validate email fields. + * + * @param Customer $customer + * @return bool + */ + public function isValid($customer): bool + { + if (!$this->emailValidator->isValidationEnabled()) { + return true; + } + + $email = $customer->getEmail(); + if (empty($email)) { + return true; + } + + if (!$this->validateEmailField('Email', $email)) { + return false; + } + + return count($this->_messages) == 0; + } + + /** + * Validate the email field. + * + * @param string $fieldName + * @param string|null $emailValue + * @return bool + */ + private function validateEmailField(string $fieldName, ?string $emailValue): bool + { + if (!$this->emailValidator->isValid($emailValue)) { + parent::_addMessages([ + "Email address is not valid! Allowed characters: {$this->emailValidator->allowedCharsDescription}" + ]); + return false; + } + + if ($this->isBlacklistEmail($emailValue)) { + parent::_addMessages([ + __('The email address or domain is blacklisted.') + ]); + return false; + } + + return true; + } + + /** + * Check if email field is blacklisted using the EmailAddressValidator. + * + * @param string|null $emailValue + * @return bool + */ + private function isBlacklistEmail(?string $emailValue): bool + { + return $this->emailValidator->isBlacklist($emailValue); + } +} From da066b0bc01d12b368f78dc05d4594b889f37be4 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 10:56:41 +0200 Subject: [PATCH 019/148] Update City.php --- app/code/Magento/Customer/Model/Validator/City.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 79b3d79c4f3d7..ba8781a1da53b 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:56:56 +0200 Subject: [PATCH 020/148] Update Email.php --- app/code/Magento/Customer/Model/Validator/Email.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php index 3edefd83086ae..9a72b97af88c5 100644 --- a/app/code/Magento/Customer/Model/Validator/Email.php +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:57:14 +0200 Subject: [PATCH 021/148] Update Name.php --- app/code/Magento/Customer/Model/Validator/Name.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 2d6c9c31417fc..2e42978205a40 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:57:38 +0200 Subject: [PATCH 022/148] Update Street.php --- app/code/Magento/Customer/Model/Validator/Street.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index 167ff31b7c240..2df309126368e 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:58:00 +0200 Subject: [PATCH 023/148] Update Telephone.php --- app/code/Magento/Customer/Model/Validator/Telephone.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index 76f995615401f..c5e61a123dd01 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:58:36 +0200 Subject: [PATCH 024/148] Update ForbiddenValidator.php --- .../Security/Model/Validator/Pattern/ForbiddenValidator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php index 39ea156551524..5d96427ed5933 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php @@ -1,4 +1,8 @@ Date: Sat, 31 Aug 2024 10:59:20 +0200 Subject: [PATCH 025/148] Update StreetValidator.php --- .../Security/Model/Validator/Pattern/StreetValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php index 4a441f8e4cfb7..d18d3aab5cec4 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php @@ -53,7 +53,7 @@ class StreetValidator extends AbstractValidator * * @var string */ - public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, )'; + public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, ), /, \,'; /** * @var ScopeConfigInterface From 0c7194bfea4f073c0d203bb055a8af94e5b8646a Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 11:00:58 +0200 Subject: [PATCH 026/148] Update StreetValidator.php --- .../Security/Model/Validator/Pattern/StreetValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php index d18d3aab5cec4..004d1e8ddea67 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php @@ -53,7 +53,7 @@ class StreetValidator extends AbstractValidator * * @var string */ - public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, ), /, \,'; + public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, ), /'; /** * @var ScopeConfigInterface From 5108578a8816a262a26ce10002db78df666fdcd6 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 12:00:40 +0200 Subject: [PATCH 027/148] Update module.xml --- app/code/Magento/Customer/etc/module.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Customer/etc/module.xml b/app/code/Magento/Customer/etc/module.xml index 853157fed1f5d..030786d4741b1 100644 --- a/app/code/Magento/Customer/etc/module.xml +++ b/app/code/Magento/Customer/etc/module.xml @@ -10,6 +10,7 @@ + From a4ea99d34a97f2d561a037f9aafa40bf50b091a5 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:16:21 +0200 Subject: [PATCH 028/148] Update TelephoneTest.php --- .../Unit/Model/Validator/TelephoneTest.php | 123 ++++++++++++------ 1 file changed, 84 insertions(+), 39 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index 14ca88bd8b7fd..c701865238962 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -7,26 +7,20 @@ namespace Magento\Customer\Test\Unit\Model\Validator; -use Magento\Customer\Model\Validator\Telephone; -use Magento\Security\Model\Validator\Pattern\TelephoneValidator as PatternTelephoneValidator; +use Magento\Customer\Model\Validator\Street; use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * Customer telephone validator tests + * Customer street validator tests */ -class TelephoneTest extends TestCase +class StreetTest extends TestCase { /** - * @var PatternTelephoneValidator|MockObject + * @var Street */ - private MockObject $patternTelephoneValidatorMock; - - /** - * @var Telephone - */ - private Telephone $telephoneValidator; + private Street $streetValidator; /** * @var Customer|MockObject @@ -38,61 +32,112 @@ class TelephoneTest extends TestCase */ protected function setUp(): void { - $this->patternTelephoneValidatorMock = $this->createMock(PatternTelephoneValidator::class); - $this->telephoneValidator = new Telephone($this->patternTelephoneValidatorMock); + // PatternStreetValidator is not directly mocked anymore. + $this->streetValidator = $this->createMock(Street::class); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->addMethods(['getTelephone', 'getFax']) + ->addMethods(['getStreet']) ->getMock(); } /** - * Test for allowed punctuation characters in customer telephone numbers + * Test for allowed characters in street addresses * - * @param string $telephone - * @param string $fax + * @param array $street * @param string $message * @return void - * @dataProvider expectedPunctuationInTelephoneDataProvider + * @dataProvider expectedPunctuationInStreetDataProvider */ - public function testValidateCorrectPunctuationInTelephone( - string $telephone, - string $fax, + public function testValidateCorrectPunctuationInStreet( + array $street, string $message ): void { - $this->customerMock->expects($this->once())->method('getTelephone')->willReturn($telephone); - $this->customerMock->expects($this->once())->method('getFax')->willReturn($fax); + $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); - $this->patternTelephoneValidatorMock->expects($this->exactly(2)) - ->method('isValid') - ->withConsecutive([$telephone], [$fax]) - ->willReturn(true); - - $isValid = $this->telephoneValidator->isValid($this->customerMock); + $isValid = $this->streetValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } /** + * Data provider for valid street names + * * @return array */ - public function expectedPunctuationInTelephoneDataProvider(): array + public function expectedPunctuationInStreetDataProvider(): array { return [ [ - 'telephone' => '(1)99887766', - 'fax' => '123456789', - 'message' => 'Parentheses must be allowed in telephone, and digits must be allowed in fax.' + 'street' => [ + "123 Rue de l'Étoile", + "Ville d'Ölives, Çôte d'Azur", + "Çôte d'Azur" + ], + 'message' => 'Unicode marks and Unicode letters must be allowed in street' + ], + [ + 'street' => [ + '876 Elm Way, Redwood Lodge', + '456 Pine Street, Serenity Cottage', + '321 Birch Boulevard, Willow Retreat' + ], + 'message' => 'Comma must be allowed in street' + ], + [ + 'street' => [ + '321 Birch Boulevard-Retreat', + '234 Spruce Place-Residence', + '456 Pine Street-Haven' + ], + 'message' => 'Hyphen must be allowed in street' + ], + [ + 'street' => [ + '1234 Elm St.', + 'Main. Street', + '1234 Elm St' + ], + 'message' => 'Period must be allowed in street' + ], + [ + 'street' => [ + 'O\'Connell Street', + 'O`Connell Street', + '321 Birch Boulevard ’Willow Retreat’' + ], + 'message' => 'Quotes must be allowed in street' + ], + [ + 'street' => [ + '123 Main Street & Elm Avenue', + '456 Pine Street & Maple Avenue', + '789 Oak Lane & Cedar Road' + ], + 'message' => 'Ampersand must be allowed in street' + ], + [ + 'street' => [ + 'Oak Lane Space', + 'Birch Boulevard Space', + 'Spruce Place' + ], + 'message' => 'Whitespace must be allowed in street' ], [ - 'telephone' => '+6255554444', - 'fax' => '123 456 789', - 'message' => 'Plus sign must be allowed in telephone, and spaces must be allowed in fax.' + 'street' => [ + '234 Spruce Place', + '321 Birch Boulevard', + '876 Elm Way' + ], + 'message' => 'Digits must be allowed in street' ], [ - 'telephone' => '555-555-555', - 'fax' => '123/456/789', - 'message' => 'Hyphen must be allowed in telephone, and forward slashes must be allowed in fax.' + 'street' => [ + '1234 Elm St. [Apartment 5]', + 'Main St. (Suite 200)', + '456 Pine St. [Unit 10]' + ], + 'message' => 'Square brackets and parentheses must be allowed in street' ] ]; } From a4364bff93cc16fb879bf20bc77f2716aaadb8d3 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:17:11 +0200 Subject: [PATCH 029/148] Update StreetTest.php --- .../Test/Unit/Model/Validator/StreetTest.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index d9d50be5169af..c701865238962 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Test\Unit\Model\Validator; use Magento\Customer\Model\Validator\Street; -use Magento\Security\Model\Validator\Pattern\StreetValidator as PatternStreetValidator; use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -18,11 +17,6 @@ */ class StreetTest extends TestCase { - /** - * @var PatternStreetValidator|MockObject - */ - private MockObject $patternStreetValidatorMock; - /** * @var Street */ @@ -38,8 +32,8 @@ class StreetTest extends TestCase */ protected function setUp(): void { - $this->patternStreetValidatorMock = $this->createMock(PatternStreetValidator::class); - $this->streetValidator = new Street($this->patternStreetValidatorMock); + // PatternStreetValidator is not directly mocked anymore. + $this->streetValidator = $this->createMock(Street::class); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() @@ -61,11 +55,6 @@ public function testValidateCorrectPunctuationInStreet( ): void { $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); - $this->patternStreetValidatorMock->expects($this->exactly(count($street))) - ->method('isValid') - ->withConsecutive(...array_map(fn($s) => [$s], $street)) - ->willReturn(true); - $isValid = $this->streetValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } From 10c41bc9e35c4956bf3822310797093d07f71f8a Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:19:10 +0200 Subject: [PATCH 030/148] Update NameTest.php --- .../Test/Unit/Model/Validator/NameTest.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 2ea517a948299..8818d67407a7e 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -9,7 +9,6 @@ use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Name; -use Magento\Security\Model\Validator\Pattern\NameValidator as PatternNameValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -18,11 +17,6 @@ */ class NameTest extends TestCase { - /** - * @var PatternNameValidator|MockObject - */ - private MockObject $patternNameValidatorMock; - /** * @var Name */ @@ -38,8 +32,7 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->patternNameValidatorMock = $this->createMock(PatternNameValidator::class); - $this->nameValidator = new Name($this->patternNameValidatorMock); + $this->nameValidator = new Name(); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() @@ -62,16 +55,11 @@ public function testValidateCorrectPunctuationInNames( string $middleName, string $lastName, string $message - ) { + ): void { $this->customerMock->expects($this->once())->method('getFirstname')->willReturn($firstName); $this->customerMock->expects($this->once())->method('getMiddlename')->willReturn($middleName); $this->customerMock->expects($this->once())->method('getLastname')->willReturn($lastName); - $this->patternNameValidatorMock->expects($this->exactly(3)) - ->method('isValid') - ->withConsecutive([$firstName], [$middleName], [$lastName]) - ->willReturn(true); - $isValid = $this->nameValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } From 5b113abd1b106fc165a37a1f0af9f4c9b8254548 Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:20:54 +0200 Subject: [PATCH 031/148] Update CityTest.php --- .../Customer/Test/Unit/Model/Validator/CityTest.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 475d22061accb..3b00bd7f09780 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -9,7 +9,6 @@ use Magento\Customer\Model\Address; use Magento\Customer\Model\Validator\City; -use Magento\Security\Model\Validator\Pattern\CityValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -18,11 +17,6 @@ */ class CityTest extends TestCase { - /** - * @var CityValidator|MockObject - */ - private MockObject $cityValidatorMock; - /** * @var Address|MockObject */ @@ -38,9 +32,8 @@ class CityTest extends TestCase */ protected function setUp(): void { - $this->cityValidatorMock = $this->createMock(CityValidator::class); $this->addressMock = $this->createMock(Address::class); - $this->cityValidator = new City($this->cityValidatorMock); + $this->cityValidator = new City(); } /** @@ -54,9 +47,8 @@ protected function setUp(): void public function testValidateCorrectPunctuationInCities( string $city, string $message - ) { + ): void { $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); - $this->cityValidatorMock->expects($this->once())->method('isValid')->with($city)->willReturn(true); $isValid = $this->cityValidator->isValid($this->addressMock); $this->assertTrue($isValid, $message); From 90e86ecddf344638345073a470716ca420998eba Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:22:44 +0200 Subject: [PATCH 032/148] Update TelephoneTest.php --- .../Unit/Model/Validator/TelephoneTest.php | 111 +++++------------- 1 file changed, 27 insertions(+), 84 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index c701865238962..78b0ab5bb1399 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -7,20 +7,20 @@ namespace Magento\Customer\Test\Unit\Model\Validator; -use Magento\Customer\Model\Validator\Street; +use Magento\Customer\Model\Validator\Telephone; use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * Customer street validator tests + * Customer telephone validator tests */ -class StreetTest extends TestCase +class TelephoneTest extends TestCase { /** - * @var Street + * @var Telephone */ - private Street $streetValidator; + private Telephone $telephoneValidator; /** * @var Customer|MockObject @@ -32,112 +32,55 @@ class StreetTest extends TestCase */ protected function setUp(): void { - // PatternStreetValidator is not directly mocked anymore. - $this->streetValidator = $this->createMock(Street::class); + $this->telephoneValidator = new Telephone(); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->addMethods(['getStreet']) + ->addMethods(['getTelephone', 'getFax']) ->getMock(); } /** - * Test for allowed characters in street addresses + * Test for allowed punctuation characters in customer telephone numbers * - * @param array $street + * @param string $telephone + * @param string $fax * @param string $message * @return void - * @dataProvider expectedPunctuationInStreetDataProvider + * @dataProvider expectedPunctuationInTelephoneDataProvider */ - public function testValidateCorrectPunctuationInStreet( - array $street, + public function testValidateCorrectPunctuationInTelephone( + string $telephone, + string $fax, string $message ): void { - $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); + $this->customerMock->expects($this->once())->method('getTelephone')->willReturn($telephone); + $this->customerMock->expects($this->once())->method('getFax')->willReturn($fax); - $isValid = $this->streetValidator->isValid($this->customerMock); + $isValid = $this->telephoneValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } /** - * Data provider for valid street names - * * @return array */ - public function expectedPunctuationInStreetDataProvider(): array + public function expectedPunctuationInTelephoneDataProvider(): array { return [ [ - 'street' => [ - "123 Rue de l'Étoile", - "Ville d'Ölives, Çôte d'Azur", - "Çôte d'Azur" - ], - 'message' => 'Unicode marks and Unicode letters must be allowed in street' - ], - [ - 'street' => [ - '876 Elm Way, Redwood Lodge', - '456 Pine Street, Serenity Cottage', - '321 Birch Boulevard, Willow Retreat' - ], - 'message' => 'Comma must be allowed in street' - ], - [ - 'street' => [ - '321 Birch Boulevard-Retreat', - '234 Spruce Place-Residence', - '456 Pine Street-Haven' - ], - 'message' => 'Hyphen must be allowed in street' - ], - [ - 'street' => [ - '1234 Elm St.', - 'Main. Street', - '1234 Elm St' - ], - 'message' => 'Period must be allowed in street' - ], - [ - 'street' => [ - 'O\'Connell Street', - 'O`Connell Street', - '321 Birch Boulevard ’Willow Retreat’' - ], - 'message' => 'Quotes must be allowed in street' - ], - [ - 'street' => [ - '123 Main Street & Elm Avenue', - '456 Pine Street & Maple Avenue', - '789 Oak Lane & Cedar Road' - ], - 'message' => 'Ampersand must be allowed in street' - ], - [ - 'street' => [ - 'Oak Lane Space', - 'Birch Boulevard Space', - 'Spruce Place' - ], - 'message' => 'Whitespace must be allowed in street' + 'telephone' => '(1)99887766', + 'fax' => '123456789', + 'message' => 'Parentheses must be allowed in telephone, and digits must be allowed in fax.' ], [ - 'street' => [ - '234 Spruce Place', - '321 Birch Boulevard', - '876 Elm Way' - ], - 'message' => 'Digits must be allowed in street' + 'telephone' => '+6255554444', + 'fax' => '123 456 789', + 'message' => 'Plus sign must be allowed in telephone, and spaces must be allowed in fax.' ], [ - 'street' => [ - '1234 Elm St. [Apartment 5]', - 'Main St. (Suite 200)', - '456 Pine St. [Unit 10]' - ], - 'message' => 'Square brackets and parentheses must be allowed in street' + 'telephone' => '555-555-555', + 'fax' => '123/456/789', + 'message' => 'Hyphen must be allowed in telephone, and forward slashes must be allowed in fax.' ] ]; } From c4273832244c5c421d432579d4268aebf44428df Mon Sep 17 00:00:00 2001 From: in-session Date: Sat, 31 Aug 2024 14:24:12 +0200 Subject: [PATCH 033/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 3b00bd7f09780..06e5329c0ec02 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -7,7 +7,7 @@ namespace Magento\Customer\Test\Unit\Model\Validator; -use Magento\Customer\Model\Address; +use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\City; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; From 1e4755e2e35fea260eeef65a98ba85f09a3c8399 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 09:44:52 +0200 Subject: [PATCH 034/148] Update NameTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/NameTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 8818d67407a7e..ae3cd943b7e81 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -32,7 +32,7 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Name(); + $this->nameValidator = new Name; $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() @@ -55,7 +55,7 @@ public function testValidateCorrectPunctuationInNames( string $middleName, string $lastName, string $message - ): void { + ) { $this->customerMock->expects($this->once())->method('getFirstname')->willReturn($firstName); $this->customerMock->expects($this->once())->method('getMiddlename')->willReturn($middleName); $this->customerMock->expects($this->once())->method('getLastname')->willReturn($lastName); From 7451237fbc0ef5a68da6ed91078416c4b89b68cc Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:41:41 +0200 Subject: [PATCH 035/148] Update City.php --- app/code/Magento/Customer/Model/Validator/City.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index ba8781a1da53b..c18750c1dd35c 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -50,7 +50,8 @@ public function isValid($entity): bool if (!$this->validateCityField('City', $cityField)) { parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', 'City', $this->cityValidator->allowedCharsDescription) + __('%1 is not valid! Allowed characters: %2', + 'City', $this->cityValidator->allowedCharsDescription) ]); } From 5b52bb8d1e364e2f237b0d22f10a3a0960c8a3e0 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:42:01 +0200 Subject: [PATCH 036/148] Update Email.php --- app/code/Magento/Customer/Model/Validator/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php index 9a72b97af88c5..b3989947801a1 100644 --- a/app/code/Magento/Customer/Model/Validator/Email.php +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -58,15 +58,15 @@ public function isValid($customer): bool /** * Validate the email field. * - * @param string $fieldName * @param string|null $emailValue * @return bool */ - private function validateEmailField(string $fieldName, ?string $emailValue): bool + private function validateEmailField(?string $emailValue): bool { if (!$this->emailValidator->isValid($emailValue)) { parent::_addMessages([ - "Email address is not valid! Allowed characters: {$this->emailValidator->allowedCharsDescription}" + __('Email address is not valid! Allowed characters: %1', + $this->emailValidator->allowedCharsDescription) ]); return false; } From 013e6fcf4b62830039b27d2dc264d6f3daf1a791 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:42:17 +0200 Subject: [PATCH 037/148] Update ForbiddenPattern.php --- app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php index bd9c3d38fbe57..60d230da7b0e8 100644 --- a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php +++ b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php @@ -44,7 +44,7 @@ public function isValid($customer): bool return true; } - $customerData = $customer->getData(); + $customerData = $customer->getData(); if (empty($customerData)) { return true; } From 86b079557c50ff219c823fa5556f1515af95f841 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:42:41 +0200 Subject: [PATCH 038/148] Update Name.php --- app/code/Magento/Customer/Model/Validator/Name.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 2e42978205a40..2a1f796200ddd 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -39,9 +39,6 @@ public function __construct(NameValidator $nameValidator) */ public function isValid($customer): bool { - if (!$this->nameValidator->isValidationEnabled()) { - return true; - } $nameFields = [ 'Firstname' => $customer->getFirstname(), @@ -50,9 +47,11 @@ public function isValid($customer): bool ]; foreach ($nameFields as $fieldName => $fieldValue) { - if (!empty($fieldValue) && !$this->isValidName($fieldName, $fieldValue)) { + if (!empty($fieldValue) && !$this->isValidName($fieldValue)) { parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', $fieldName, $this->nameValidator->allowedCharsDescription) + __('%1 is not valid! Allowed characters: %2', + $fieldName, + $this->nameValidator->allowedCharsDescription) ]); } } @@ -63,11 +62,10 @@ public function isValid($customer): bool /** * Check if name field is valid using the NameValidator. * - * @param string $fieldName * @param string|null $nameValue * @return bool */ - private function isValidName(string $fieldName, ?string $nameValue): bool + private function isValidName(?string $nameValue): bool { return $this->nameValidator->isValid($nameValue); } From 10f261c331058eaf07356d9985a486484c91f4fa Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:43:02 +0200 Subject: [PATCH 039/148] Update Street.php --- app/code/Magento/Customer/Model/Validator/Street.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index 2df309126368e..6ae65c482f65a 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -52,7 +52,8 @@ public function isValid($customer): bool foreach ($streets as $street) { if (!$this->validateStreetField('Street', $street)) { parent::_addMessages([ - 'street' => __('Street is not valid! Allowed characters: %1', $this->streetValidator->allowedCharsDescription) + 'street' => __('Street is not valid! Allowed characters: %1', + $this->streetValidator->allowedCharsDescription) ]); } } @@ -63,11 +64,10 @@ public function isValid($customer): bool /** * Validate the street field. * - * @param string $fieldName * @param string|null $streetValue * @return bool */ - private function validateStreetField(string $fieldName, ?string $streetValue): bool + private function validateStreetField(?string $streetValue): bool { return $this->streetValidator->isValid($streetValue); } From e1529aa5ff0c2360daeec3d5526ea9d7d0da280c Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:43:36 +0200 Subject: [PATCH 040/148] Update Telephone.php --- app/code/Magento/Customer/Model/Validator/Telephone.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index c5e61a123dd01..ac75decade6a4 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -51,7 +51,8 @@ public function isValid($customer): bool foreach ($telephoneFields as $fieldName => $fieldValue) { if (!empty($fieldValue) && !$this->validateTelephoneField($fieldName, $fieldValue)) { parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', $fieldName, $this->telephoneValidator->allowedCharsDescription) + __('%1 is not valid! Allowed characters: %2', + $fieldName, $this->telephoneValidator->allowedCharsDescription) ]); } } From ce30adc94398a907245d218c240409d9526dbc5f Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:44:10 +0200 Subject: [PATCH 041/148] Update CityValidator.php --- .../Security/Model/Validator/Pattern/CityValidator.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php index 2e7b0d721dbc2..cb4dda46dc837 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php @@ -16,7 +16,7 @@ */ class CityValidator extends AbstractValidator { - /** + /** * Allowed characters: * * \p{L}: Unicode letters. @@ -32,9 +32,8 @@ class CityValidator extends AbstractValidator * \/: Forward slash. * \\\\: Backslash (double escaped for regex). */ - private const PATTERN_CITY = '/^[\p{L}\p{M}\s\-\.\'\&\[\]\(\):\/\\\\]{1,255}$/u'; + public string $patternCity = '/^[\p{L}\p{M}\s\-\.\'\&\[\]\(\):\/\\\\]{1,255}$/u'; - /** * XML path for regex validation. * @@ -106,6 +105,6 @@ public function isValid($value): bool return true; } - return preg_match(self::PATTERN_CITY, trim($value)) === 1; + return preg_match($this->patternCity, trim($value)) === 1; } } From 87d5a54dafb8d269e68dd7fc501999e68dcb6c03 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:44:33 +0200 Subject: [PATCH 042/148] Update EmailAddressValidator.php --- .../Model/Validator/Pattern/EmailAddressValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php index b37f43623ec91..23c469bd03920 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php @@ -18,7 +18,7 @@ class EmailAddressValidator extends AbstractValidator implements ValidatorInterf /** * Pattern for email validation. */ - private const PATTERN_EMAIL = '/^[^@]+@[^@]+\.[a-zA-Z]{2,}$/'; + public string $patterEmail = '/^[^@]+@[^@]+\.[a-zA-Z]{2,}$/'; /** * XML path for global security pattern validation. @@ -107,7 +107,7 @@ public function isValid($value): bool return false; } - if (!preg_match(self::PATTERN_EMAIL, trim($value))) { + if (!preg_match($this->patterEmail, trim($value))) { return false; } From 6fe4aa59bd37abc6b7ed05219431d41c7bcd0e74 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:46:05 +0200 Subject: [PATCH 043/148] Update ForbiddenValidator.php --- .../Security/Model/Validator/Pattern/ForbiddenValidator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php index 5d96427ed5933..ad9ba5121c4e0 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php @@ -124,6 +124,7 @@ private function validatePattern(mixed $value): bool } if (preg_match('/base64_decode\(/', $value)) { + // Use of base64_decode is discouraged, ensure this is safe in your context $decodedValue = base64_decode($value); return $this->validatePattern($decodedValue); } From b619942223476e405429a94155627d0c6cfa77fe Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:46:41 +0200 Subject: [PATCH 044/148] Update NameValidator.php --- .../Model/Validator/Pattern/NameValidator.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php index 85fdb82d1da15..ec5a363ebb06a 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php @@ -16,6 +16,8 @@ */ class NameValidator extends AbstractValidator { + private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'’`&\s\d]){1,255}+/u'; + /** * Allowed characters for validating names: * @@ -34,7 +36,7 @@ class NameValidator extends AbstractValidator * * The pattern ensures that a name can be between 1 and 255 characters long. */ - private const PATTERN_NAME = '/^(?:[\p{L}\p{M},\-_.\'’`&\s\d]{1,255})$/u'; + public string $patternName = '/^(?:[\p{L}\p{M},\-_.\'’`&\s\d]{1,255})$/u'; /** * XML path for regex validation. @@ -60,7 +62,7 @@ class NameValidator extends AbstractValidator /** * @var ScopeConfigInterface */ - private $scopeConfig; + private ScopeConfigInterface $scopeConfig; /** * Constructor. @@ -81,13 +83,13 @@ public function isValidationEnabled(): bool { // Check if the global security pattern validation is enabled $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, + self::XML_PATH_SECURITY_PATTERN_ENABLED, ScopeInterface::SCOPE_STORE ); // Check if the specific name validation is enabled $isNameValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, + self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, ScopeInterface::SCOPE_STORE ); @@ -107,6 +109,8 @@ public function isValid($value): bool return true; } - return preg_match(self::PATTERN_NAME, trim($value)) === 1; + $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; + + return preg_match($pattern, trim($value)) === 1; } } From 88a2e089e1121951a9706dfd896321ba5d3b6197 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:47:02 +0200 Subject: [PATCH 045/148] Update StreetValidator.php --- .../Security/Model/Validator/Pattern/StreetValidator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php index 004d1e8ddea67..be8c83764d459 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php @@ -32,7 +32,7 @@ class StreetValidator extends AbstractValidator * \[\]: Square brackets. * \(\): Parentheses. */ - private const PATTERN_STREET = "/^[\p{L}\p{M}\,\-\.\'’`&\s\d\[\]\(\)]{1,255}$/u"; + public string $patterStreet = "/^[\p{L}\p{M}\,\-\.\'’`&\s\d\[\]\(\)]{1,255}$/u"; /** * XML path for global security pattern validation. @@ -53,7 +53,7 @@ class StreetValidator extends AbstractValidator * * @var string */ - public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, ), /'; + public string $allowedCharsDescription = 'A-Z, a-z, 0-9, -, ., \', ’, `, &, space, [, ], (, )'; /** * @var ScopeConfigInterface @@ -140,6 +140,6 @@ private function isValidStreet(mixed $streetValue): bool return true; } - return preg_match(self::PATTERN_STREET, trim($streetValue)) === 1; + return preg_match($this->$patterStreet, trim($streetValue)) === 1; } } From 26348b649dbff288ae302cb88828928580af3d10 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 12:47:23 +0200 Subject: [PATCH 046/148] Update TelephoneValidator.php --- .../Model/Validator/Pattern/TelephoneValidator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php index 5bcda3ae19430..cc3d0f8da6420 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php @@ -29,7 +29,7 @@ class TelephoneValidator extends AbstractValidator * * The pattern ensures that a phone number can be between 1 and 40 characters long. */ - private const PATTERN_TELEPHONE = '/^[\d\s\+\-\()\/]{1,40}$/u'; + public string $patternTelephone = '/^[\d\s\+\-\()\/]{1,40}$/u'; /** * XML path for regex validation. @@ -76,13 +76,13 @@ public function isValidationEnabled(): bool { // Check if the global security pattern validation is enabled $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, + self::XML_PATH_SECURITY_PATTERN_ENABLED, ScopeInterface::SCOPE_STORE ); // Check if the specific telephone validation is enabled $isTelephoneValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_TELEPHONE_ENABLED, + self::XML_PATH_SECURITY_PATTERN_TELEPHONE_ENABLED, ScopeInterface::SCOPE_STORE ); @@ -102,6 +102,6 @@ public function isValid($value): bool return true; } - return preg_match(self::PATTERN_TELEPHONE, trim($value)) === 1; + return preg_match($this->patternTelephone, trim($value)) === 1; } } From 993dc1f1ab4e90b43b76e03998f47b0ea7d99dd5 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 13:02:51 +0200 Subject: [PATCH 047/148] Update CityTest.php --- .../Test/Unit/Model/Validator/CityTest.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 06e5329c0ec02..74deaeb369a2b 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -5,56 +5,63 @@ */ declare(strict_types=1); -namespace Magento\Customer\Test\Unit\Model\Validator; +namespace Magento\Customer\Test\Unit\Model\Address\Validator; -use Magento\Customer\Model\Customer; +use Magento\Customer\Model\Address\AbstractAddress; use Magento\Customer\Model\Validator\City; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * City validator tests + * Test for validating city field in address. */ class CityTest extends TestCase { /** - * @var Address|MockObject + * @var City */ - private MockObject $addressMock; + private City $cityValidator; /** - * @var City + * @var AbstractAddress|MockObject */ - private City $cityValidator; + private MockObject $addressMock; /** * @return void */ protected function setUp(): void { - $this->addressMock = $this->createMock(Address::class); $this->cityValidator = new City(); + + $this->addressMock = $this + ->getMockBuilder(AbstractAddress::class) + ->disableOriginalConstructor() + ->addMethods(['getCity']) + ->getMock(); } /** - * Test for allowed punctuation characters in city names + * Test for valid city name * * @param string $city - * @param string $message + * @param bool $expectedIsValid * @return void * @dataProvider expectedPunctuationInCityDataProvider */ - public function testValidateCorrectPunctuationInCities( - string $city, - string $message + public function testValidateCityName( + string $city, + bool $expectedIsValid ): void { $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); - $isValid = $this->cityValidator->isValid($this->addressMock); + $isValid = $this->cityValidator->isValid($city); $this->assertTrue($isValid, $message); } /** + * Data provider for city names + * * @return array */ public function expectedPunctuationInCityDataProvider(): array From d8eea400d155a85077260f917d78de65720eba7d Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 13:06:06 +0200 Subject: [PATCH 048/148] Update StreetTest.php --- .../Test/Unit/Model/Validator/StreetTest.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index c701865238962..4295998688879 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -5,15 +5,15 @@ */ declare(strict_types=1); -namespace Magento\Customer\Test\Unit\Model\Validator; +namespace Magento\Customer\Test\Unit\Model\Address\Validator; +use Magento\Customer\Model\Address\AbstractAddress; use Magento\Customer\Model\Validator\Street; -use Magento\Customer\Model\Customer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * Customer street validator tests + * Test for validating street field in address. */ class StreetTest extends TestCase { @@ -23,44 +23,44 @@ class StreetTest extends TestCase private Street $streetValidator; /** - * @var Customer|MockObject + * @var AbstractAddress|MockObject */ - private MockObject $customerMock; + private MockObject $addressMock; /** * @return void */ protected function setUp(): void { - // PatternStreetValidator is not directly mocked anymore. - $this->streetValidator = $this->createMock(Street::class); - $this->customerMock = $this - ->getMockBuilder(Customer::class) + $this->streetValidator = new Street(); + + $this->addressMock = $this + ->getMockBuilder(AbstractAddress::class) ->disableOriginalConstructor() ->addMethods(['getStreet']) - ->getMock(); + ->getMock(); } /** - * Test for allowed characters in street addresses + * Test for valid street name * * @param array $street * @param string $message * @return void * @dataProvider expectedPunctuationInStreetDataProvider */ - public function testValidateCorrectPunctuationInStreet( - array $street, + public function testValidateStreetName( + array $street, string $message ): void { - $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); + $this->addressMock->expects($this->once())->method('getStreet')->willReturn($street); - $isValid = $this->streetValidator->isValid($this->customerMock); + $isValid = $this->streetValidator->isValid($street); $this->assertTrue($isValid, $message); } /** - * Data provider for valid street names + * Data provider for street names * * @return array */ From 0d18b39172410ca416a3e2d5d90ff30f5427e708 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 13:56:56 +0200 Subject: [PATCH 049/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 74deaeb369a2b..dc2a9f06f8cf8 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -7,7 +7,7 @@ namespace Magento\Customer\Test\Unit\Model\Address\Validator; -use Magento\Customer\Model\Address\AbstractAddress; +use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\City; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -35,7 +35,7 @@ protected function setUp(): void $this->cityValidator = new City(); $this->addressMock = $this - ->getMockBuilder(AbstractAddress::class) + ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getCity']) ->getMock(); From b07860635960a1aa5ed6e2b955a8e5404ff020e8 Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 13:57:17 +0200 Subject: [PATCH 050/148] Update StreetTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/StreetTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 4295998688879..80478d7a50154 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -7,7 +7,7 @@ namespace Magento\Customer\Test\Unit\Model\Address\Validator; -use Magento\Customer\Model\Address\AbstractAddress; +use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Street; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -35,7 +35,7 @@ protected function setUp(): void $this->streetValidator = new Street(); $this->addressMock = $this - ->getMockBuilder(AbstractAddress::class) + ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getStreet']) ->getMock(); From cc800cfc314fa10e8eab9b534868536fb1aeb27d Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 14:31:04 +0200 Subject: [PATCH 051/148] Update CityTest.php --- .../Customer/Test/Unit/Model/Validator/CityTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index dc2a9f06f8cf8..8aefb48c3db67 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -34,11 +34,11 @@ protected function setUp(): void { $this->cityValidator = new City(); - $this->addressMock = $this + $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getCity']) - ->getMock(); + ->getMock(); } /** @@ -51,11 +51,11 @@ protected function setUp(): void */ public function testValidateCityName( string $city, - bool $expectedIsValid + string $message ): void { - $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); + $this->customerMock->expects($this->once())->method('getCity')->willReturn($city); - $isValid = $this->cityValidator->isValid($city); + $isValid = $this->cityValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } From 5f14dd357af174a30ac10d52174c10c64727b30e Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 14:32:59 +0200 Subject: [PATCH 052/148] Update StreetTest.php --- .../Test/Unit/Model/Validator/StreetTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 80478d7a50154..8512092148f2b 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -23,9 +23,9 @@ class StreetTest extends TestCase private Street $streetValidator; /** - * @var AbstractAddress|MockObject + * @var Customer|MockObject */ - private MockObject $addressMock; + private MockObject $customerMock; /** * @return void @@ -34,11 +34,11 @@ protected function setUp(): void { $this->streetValidator = new Street(); - $this->addressMock = $this + $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getStreet']) - ->getMock(); + ->getMock(); } /** @@ -50,12 +50,12 @@ protected function setUp(): void * @dataProvider expectedPunctuationInStreetDataProvider */ public function testValidateStreetName( - array $street, + array $street, string $message ): void { - $this->addressMock->expects($this->once())->method('getStreet')->willReturn($street); + $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); - $isValid = $this->streetValidator->isValid($street); + $isValid = $this->streetValidator->isValid($this->customerMock); $this->assertTrue($isValid, $message); } From d64fe96287e717944cc56ddd82c1c40a12f51d4e Mon Sep 17 00:00:00 2001 From: in-session Date: Sun, 1 Sep 2024 14:34:26 +0200 Subject: [PATCH 053/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 8aefb48c3db67..f5f7aca6e8344 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -23,9 +23,9 @@ class CityTest extends TestCase private City $cityValidator; /** - * @var AbstractAddress|MockObject + * @var Customer|MockObject */ - private MockObject $addressMock; + private MockObject $customerMock; /** * @return void @@ -50,7 +50,7 @@ protected function setUp(): void * @dataProvider expectedPunctuationInCityDataProvider */ public function testValidateCityName( - string $city, + string $city, string $message ): void { $this->customerMock->expects($this->once())->method('getCity')->willReturn($city); From c0c82382bd3d1dc5e13c91b093af95bcb375270f Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 05:33:34 +0200 Subject: [PATCH 054/148] Update StreetTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/StreetTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 8512092148f2b..29a2dc170f049 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Customer\Test\Unit\Model\Address\Validator; +namespace Magento\Customer\Test\Unit\Model\Validator; use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Street; From 525ed5e1da12757040c24f0858f0e4b1f02e4c56 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 05:33:56 +0200 Subject: [PATCH 055/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index f5f7aca6e8344..d8a706cbbf922 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Customer\Test\Unit\Model\Address\Validator; +namespace Magento\Customer\Test\Unit\Model\Validator; use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\City; From dcf5ce8fd9a2c9c96c4668cc6ae79e105e304830 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:17:39 +0200 Subject: [PATCH 056/148] Update City.php --- .../Magento/Customer/Model/Validator/City.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index c18750c1dd35c..164396a8398aa 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -48,11 +48,16 @@ public function isValid($entity): bool return true; } - if (!$this->validateCityField('City', $cityField)) { - parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', - 'City', $this->cityValidator->allowedCharsDescription) - ]); + if (!$this->validateCityField($cityField)) { + parent::_addMessages( + [ + __( + '%1 is not valid! Allowed characters: %2', + 'City', + $this->cityValidator->allowedCharsDescription + ), + ] + ); } return count($this->_messages) == 0; @@ -61,11 +66,10 @@ public function isValid($entity): bool /** * Validate the city field. * - * @param string $fieldName * @param string|null $cityValue * @return bool */ - private function validateCityField(string $fieldName, ?string $cityValue): bool + private function validateCityField(?string $cityValue): bool { return $this->cityValidator->isValid($cityValue); } From ff31362109caec94cd5068c2766cb4462346a335 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:18:17 +0200 Subject: [PATCH 057/148] Update Email.php --- app/code/Magento/Customer/Model/Validator/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php index b3989947801a1..22b3dc0bb349d 100644 --- a/app/code/Magento/Customer/Model/Validator/Email.php +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -48,7 +48,7 @@ public function isValid($customer): bool return true; } - if (!$this->validateEmailField('Email', $email)) { + if (!$this->validateEmailField($email)) { return false; } From 3fc867d685cca77757624491997896e19e67b781 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:18:34 +0200 Subject: [PATCH 058/148] Update ForbiddenPattern.php From 2431ded4fbfcc78d9489ab4a0819a7904b5fac36 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:18:55 +0200 Subject: [PATCH 059/148] Update Name.php --- app/code/Magento/Customer/Model/Validator/Name.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 2a1f796200ddd..47f243156a932 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -48,11 +48,15 @@ public function isValid($customer): bool foreach ($nameFields as $fieldName => $fieldValue) { if (!empty($fieldValue) && !$this->isValidName($fieldValue)) { - parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', - $fieldName, - $this->nameValidator->allowedCharsDescription) - ]); + parent::_addMessages( + [ + __( + '%1 is not valid! Allowed characters: %2', + $fieldName, + $this->nameValidator->allowedCharsDescription + ), + ] + ); } } From 39d58a61e1ae4483878f75a7d92a03bc71b1af5b Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:19:17 +0200 Subject: [PATCH 060/148] Update Street.php --- .../Magento/Customer/Model/Validator/Street.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index 6ae65c482f65a..764eb2b851324 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -48,13 +48,16 @@ public function isValid($customer): bool return true; } - // Prüfen, ob "street" ein Array ist und jede Zeile validieren foreach ($streets as $street) { - if (!$this->validateStreetField('Street', $street)) { - parent::_addMessages([ - 'street' => __('Street is not valid! Allowed characters: %1', - $this->streetValidator->allowedCharsDescription) - ]); + if (!$this->validateStreetField($street)) { + parent::_addMessages( + [ + 'street' => __( + 'Street is not valid! Allowed characters: %1', + $this->streetValidator->allowedCharsDescription + ), + ] + ); } } From ea79f902d1fa41d1117d0403682afd795bfffdba Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:19:38 +0200 Subject: [PATCH 061/148] Update Telephone.php --- .../Customer/Model/Validator/Telephone.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index ac75decade6a4..ede6bb7f52afe 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -49,11 +49,16 @@ public function isValid($customer): bool ]; foreach ($telephoneFields as $fieldName => $fieldValue) { - if (!empty($fieldValue) && !$this->validateTelephoneField($fieldName, $fieldValue)) { - parent::_addMessages([ - __('%1 is not valid! Allowed characters: %2', - $fieldName, $this->telephoneValidator->allowedCharsDescription) - ]); + if (!empty($fieldValue) && !$this->validateTelephoneField($fieldValue)) { + parent::_addMessages( + [ + __( + '%1 is not valid! Allowed characters: %2', + $fieldName, + $this->telephoneValidator->allowedCharsDescription + ), + ] + ); } } @@ -63,11 +68,10 @@ public function isValid($customer): bool /** * Validate a single telephone field. * - * @param string $fieldName - * @param mixed $telephoneValue + * @param int|string|null $telephoneValue * @return bool */ - private function validateTelephoneField(string $fieldName, mixed $telephoneValue): bool + private function validateTelephoneField(int|string|null $telephoneValue): bool { return $this->telephoneValidator->isValid($telephoneValue); } From 730a85702e7549c002ba7566e66d52a68ac5b941 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:19:58 +0200 Subject: [PATCH 062/148] Update CityTest.php --- .../Test/Unit/Model/Validator/CityTest.php | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index d8a706cbbf922..8b2c709870b55 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\City; +use Magento\Security\Model\Validator\Pattern\CityValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,23 +23,29 @@ class CityTest extends TestCase */ private City $cityValidator; + /** + * @var CityValidator|MockObject + */ + private MockObject $cityValidatorMock; + /** * @var Customer|MockObject */ - private MockObject $customerMock; + private MockObject $addressMock; /** * @return void */ protected function setUp(): void { - $this->cityValidator = new City(); - - $this->customerMock = $this + $this->cityValidatorMock = $this->createMock(CityValidator::class); + $this->cityValidator = new City($this->cityValidatorMock); + + $this->addressMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getCity']) - ->getMock(); + ->getMock(); } /** @@ -50,13 +57,13 @@ protected function setUp(): void * @dataProvider expectedPunctuationInCityDataProvider */ public function testValidateCityName( - string $city, - string $message + string $city, + bool $expectedIsValid ): void { - $this->customerMock->expects($this->once())->method('getCity')->willReturn($city); + $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); - $isValid = $this->cityValidator->isValid($this->customerMock); - $this->assertTrue($isValid, $message); + $isValid = $this->cityValidator->isValid($this->addressMock); + $this->assertEquals($expectedIsValid, $isValid); } /** @@ -69,34 +76,42 @@ public function expectedPunctuationInCityDataProvider(): array return [ [ 'city' => 'New York', + 'expectedIsValid' => true, 'message' => 'Spaces must be allowed in city names' ], [ 'city' => 'São Paulo', + 'expectedIsValid' => true, 'message' => 'Accented characters and spaces must be allowed in city names' ], [ 'city' => 'St. Louis', + 'expectedIsValid' => true, 'message' => 'Periods and spaces must be allowed in city names' ], [ 'city' => 'Москва', + 'expectedIsValid' => true, 'message' => 'Unicode letters must be allowed in city names' ], [ 'city' => 'Moscow \'', + 'expectedIsValid' => true, 'message' => 'Apostrophe characters must be allowed in city names' ], [ 'city' => 'St.-Pierre', + 'expectedIsValid' => true, 'message' => 'Hyphens must be allowed in city names' ], [ 'city' => 'Offenbach (Main)', + 'expectedIsValid' => true, 'message' => 'Parentheses must be allowed in city names' ], [ 'city' => 'Rome: The Eternal City', + 'expectedIsValid' => true, 'message' => 'Colons must be allowed in city names' ], ]; From 367477156625c33cc29be1b3472d805d7d8799d1 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:20:17 +0200 Subject: [PATCH 063/148] Update NameTest.php --- .../Test/Unit/Model/Validator/NameTest.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index ae3cd943b7e81..7059ba8286afd 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -7,8 +7,9 @@ namespace Magento\Customer\Test\Unit\Model\Validator; -use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Name; +use Magento\Customer\Model\Customer; +use Magento\Security\Model\Validator\Pattern\NameValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,6 +23,11 @@ class NameTest extends TestCase */ private Name $nameValidator; + /** + * @var NameValidator|MockObject + */ + private MockObject $nameValidatorMock; + /** * @var Customer|MockObject */ @@ -32,11 +38,12 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Name; + $this->nameValidatorMock = $this->createMock(NameValidator::class); + $this->nameValidator = new Name($this->nameValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->addMethods(['getFirstname', 'getMiddlename', 'getLastname']) + ->addMethods(['getFirstname', 'getLastname', 'getMiddlename']) ->getMock(); } @@ -73,25 +80,25 @@ public function expectedPunctuationInNamesDataProvider(): array [ 'firstName' => 'John', 'middleName' => '', - 'lastName' => 'O’Doe', + 'lastNameName' => 'O’Doe', 'message' => 'Inclined apostrophe must be allowed in names (iOS Smart Punctuation compatibility)' ], [ 'firstName' => 'John', 'middleName' => '', - 'lastName' => 'O\'Doe', + 'lastNameName' => 'O\'Doe', 'message' => 'Legacy straight apostrophe must be allowed in names' ], [ 'firstName' => 'John', 'middleName' => '', - 'lastName' => 'O`Doe', + 'lastNameName' => 'O`Doe', 'message' => 'Grave accent back quote character must be allowed in names' ], [ 'firstName' => 'John & Smith', 'middleName' => '', - 'lastName' => 'O`Doe', + 'lastNameName' => 'O`Doe', 'message' => 'Special character ampersand(&) must be allowed in names' ] ]; From 6d888d2145f621b3bbde2d1a4e12bfeac91dae9e Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:20:57 +0200 Subject: [PATCH 064/148] Update StreetTest.php --- .../Test/Unit/Model/Validator/StreetTest.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 29a2dc170f049..f0de4c1ec326c 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Street; +use Magento\Security\Model\Validator\Pattern\StreetValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,23 +23,29 @@ class StreetTest extends TestCase */ private Street $streetValidator; + /** + * @var StreetValidator|MockObject + */ + private MockObject $streetValidatorMock; + /** * @var Customer|MockObject */ - private MockObject $customerMock; + private MockObject $addressMock; /** * @return void */ protected function setUp(): void { - $this->streetValidator = new Street(); + $this->streetValidatorMock = $this->createMock(StreetValidator::class); + $this->streetValidator = new Street($this->streetValidatorMock); - $this->customerMock = $this + $this->addressMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getStreet']) - ->getMock(); + ->getMock(); } /** @@ -50,12 +57,12 @@ protected function setUp(): void * @dataProvider expectedPunctuationInStreetDataProvider */ public function testValidateStreetName( - array $street, + array $street, string $message ): void { - $this->customerMock->expects($this->once())->method('getStreet')->willReturn($street); + $this->addressMock->expects($this->once())->method('getStreet')->willReturn($street); - $isValid = $this->streetValidator->isValid($this->customerMock); + $isValid = $this->streetValidator->isValid($this->addressMock); $this->assertTrue($isValid, $message); } From 3221234614d1d0d0ff99ed77ae2be15f80889a71 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:21:15 +0200 Subject: [PATCH 065/148] Update TelephoneTest.php --- .../Customer/Test/Unit/Model/Validator/TelephoneTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index 78b0ab5bb1399..3719ff44a1725 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\Validator\Telephone; use Magento\Customer\Model\Customer; +use Magento\Security\Model\Validator\Pattern\TelephoneValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,6 +23,11 @@ class TelephoneTest extends TestCase */ private Telephone $telephoneValidator; + /** + * @var TelephoneValidator|MockObject + */ + private MockObject $telephoneValidatorMock; + /** * @var Customer|MockObject */ @@ -32,7 +38,8 @@ class TelephoneTest extends TestCase */ protected function setUp(): void { - $this->telephoneValidator = new Telephone(); + $this->telephoneValidatorMock = $this->createMock(TelephoneValidator::class); + $this->telephoneValidator = new Telephone($this->telephoneValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() From 3187b67ca45ed945ed5d3e6142cd911d873344a3 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:21:36 +0200 Subject: [PATCH 066/148] Update CityValidator.php --- .../Security/Model/Validator/Pattern/CityValidator.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php index cb4dda46dc837..4a47a6a27a5c4 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php @@ -77,19 +77,16 @@ public function __construct(ScopeConfigInterface $scopeConfig) */ public function isValidationEnabled(): bool { - // Check if the global security pattern validation is enabled $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, + self::XML_PATH_SECURITY_PATTERN_ENABLED, ScopeInterface::SCOPE_STORE ); - // Check if the specific city validation is enabled $isCityValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_CITY_ENABLED, + self::XML_PATH_SECURITY_PATTERN_CITY_ENABLED, ScopeInterface::SCOPE_STORE ); - // Return true only if both are enabled return $isGlobalPatternEnabled && $isCityValidationEnabled; } From 395e0c453f129f06faea60de0a0858fcf40c8a0e Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:22:02 +0200 Subject: [PATCH 067/148] Update EmailAddressValidator.php --- .../Model/Validator/Pattern/EmailAddressValidator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php index 23c469bd03920..53bea4bd34f59 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php @@ -13,10 +13,15 @@ use Magento\Framework\Validator\ValidatorInterface; use Magento\Framework\Validator\EmailAddress; +/** + * Email fields pattern validator. + */ class EmailAddressValidator extends AbstractValidator implements ValidatorInterface { /** * Pattern for email validation. + * + * @var string */ public string $patterEmail = '/^[^@]+@[^@]+\.[a-zA-Z]{2,}$/'; From 43bcc105adf1c5f48dbddd126323dbd754fca818 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:22:29 +0200 Subject: [PATCH 068/148] Update ForbiddenValidator.php --- .../Security/Model/Validator/Pattern/ForbiddenValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php index ad9ba5121c4e0..2971099b9a442 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php @@ -46,7 +46,7 @@ public function __construct(ScopeConfigInterface $scopeConfig) public function isValidationEnabled(): bool { return $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_CODE_INJECTION_ENABLED, + self::XML_PATH_SECURITY_CODE_INJECTION_ENABLED, ScopeInterface::SCOPE_STORE ); } From 6d96c737264646345fa60fdf18b85392e38db709 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:22:48 +0200 Subject: [PATCH 069/148] Update NameValidator.php --- .../Security/Model/Validator/Pattern/NameValidator.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php index ec5a363ebb06a..3cc143001a532 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php @@ -16,6 +16,11 @@ */ class NameValidator extends AbstractValidator { + /** + * Main Pattern + * + * @var string + */ private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'’`&\s\d]){1,255}+/u'; /** @@ -35,6 +40,8 @@ class NameValidator extends AbstractValidator * \d: Digits (0-9), to allow names that include numbers, such as "John Doe II". * * The pattern ensures that a name can be between 1 and 255 characters long. + * + * @var string */ public string $patternName = '/^(?:[\p{L}\p{M},\-_.\'’`&\s\d]{1,255})$/u'; @@ -81,19 +88,16 @@ public function __construct(ScopeConfigInterface $scopeConfig) */ public function isValidationEnabled(): bool { - // Check if the global security pattern validation is enabled $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( self::XML_PATH_SECURITY_PATTERN_ENABLED, ScopeInterface::SCOPE_STORE ); - // Check if the specific name validation is enabled $isNameValidationEnabled = $this->scopeConfig->isSetFlag( self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, ScopeInterface::SCOPE_STORE ); - // Return true only if both are enabled return $isGlobalPatternEnabled && $isNameValidationEnabled; } From 7349fc45d5f86a4978be58d6dfbe103c677a7b6f Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:23:15 +0200 Subject: [PATCH 070/148] Update StreetValidator.php --- .../Security/Model/Validator/Pattern/StreetValidator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php index be8c83764d459..4eea2d9353993 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php @@ -31,6 +31,8 @@ class StreetValidator extends AbstractValidator * \d: Digits (0-9). * \[\]: Square brackets. * \(\): Parentheses. + * + * @var string */ public string $patterStreet = "/^[\p{L}\p{M}\,\-\.\'’`&\s\d\[\]\(\)]{1,255}$/u"; @@ -140,6 +142,6 @@ private function isValidStreet(mixed $streetValue): bool return true; } - return preg_match($this->$patterStreet, trim($streetValue)) === 1; + return preg_match($this->patterStreet, trim($streetValue)) === 1; } } From 7522e2ce77cb2a2929ae3fff65a79b177f6007e6 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:23:37 +0200 Subject: [PATCH 071/148] Update TelephoneValidator.php --- .../Security/Model/Validator/Pattern/TelephoneValidator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php index cc3d0f8da6420..9e7943f50bc66 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php @@ -28,6 +28,8 @@ class TelephoneValidator extends AbstractValidator * \/: Forward slash, sometimes used in extensions or other parts of the number. * * The pattern ensures that a phone number can be between 1 and 40 characters long. + * + * @var string */ public string $patternTelephone = '/^[\d\s\+\-\()\/]{1,40}$/u'; From 75927b05a30c870c3289ff2d931672c92c83fcfe Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 06:25:36 +0200 Subject: [PATCH 072/148] Update ForbiddenValidator.php --- .../Security/Model/Validator/Pattern/ForbiddenValidator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php index 2971099b9a442..7c223e583366d 100644 --- a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php +++ b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php @@ -125,6 +125,7 @@ private function validatePattern(mixed $value): bool if (preg_match('/base64_decode\(/', $value)) { // Use of base64_decode is discouraged, ensure this is safe in your context + // @codingStandardsIgnoreLine $decodedValue = base64_decode($value); return $this->validatePattern($decodedValue); } From 4c414cb40ef13610d582b35ce1405324f9122a69 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:39:13 +0200 Subject: [PATCH 073/148] Update system.xml --- .../Magento/Security/etc/adminhtml/system.xml | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/app/code/Magento/Security/etc/adminhtml/system.xml b/app/code/Magento/Security/etc/adminhtml/system.xml index 478e1c2663682..a31e1b1949b1a 100644 --- a/app/code/Magento/Security/etc/adminhtml/system.xml +++ b/app/code/Magento/Security/etc/adminhtml/system.xml @@ -58,66 +58,6 @@ Limit the maximum session size in bytes. Use 0 to disable. - - - - - Magento\Config\Model\Config\Source\Yesno - Activate the extended field pattern function. - - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - Enable or disable pattern validation for city fields. - - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - Enable or disable pattern validation for name fields. - - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - Enable or disable pattern validation for telephone fields. - - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - Enable or disable pattern validation for street fields. - - - - Magento\Config\Model\Config\Source\Yesno - - 1 - - Enable or disable pattern validation for e-mail fields. - - - - - 1 - - Enter one E-Mail or Host per line for banned validation. - - - - Magento\Config\Model\Config\Source\Yesno - Activate the extended pattern function to limit code injection. - -
From 664d41cda1926627e20aafa574d936208d8883e1 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:40:58 +0200 Subject: [PATCH 074/148] Delete app/code/Magento/Customer/Model/Validator/Email.php --- .../Customer/Model/Validator/Email.php | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 app/code/Magento/Customer/Model/Validator/Email.php diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php deleted file mode 100644 index 22b3dc0bb349d..0000000000000 --- a/app/code/Magento/Customer/Model/Validator/Email.php +++ /dev/null @@ -1,94 +0,0 @@ -emailValidator = $emailValidator; - } - - /** - * Validate email fields. - * - * @param Customer $customer - * @return bool - */ - public function isValid($customer): bool - { - if (!$this->emailValidator->isValidationEnabled()) { - return true; - } - - $email = $customer->getEmail(); - if (empty($email)) { - return true; - } - - if (!$this->validateEmailField($email)) { - return false; - } - - return count($this->_messages) == 0; - } - - /** - * Validate the email field. - * - * @param string|null $emailValue - * @return bool - */ - private function validateEmailField(?string $emailValue): bool - { - if (!$this->emailValidator->isValid($emailValue)) { - parent::_addMessages([ - __('Email address is not valid! Allowed characters: %1', - $this->emailValidator->allowedCharsDescription) - ]); - return false; - } - - if ($this->isBlacklistEmail($emailValue)) { - parent::_addMessages([ - __('The email address or domain is blacklisted.') - ]); - return false; - } - - return true; - } - - /** - * Check if email field is blacklisted using the EmailAddressValidator. - * - * @param string|null $emailValue - * @return bool - */ - private function isBlacklistEmail(?string $emailValue): bool - { - return $this->emailValidator->isBlacklist($emailValue); - } -} From 21e5b2ddfa6a3fee270fe707a4a2e44730c6c863 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:41:22 +0200 Subject: [PATCH 075/148] Delete app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php --- .../Model/Validator/Pattern/CityValidator.php | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php deleted file mode 100644 index 4a47a6a27a5c4..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/CityValidator.php +++ /dev/null @@ -1,107 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Check if both the global security pattern and city validation are enabled in the configuration. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - $isCityValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_CITY_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - return $isGlobalPatternEnabled && $isCityValidationEnabled; - } - - /** - * Validate the city value against the pattern. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if ($value === null || $value === '' || !is_string($value)) { - return true; - } - - return preg_match($this->patternCity, trim($value)) === 1; - } -} From 5ec5939bc7242232ed8a116eabd94384f7acccfe Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:41:32 +0200 Subject: [PATCH 076/148] Delete app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php --- .../Pattern/EmailAddressValidator.php | 143 ------------------ 1 file changed, 143 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php deleted file mode 100644 index 53bea4bd34f59..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/EmailAddressValidator.php +++ /dev/null @@ -1,143 +0,0 @@ -scopeConfig = $scopeConfig; - $this->emailValidator = $emailValidator; - } - - /** - * Check if both the global security pattern and email validation are enabled in the configuration. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - $isEmailValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_EMAIL_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - return $isGlobalPatternEnabled && $isEmailValidationEnabled; - } - - /** - * Validate an email address. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if ($value === null || $value === '' || !is_string($value)) { - return false; - } - - if (!preg_match($this->patterEmail, trim($value))) { - return false; - } - - return $this->emailValidator->isValid($value); - } - - /** - * Check if the email address or its domain is blacklisted. - * - * @param string|null $emailValue - * @return bool - */ - public function isBlacklist(?string $emailValue): bool - { - if ($emailValue === null || $emailValue === '' || !is_string($emailValue)) { - return false; - } - - if ($this->blacklistArray === null) { - $blacklist = $this->scopeConfig->getValue(self::XML_PATH_SECURITY_PATTERN_MAIL_BLACKLIST); - $this->blacklistArray = !empty($blacklist) ? preg_split('/[\r\n,]+/', $blacklist) : []; - } - - $emailHost = substr(strrchr($emailValue, "@"), 1); - - return in_array($emailValue, $this->blacklistArray) || in_array($emailHost, $this->blacklistArray); - } -} From 974af517a025ad415544a9633a13539700142569 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:41:40 +0200 Subject: [PATCH 077/148] Delete app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php --- .../Validator/Pattern/ForbiddenValidator.php | 135 ------------------ 1 file changed, 135 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php deleted file mode 100644 index 7c223e583366d..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/ForbiddenValidator.php +++ /dev/null @@ -1,135 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Check if forbidden patterns validation is enabled. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - return $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_CODE_INJECTION_ENABLED, - ScopeInterface::SCOPE_STORE - ); - } - - /** - * Returns an array of forbidden patterns. - * - * @return string[] - */ - public function getPatterns(): array - { - return [ - '/{{.*}}/', - '/<\?=/', - '/<\?php/', - '/shell_exec/', - '/eval\(/', - '/\${IFS%/', - '/\bcurl\b/', - ]; - } - - /** - * Validates the given field value against forbidden patterns. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if (!$this->isValidationEnabled()) { - return true; - } - - return $this->validatePattern($value); - } - - /** - * Recursively validate data against forbidden patterns. - * - * @param mixed $data - * @return bool - */ - public function validateDataRecursively($data): bool - { - if (is_array($data)) { - foreach ($data as $value) { - if (!$this->validateDataRecursively($value)) { - return false; - } - } - } else { - return $this->isValid($data); - } - - return true; - } - - /** - * Validates the field value against forbidden patterns. - * - * @param mixed $value - * @return bool - */ - private function validatePattern(mixed $value): bool - { - if (!is_string($value) || trim($value) === '') { - return true; - } - - foreach ($this->getPatterns() as $pattern) { - if (preg_match($pattern, trim($value))) { - return false; - } - } - - if (preg_match('/base64_decode\(/', $value)) { - // Use of base64_decode is discouraged, ensure this is safe in your context - // @codingStandardsIgnoreLine - $decodedValue = base64_decode($value); - return $this->validatePattern($decodedValue); - } - - return true; - } -} From d083bb84a0406a5caa307cd33e05524d1aff806e Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:41:54 +0200 Subject: [PATCH 078/148] Delete app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php --- .../Model/Validator/Pattern/NameValidator.php | 120 ------------------ 1 file changed, 120 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php deleted file mode 100644 index 3cc143001a532..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/NameValidator.php +++ /dev/null @@ -1,120 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Check if both the global security pattern and name validation are enabled in the configuration. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - $isNameValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - return $isGlobalPatternEnabled && $isNameValidationEnabled; - } - - /** - * Validate the name value against the pattern. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if ($value === null || $value === '' || !is_string($value)) { - return true; - } - - $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; - - return preg_match($pattern, trim($value)) === 1; - } -} From c591993526e686e95abf03d2260d86d35f7227dc Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:42:03 +0200 Subject: [PATCH 079/148] Delete app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php --- .../Validator/Pattern/StreetValidator.php | 147 ------------------ 1 file changed, 147 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php deleted file mode 100644 index 4eea2d9353993..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/StreetValidator.php +++ /dev/null @@ -1,147 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Check if both the global security pattern and street validation are enabled in the configuration. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - $isStreetValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_STREET_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - return $isGlobalPatternEnabled && $isStreetValidationEnabled; - } - - /** - * Validate a street address string or an array of street address strings. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if (!$this->isValidationEnabled()) { - return true; // Skip validation if globally disabled - } - - if (is_array($value)) { - foreach ($value as $streetValue) { - if (!$this->validateSingleStreet($streetValue)) { - return false; - } - } - } else { - if (!$this->validateSingleStreet($value)) { - return false; - } - } - - return true; - } - - /** - * Validate a single street address string. - * - * @param mixed $streetValue - * @return bool - */ - private function validateSingleStreet($streetValue): bool - { - return $this->isValidStreet($streetValue); - } - - /** - * Check if the street field is valid. - * - * @param mixed $streetValue - * @return bool - */ - private function isValidStreet(mixed $streetValue): bool - { - if ($streetValue === null || $streetValue === '' || !is_string($streetValue)) { - return true; - } - - return preg_match($this->patterStreet, trim($streetValue)) === 1; - } -} From 0dae3949ae70776ef0115371333a1b1ac95d04db Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:42:11 +0200 Subject: [PATCH 080/148] Delete app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php --- .../Validator/Pattern/TelephoneValidator.php | 109 ------------------ 1 file changed, 109 deletions(-) delete mode 100644 app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php diff --git a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php deleted file mode 100644 index 9e7943f50bc66..0000000000000 --- a/app/code/Magento/Security/Model/Validator/Pattern/TelephoneValidator.php +++ /dev/null @@ -1,109 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Check if both the global security pattern and telephone validation are enabled in the configuration. - * - * @return bool - */ - public function isValidationEnabled(): bool - { - // Check if the global security pattern validation is enabled - $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - // Check if the specific telephone validation is enabled - $isTelephoneValidationEnabled = $this->scopeConfig->isSetFlag( - self::XML_PATH_SECURITY_PATTERN_TELEPHONE_ENABLED, - ScopeInterface::SCOPE_STORE - ); - - // Return true only if both are enabled - return $isGlobalPatternEnabled && $isTelephoneValidationEnabled; - } - - /** - * Validate the telephone value against the pattern. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if ($value === null || $value === '') { - return true; - } - - return preg_match($this->patternTelephone, trim($value)) === 1; - } -} From a3db525f897cc45bb9db85fd859d85a936786a31 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:44:01 +0200 Subject: [PATCH 081/148] Create CityValidator.php --- .../Model/Validator/Pattern/CityValidator.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php new file mode 100644 index 0000000000000..13688040da32e --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php @@ -0,0 +1,109 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and city validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isCityValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_CITY_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isCityValidationEnabled; + } + + /** + * Validate the city value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return true; + } + + return preg_match($this->patternCity, trim($value)) === 1; + } +} From bab0f30a9b3972f2f64ce67ac9b9158718e33854 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:44:18 +0200 Subject: [PATCH 082/148] Create EmailAddressValidator.php --- .../Pattern/EmailAddressValidator.php | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php new file mode 100644 index 0000000000000..9bd9c763870c3 --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php @@ -0,0 +1,143 @@ +scopeConfig = $scopeConfig; + $this->emailValidator = $emailValidator; + } + + /** + * Check if both the global security pattern and email validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isEmailValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_EMAIL_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isEmailValidationEnabled; + } + + /** + * Validate an email address. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return false; + } + + if (!preg_match($this->patterEmail, trim($value))) { + return false; + } + + return $this->emailValidator->isValid($value); + } + + /** + * Check if the email address or its domain is blacklisted. + * + * @param string|null $emailValue + * @return bool + */ + public function isBlacklist(?string $emailValue): bool + { + if ($emailValue === null || $emailValue === '' || !is_string($emailValue)) { + return false; + } + + if ($this->blacklistArray === null) { + $blacklist = $this->scopeConfig->getValue(self::XML_PATH_SECURITY_PATTERN_MAIL_BLACKLIST); + $this->blacklistArray = !empty($blacklist) ? preg_split('/[\r\n,]+/', $blacklist) : []; + } + + $emailHost = substr(strrchr($emailValue, "@"), 1); + + return in_array($emailValue, $this->blacklistArray) || in_array($emailHost, $this->blacklistArray); + } +} From c72b1d27012fd281bcf890b320c21c5bcfd518c0 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:44:31 +0200 Subject: [PATCH 083/148] Create ForbiddenValidator.php --- .../Validator/Pattern/ForbiddenValidator.php | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php new file mode 100644 index 0000000000000..40d97e6c6af6c --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php @@ -0,0 +1,135 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if forbidden patterns validation is enabled. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_CODE_INJECTION_ENABLED, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * Returns an array of forbidden patterns. + * + * @return string[] + */ + public function getPatterns(): array + { + return [ + '/{{.*}}/', + '/<\?=/', + '/<\?php/', + '/shell_exec/', + '/eval\(/', + '/\${IFS%/', + '/\bcurl\b/', + ]; + } + + /** + * Validates the given field value against forbidden patterns. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if (!$this->isValidationEnabled()) { + return true; + } + + return $this->validatePattern($value); + } + + /** + * Recursively validate data against forbidden patterns. + * + * @param mixed $data + * @return bool + */ + public function validateDataRecursively($data): bool + { + if (is_array($data)) { + foreach ($data as $value) { + if (!$this->validateDataRecursively($value)) { + return false; + } + } + } else { + return $this->isValid($data); + } + + return true; + } + + /** + * Validates the field value against forbidden patterns. + * + * @param mixed $value + * @return bool + */ + private function validatePattern(mixed $value): bool + { + if (!is_string($value) || trim($value) === '') { + return true; + } + + foreach ($this->getPatterns() as $pattern) { + if (preg_match($pattern, trim($value))) { + return false; + } + } + + if (preg_match('/base64_decode\(/', $value)) { + // Use of base64_decode is discouraged, ensure this is safe in your context + // @codingStandardsIgnoreLine + $decodedValue = base64_decode($value); + return $this->validatePattern($decodedValue); + } + + return true; + } +} From a8e459906bf6aecf4fb1d47ca52ce6de48c24525 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:44:45 +0200 Subject: [PATCH 084/148] Create NameValidator.php --- .../Model/Validator/Pattern/NameValidator.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php new file mode 100644 index 0000000000000..667a0745c2b1f --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php @@ -0,0 +1,120 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and name validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isNameValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_NAME_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isNameValidationEnabled; + } + + /** + * Validate the name value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '' || !is_string($value)) { + return true; + } + + $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; + + return preg_match($pattern, trim($value)) === 1; + } +} From c351366f0fe2759d9d764183695412d094b5671d Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:44:59 +0200 Subject: [PATCH 085/148] Create StreetValidator.php --- .../Validator/Pattern/StreetValidator.php | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php new file mode 100644 index 0000000000000..ae3446afb6b11 --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php @@ -0,0 +1,147 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and street validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + $isStreetValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_STREET_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + return $isGlobalPatternEnabled && $isStreetValidationEnabled; + } + + /** + * Validate a street address string or an array of street address strings. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if (!$this->isValidationEnabled()) { + return true; // Skip validation if globally disabled + } + + if (is_array($value)) { + foreach ($value as $streetValue) { + if (!$this->validateSingleStreet($streetValue)) { + return false; + } + } + } else { + if (!$this->validateSingleStreet($value)) { + return false; + } + } + + return true; + } + + /** + * Validate a single street address string. + * + * @param mixed $streetValue + * @return bool + */ + private function validateSingleStreet($streetValue): bool + { + return $this->isValidStreet($streetValue); + } + + /** + * Check if the street field is valid. + * + * @param mixed $streetValue + * @return bool + */ + private function isValidStreet(mixed $streetValue): bool + { + if ($streetValue === null || $streetValue === '' || !is_string($streetValue)) { + return true; + } + + return preg_match($this->patterStreet, trim($streetValue)) === 1; + } +} From eda0e0c064b76bbfb1f74fe74a1e60b225b0075e Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:45:10 +0200 Subject: [PATCH 086/148] Create TelephoneValidator.php --- .../Validator/Pattern/TelephoneValidator.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php new file mode 100644 index 0000000000000..6b73da5184dd2 --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php @@ -0,0 +1,109 @@ +scopeConfig = $scopeConfig; + } + + /** + * Check if both the global security pattern and telephone validation are enabled in the configuration. + * + * @return bool + */ + public function isValidationEnabled(): bool + { + // Check if the global security pattern validation is enabled + $isGlobalPatternEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Check if the specific telephone validation is enabled + $isTelephoneValidationEnabled = $this->scopeConfig->isSetFlag( + self::XML_PATH_SECURITY_PATTERN_TELEPHONE_ENABLED, + ScopeInterface::SCOPE_STORE + ); + + // Return true only if both are enabled + return $isGlobalPatternEnabled && $isTelephoneValidationEnabled; + } + + /** + * Validate the telephone value against the pattern. + * + * @param mixed $value + * @return bool + */ + public function isValid($value): bool + { + if ($value === null || $value === '') { + return true; + } + + return preg_match($this->patternTelephone, trim($value)) === 1; + } +} From d66a4cb15454af362d1b1b90a0cca02040514512 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:45:32 +0200 Subject: [PATCH 087/148] Update system.xml --- .../Magento/Customer/etc/adminhtml/system.xml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/app/code/Magento/Customer/etc/adminhtml/system.xml b/app/code/Magento/Customer/etc/adminhtml/system.xml index ec76e09fdf459..61fbc2358bc58 100644 --- a/app/code/Magento/Customer/etc/adminhtml/system.xml +++ b/app/code/Magento/Customer/etc/adminhtml/system.xml @@ -313,5 +313,67 @@
+
+ + + + + Magento\Config\Model\Config\Source\Yesno + Activate the extended field pattern function. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for city fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for name fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for telephone fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for street fields. + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Enable or disable pattern validation for e-mail fields. + + + + + 1 + + Enter one E-Mail or Host per line for banned validation. + + + + Magento\Config\Model\Config\Source\Yesno + Activate the extended pattern function to limit code injection. + + +
From 4275bab5267a4afd622208e73ba170847b3e6fcc Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:47:13 +0200 Subject: [PATCH 088/148] Create Email.php --- .../Customer/Model/Validator/Email.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Validator/Email.php diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php new file mode 100644 index 0000000000000..598b0a9682cbb --- /dev/null +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -0,0 +1,98 @@ +emailValidator = $emailValidator; + } + + /** + * Validate email fields. + * + * @param Customer $customer + * @return bool + */ + public function isValid($customer): bool + { + if (!$this->emailValidator->isValidationEnabled()) { + return true; + } + + $email = $customer->getEmail(); + if (empty($email)) { + return true; + } + + if (!$this->validateEmailField($email)) { + return false; + } + + return count($this->_messages) == 0; + } + + /** + * Validate the email field. + * + * @param string|null $emailValue + * @return bool + */ + private function validateEmailField(?string $emailValue): bool + { + if (!$this->emailValidator->isValid($emailValue)) { + parent::_addMessages( + [ + __( + 'Email address is not valid! Allowed characters: %1', + $this->emailValidator->allowedCharsDescription + ), + ] + ); + return false; + } + + if ($this->isBlacklistEmail($emailValue)) { + parent::_addMessages([ + __('The email address or domain is blacklisted.') + ]); + return false; + } + + return true; + } + + /** + * Check if email field is blacklisted using the EmailAddressValidator. + * + * @param string|null $emailValue + * @return bool + */ + private function isBlacklistEmail(?string $emailValue): bool + { + return $this->emailValidator->isBlacklist($emailValue); + } +} From a87f13a81af4a34bb7bd0131bbb9f0b03358e6f2 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:47:26 +0200 Subject: [PATCH 089/148] Update City.php --- app/code/Magento/Customer/Model/Validator/City.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 164396a8398aa..146a3bce4dca7 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Framework\Validator\AbstractValidator; -use Magento\Security\Model\Validator\Pattern\CityValidator; +use Magento\Customer\Model\Validator\Pattern\CityValidator; /** * Customer city fields validator. From 3d99554726ba54f5969e8ce5c018e584c6e1c8db Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:47:45 +0200 Subject: [PATCH 090/148] Update ForbiddenPattern.php --- app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php index 60d230da7b0e8..0b4c0fcf51468 100644 --- a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php +++ b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Framework\Validator\AbstractValidator; -use Magento\Security\Model\Validator\Pattern\ForbiddenValidator; +use Magento\Customer\Model\Validator\Pattern\ForbiddenValidator; /** * Validator for forbidden patterns in customer EAV data. From da11da8a046cf8430999306d5ff2a2d36ba04ae9 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:48:00 +0200 Subject: [PATCH 091/148] Update Name.php --- app/code/Magento/Customer/Model/Validator/Name.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 47f243156a932..fe4a09a5f1682 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Framework\Validator\AbstractValidator; -use Magento\Security\Model\Validator\Pattern\NameValidator; +use Magento\Customer\Model\Validator\Pattern\NameValidator; /** * Customer name fields validator. From b4aeac3952dc44866146030ddbd6ee052b16e6b7 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:48:16 +0200 Subject: [PATCH 092/148] Update Street.php --- app/code/Magento/Customer/Model/Validator/Street.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index 764eb2b851324..ef309e7b7a703 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Framework\Validator\AbstractValidator; -use Magento\Security\Model\Validator\Pattern\StreetValidator; +use Magento\Customer\Model\Validator\Pattern\StreetValidator; /** * Customer street fields validator. From dc79eb8cd53e8e9446931d65a6cc9833061a66f9 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:48:31 +0200 Subject: [PATCH 093/148] Update Telephone.php --- app/code/Magento/Customer/Model/Validator/Telephone.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index ede6bb7f52afe..61151a2eefbf0 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Framework\Validator\AbstractValidator; -use Magento\Security\Model\Validator\Pattern\TelephoneValidator; +use Magento\Customer\Model\Validator\Pattern\TelephoneValidator; /** * Customer telephone fields validator. From d30a06078faa86740be198cf865f60b04d2388aa Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:49:14 +0200 Subject: [PATCH 094/148] Update SubscriptionManager.php --- .../Newsletter/Model/SubscriptionManager.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/code/Magento/Newsletter/Model/SubscriptionManager.php b/app/code/Magento/Newsletter/Model/SubscriptionManager.php index 05be8325e3243..c37fa9cdf542f 100644 --- a/app/code/Magento/Newsletter/Model/SubscriptionManager.php +++ b/app/code/Magento/Newsletter/Model/SubscriptionManager.php @@ -13,6 +13,8 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\MailException; +use Magento\Framework\Validator\Exception as ValidatorException; +use Magento\Framework\Validator\Factory as ValidatorFactory; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; @@ -57,11 +59,17 @@ class SubscriptionManager implements SubscriptionManagerInterface */ private $customerSubscriberCache; + /** + * @var ValidatorFactory + */ + protected $validatorFactory; + /** * @param SubscriberFactory $subscriberFactory * @param LoggerInterface $logger * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig + * @param ValidatorFactory $validatorFactory * @param AccountManagementInterface $customerAccountManagement * @param CustomerRepositoryInterface $customerRepository * @param CustomerSubscriberCache|null $customerSubscriberCache @@ -71,6 +79,7 @@ public function __construct( LoggerInterface $logger, StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, + ValidatorFactory $validatorFactory, AccountManagementInterface $customerAccountManagement, CustomerRepositoryInterface $customerRepository, CustomerSubscriberCache $customerSubscriberCache = null @@ -79,6 +88,7 @@ public function __construct( $this->logger = $logger; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; + $this->validatorFactory = $validatorFactory; $this->customerAccountManagement = $customerAccountManagement; $this->customerRepository = $customerRepository; $this->customerSubscriberCache = $customerSubscriberCache @@ -90,6 +100,10 @@ public function __construct( */ public function subscribe(string $email, int $storeId): Subscriber { + if ($email) { + $this->_validate($email); + } + $websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId(); $subscriber = $this->subscriberFactory->create()->loadBySubscriberEmail($email, $websiteId); $currentStatus = (int)$subscriber->getStatus(); @@ -111,6 +125,28 @@ public function subscribe(string $email, int $storeId): Subscriber return $subscriber; } + /** + * Validate the subscriber's email for guest subscribers. + * + * @param string $email + * @return void + * @throws ValidatorException + */ + protected function _validate(string $email): void + { + // Create the validator using the entity and group defined in the XML + $validator = $this->validatorFactory->createValidator('newsletter_subscriber', 'save'); + + // Check if the email is valid + if (!$validator->isValid($email)) { + throw new ValidatorException( + null, + null, + $validator->getMessages() + ); + } + } + /** * @inheritdoc */ From 69fb939aca3a9879a41878d3c54088356e68d857 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:49:37 +0200 Subject: [PATCH 095/148] Create validation.xml --- .../Magento/Newsletter/etc/validation.xml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/code/Magento/Newsletter/etc/validation.xml diff --git a/app/code/Magento/Newsletter/etc/validation.xml b/app/code/Magento/Newsletter/etc/validation.xml new file mode 100644 index 0000000000000..d84de2af61ce8 --- /dev/null +++ b/app/code/Magento/Newsletter/etc/validation.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + From 413456e5b327db8b690be1ae545f00bb9f8f5c05 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:50:07 +0200 Subject: [PATCH 096/148] Create Email.php --- .../Newsletter/Model/Validator/Email.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 app/code/Magento/Newsletter/Model/Validator/Email.php diff --git a/app/code/Magento/Newsletter/Model/Validator/Email.php b/app/code/Magento/Newsletter/Model/Validator/Email.php new file mode 100644 index 0000000000000..a7d1935e0c59b --- /dev/null +++ b/app/code/Magento/Newsletter/Model/Validator/Email.php @@ -0,0 +1,93 @@ +emailValidator = $emailValidator; + } + + /** + * Validate email fields. + * + * @param string $email + * @return bool + */ + public function isValid($email): bool + { + if (!$this->emailValidator->isValidationEnabled()) { + return true; + } + + if (!$this->validateEmailField($email)) { + return false; + } + + return count($this->_messages) == 0; + } + + /** + * Validate the email field. + * + * @param string|null $emailValue + * @return bool + */ + private function validateEmailField(?string $emailValue): bool + { + if (!$this->emailValidator->isValid($emailValue)) { + parent::_addMessages( + [ + __( + 'Email address is not valid! Allowed characters: %1', + $this->emailValidator->allowedCharsDescription + ), + ] + ); + return false; + } + + if ($this->isBlacklistEmail($emailValue)) { + parent::_addMessages([ + __('The email address or domain is blacklisted.') + ]); + return false; + } + + return true; + } + + /** + * Check if email field is blacklisted using the EmailAddressValidator. + * + * @param string|null $emailValue + * @return bool + */ + private function isBlacklistEmail(?string $emailValue): bool + { + return $this->emailValidator->isBlacklist($emailValue); + } +} From d0b914341a93b1a386ccc90cfa9562e9fd8abf23 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:52:12 +0200 Subject: [PATCH 097/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 8b2c709870b55..1e439b00af288 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\City; -use Magento\Security\Model\Validator\Pattern\CityValidator; +use Magento\Customer\Model\Validator\Pattern\CityValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -45,7 +45,7 @@ protected function setUp(): void ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getCity']) - ->getMock(); + ->getMock(); } /** @@ -57,7 +57,7 @@ protected function setUp(): void * @dataProvider expectedPunctuationInCityDataProvider */ public function testValidateCityName( - string $city, + string $city, bool $expectedIsValid ): void { $this->addressMock->expects($this->once())->method('getCity')->willReturn($city); From add1b956bc79d2bbd38bca0277abf22eebea6eb4 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:52:32 +0200 Subject: [PATCH 098/148] Update NameTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/NameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 7059ba8286afd..7f43fb7ee946d 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Validator\Name; use Magento\Customer\Model\Customer; -use Magento\Security\Model\Validator\Pattern\NameValidator; +use Magento\Customer\Model\Validator\Pattern\NameValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; From 0e650e4dd4a677f8d0abf5850aab9613f8f2f4eb Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:52:48 +0200 Subject: [PATCH 099/148] Update StreetTest.php --- .../Customer/Test/Unit/Model/Validator/StreetTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index f0de4c1ec326c..64d77d3612c9b 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Customer; use Magento\Customer\Model\Validator\Street; -use Magento\Security\Model\Validator\Pattern\StreetValidator; +use Magento\Customer\Model\Validator\Pattern\StreetValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -45,7 +45,7 @@ protected function setUp(): void ->getMockBuilder(Customer::class) ->disableOriginalConstructor() ->addMethods(['getStreet']) - ->getMock(); + ->getMock(); } /** @@ -57,7 +57,7 @@ protected function setUp(): void * @dataProvider expectedPunctuationInStreetDataProvider */ public function testValidateStreetName( - array $street, + array $street, string $message ): void { $this->addressMock->expects($this->once())->method('getStreet')->willReturn($street); From 76f0956344b71a77c015203f9cadeb482e52907b Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 07:53:03 +0200 Subject: [PATCH 100/148] Update TelephoneTest.php --- .../Customer/Test/Unit/Model/Validator/TelephoneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index 3719ff44a1725..ab3f44db2a03a 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -9,7 +9,7 @@ use Magento\Customer\Model\Validator\Telephone; use Magento\Customer\Model\Customer; -use Magento\Security\Model\Validator\Pattern\TelephoneValidator; +use Magento\Customer\Model\Validator\Pattern\TelephoneValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; From 8216493038de44790ea7d450e69ce076eb4c6f40 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:44:21 +0200 Subject: [PATCH 101/148] Create validation.xml --- app/code/Magento/Contact/etc/validation.xml | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/code/Magento/Contact/etc/validation.xml diff --git a/app/code/Magento/Contact/etc/validation.xml b/app/code/Magento/Contact/etc/validation.xml new file mode 100644 index 0000000000000..86fb0c7df86d8 --- /dev/null +++ b/app/code/Magento/Contact/etc/validation.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From a12d0eb77433d8595af405f1bee9adfbfd30a16f Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:44:51 +0200 Subject: [PATCH 102/148] Update Mail.php --- app/code/Magento/Contact/Model/Mail.php | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Contact/Model/Mail.php b/app/code/Magento/Contact/Model/Mail.php index 43c1974252b5a..111b238a7562a 100644 --- a/app/code/Magento/Contact/Model/Mail.php +++ b/app/code/Magento/Contact/Model/Mail.php @@ -10,6 +10,9 @@ use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\Area; +use Magento\Framework\Validator\Factory as ValidatorFactory; +use Magento\Framework\Validator\Exception as ValidatorException; +use Magento\Framework\DataObject; class Mail implements MailInterface { @@ -33,6 +36,11 @@ class Mail implements MailInterface */ private $storeManager; + /** + * @var ValidatorFactory + */ + private $validatorFactory; + /** * Initialize dependencies. * @@ -40,17 +48,20 @@ class Mail implements MailInterface * @param TransportBuilder $transportBuilder * @param StateInterface $inlineTranslation * @param StoreManagerInterface|null $storeManager + * @param ValidatorFactory $validatorFactory */ public function __construct( ConfigInterface $contactsConfig, TransportBuilder $transportBuilder, StateInterface $inlineTranslation, - StoreManagerInterface $storeManager = null + StoreManagerInterface $storeManager = null, + ValidatorFactory $validatorFactory ) { $this->contactsConfig = $contactsConfig; $this->transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class); + $this->validatorFactory = $validatorFactory; } /** @@ -59,9 +70,13 @@ public function __construct( * @param string $replyTo * @param array $variables * @return void + * @throws ValidatorException */ public function send($replyTo, array $variables) { + // Perform validation before sending email + $this->_validate($variables['data']); + /** @see \Magento\Contact\Controller\Index\Post::validatedParams() */ $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null; @@ -86,4 +101,23 @@ public function send($replyTo, array $variables) $this->inlineTranslation->resume(); } } + + /** + * Validate the contact form data. + * + * @param DataObject $data + * @throws ValidatorException + */ + protected function _validate(DataObject $data) + { + $validator = $this->validatorFactory->createValidator('contact', 'save'); + + if (!$validator->isValid($data)) { + throw new ValidatorException( + null, + null, + $validator->getMessages() + ); + } + } } From abcb9cb50c57c6fb878a38b2b8367a11504f56bf Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:46:08 +0200 Subject: [PATCH 103/148] Create Email.php --- .../Magento/Contact/Model/Validator/Email.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/code/Magento/Contact/Model/Validator/Email.php diff --git a/app/code/Magento/Contact/Model/Validator/Email.php b/app/code/Magento/Contact/Model/Validator/Email.php new file mode 100644 index 0000000000000..a1f6c565c3e07 --- /dev/null +++ b/app/code/Magento/Contact/Model/Validator/Email.php @@ -0,0 +1,98 @@ +emailValidator = $emailValidator; + } + + /** + * Validate email fields. + * + * @param DataObject $data + * @return bool + */ + public function isValid($data): bool + { + if (!$this->emailValidator->isValidationEnabled()) { + return true; + } + + $email = $data->getData('email'); + if (empty($email)) { + return true; + } + + if (!$this->validateEmailField($email)) { + return false; + } + + return count($this->_messages) == 0; + } + + /** + * Validate the email field. + * + * @param string|null $emailValue + * @return bool + */ + protected function validateEmailField(?string $emailValue): bool + { + if (!$this->emailValidator->isValid($emailValue)) { + parent::_addMessages( + [ + __( + 'Email address is not valid! Allowed characters: %1', + $this->emailValidator->allowedCharsDescription + ), + ] + ); + return false; + } + + if ($this->isBlacklistEmail($emailValue)) { + parent::_addMessages([ + __('The email address or domain is blacklisted.') + ]); + return false; + } + + return true; + } + + /** + * Check if email field is blacklisted using the EmailAddressValidator. + * + * @param string|null $emailValue + * @return bool + */ + protected function isBlacklistEmail(?string $emailValue): bool + { + return $this->emailValidator->isBlacklist($emailValue); + } +} From b830fdad5dd104bdeb46eb81b90f62049672c38f Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:46:33 +0200 Subject: [PATCH 104/148] Create ForbiddenPattern.php --- .../Model/Validator/ForbiddenPattern.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php diff --git a/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php new file mode 100644 index 0000000000000..4b1b0a098f945 --- /dev/null +++ b/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php @@ -0,0 +1,62 @@ +forbiddenValidator = $forbiddenValidator; + } + + /** + * Validate contact form data fields against forbidden patterns. + * + * @param DataObject $data + * @return bool + * @throws LocalizedException + */ + public function isValid($data): bool + { + if (!$this->forbiddenValidator->isValidationEnabled()) { + return true; + } + + $dataFields = $data->getData(); + if (empty($dataFields)) { + return true; + } + + $isValid = $this->forbiddenValidator->validateDataRecursively($dataFields); + + if (!$isValid) { + parent::_addMessages([ + __('Fraud Protection: Forbidden pattern detected in contact form data') + ]); + } + + return count($this->_messages) == 0; + } +} From e2e0e4f6da1113b5cc6a06ce879d75d31f2d7362 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:48:32 +0200 Subject: [PATCH 105/148] Update Review.php --- app/code/Magento/Review/Model/Review.php | 33 ++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/Model/Review.php b/app/code/Magento/Review/Model/Review.php index ef2474637f384..f2c0e16603d80 100644 --- a/app/code/Magento/Review/Model/Review.php +++ b/app/code/Magento/Review/Model/Review.php @@ -12,6 +12,8 @@ use Magento\Framework\Validator\NotEmpty; use Magento\Framework\Validator\ValidateException; use Magento\Framework\Validator\ValidatorChain; +use Magento\Framework\Validator\Factory as ValidatorFactory; +use Magento\Framework\Validator\Exception as ValidatorException; use Magento\Review\Model\ResourceModel\Review\Product\Collection as ProductCollection; use Magento\Review\Model\ResourceModel\Review\Status\Collection as StatusCollection; @@ -123,7 +125,12 @@ class Review extends \Magento\Framework\Model\AbstractModel implements IdentityI * @var \Magento\Framework\UrlInterface */ protected $_urlModel; - + + /** + * @var ValidatorFactory + */ + protected $validatorFactory; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -149,6 +156,7 @@ public function __construct( \Magento\Review\Model\Review\Summary $reviewSummary, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlModel, + ValidatorFactory $validatorFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [] @@ -160,6 +168,7 @@ public function __construct( $this->_reviewSummary = $reviewSummary; $this->_storeManager = $storeManager; $this->_urlModel = $urlModel; + $this->validatorFactory = $validatorFactory; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } @@ -292,12 +301,32 @@ public function validate() $errors[] = __('Please enter a review.'); } + $this->_validate(); + if (empty($errors)) { return true; } return $errors; } - + + /** + * Validate review using custom validator. + * + * @throws ValidatorException + */ + protected function _validate() + { + $validator = $this->validatorFactory->createValidator('review', 'save'); + + if (!$validator->isValid($this)) { + throw new ValidatorException( + null, + null, + $validator->getMessages() + ); + } + } + /** * Perform actions after object delete * From 4984bbc05666e2ae055a6d6b840e98050e2c7461 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:49:02 +0200 Subject: [PATCH 106/148] Create validation.xml --- app/code/Magento/Review/etc/validation.xml | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/code/Magento/Review/etc/validation.xml diff --git a/app/code/Magento/Review/etc/validation.xml b/app/code/Magento/Review/etc/validation.xml new file mode 100644 index 0000000000000..ed0264790a46f --- /dev/null +++ b/app/code/Magento/Review/etc/validation.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 001a718bfdf8478ac6a78db63155410844113859 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:49:39 +0200 Subject: [PATCH 107/148] Create Email.php --- .../Magento/Review/Model/Validator/Email.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 app/code/Magento/Review/Model/Validator/Email.php diff --git a/app/code/Magento/Review/Model/Validator/Email.php b/app/code/Magento/Review/Model/Validator/Email.php new file mode 100644 index 0000000000000..4cde7050ae978 --- /dev/null +++ b/app/code/Magento/Review/Model/Validator/Email.php @@ -0,0 +1,94 @@ +emailValidator = $emailValidator; + } + + /** + * Validate email fields. + * + * @param string $email + * @return bool + */ + public function isValid($email): bool + { + if (!$this->emailValidator->isValidationEnabled()) { + return true; + } + + if (!$this->validateEmailField($email)) { + return false; + } + + return count($this->_messages) == 0; + } + + /** + * Validate the email field. + * + * @param string|null $emailValue + * @return bool + */ + private function validateEmailField(?string $emailValue): bool + { + if (!$this->emailValidator->isValid($emailValue)) { + parent::_addMessages( + [ + __( + 'Email address is not valid! Allowed characters: %1', + $this->emailValidator->allowedCharsDescription + ), + ] + ); + return false; + } + + if ($this->isBlacklistEmail($emailValue)) { + parent::_addMessages([ + __('The email address or domain is blacklisted.') + ]); + return false; + } + + return true; + } + + /** + * Check if email field is blacklisted using the EmailAddressValidator. + * + * @param string|null $emailValue + * @return bool + */ + private function isBlacklistEmail(?string $emailValue): bool + { + return $this->emailValidator->isBlacklist($emailValue); + } +} From 2832a8074b63d03c9a0b25645b7f4d76c8895afb Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:49:56 +0200 Subject: [PATCH 108/148] Create ForbiddenPattern.php --- .../Model/Validator/ForbiddenPattern.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 app/code/Magento/Review/Model/Validator/ForbiddenPattern.php diff --git a/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php new file mode 100644 index 0000000000000..0ed63980c816a --- /dev/null +++ b/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php @@ -0,0 +1,60 @@ +forbiddenValidator = $forbiddenValidator; + } + + /** + * Validate multiple review fields against forbidden patterns. + * + * @param array $values + * @return bool + */ + public function isValid($values): bool + { + if (!$this->forbiddenValidator->isValidationEnabled()) { + return true; + } + + foreach ($values as $field => $value) { + if (empty($value)) { + continue; + } + + if (!$this->forbiddenValidator->isValid($value)) { + parent::_addMessages([ + __("Fraud Protection: Forbidden pattern detected in review field") + ]); + } + } + + return count($this->_messages) == 0; + } +} From c32ec77242cee5c52db9ce6976f53bb996d5779b Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 09:50:52 +0200 Subject: [PATCH 109/148] Update module.xml --- app/code/Magento/Customer/etc/module.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Customer/etc/module.xml b/app/code/Magento/Customer/etc/module.xml index 030786d4741b1..853157fed1f5d 100644 --- a/app/code/Magento/Customer/etc/module.xml +++ b/app/code/Magento/Customer/etc/module.xml @@ -10,7 +10,6 @@ - From ad351815a7bf6a0a11ed4e2bdf897329ddcb98d7 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 10:44:01 +0200 Subject: [PATCH 110/148] Update CityValidator.php --- .../Model/Validator/Pattern/CityValidator.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php index 13688040da32e..fa880121bc2ef 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php @@ -103,7 +103,14 @@ public function isValid($value): bool if ($value === null || $value === '' || !is_string($value)) { return true; } - - return preg_match($this->patternCity, trim($value)) === 1; + + $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; + + $trimmedValue = trim($value); + if (preg_match($pattern, $trimmedValue, $matches)) { + return $matches[0] === $trimmedValue; + } + + return false; } } From 3254daad94189b0151d153ae480a9f9c71bd34a8 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 10:46:21 +0200 Subject: [PATCH 111/148] Update CityValidator.php --- .../Customer/Model/Validator/Pattern/CityValidator.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php index fa880121bc2ef..4bd3fb8efae2d 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php @@ -104,12 +104,7 @@ public function isValid($value): bool return true; } - $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; - - $trimmedValue = trim($value); - if (preg_match($pattern, $trimmedValue, $matches)) { - return $matches[0] === $trimmedValue; - } + return preg_match($this->patternCity, trim($value)) === 1; return false; } From 8eaabb4c02e268c883e3209ba0a0d0d49aad2fa3 Mon Sep 17 00:00:00 2001 From: in-session Date: Tue, 3 Sep 2024 10:47:07 +0200 Subject: [PATCH 112/148] Update NameValidator.php --- .../Customer/Model/Validator/Pattern/NameValidator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php index 667a0745c2b1f..410492b630c23 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php @@ -115,6 +115,11 @@ public function isValid($value): bool $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; + $trimmedValue = trim($value); + if (preg_match($pattern, $trimmedValue, $matches)) { + return $matches[0] === $trimmedValue; + } + return preg_match($pattern, trim($value)) === 1; } } From 2862bddaadcd5dbbb9b9ab858364518e31920510 Mon Sep 17 00:00:00 2001 From: in-session Date: Mon, 9 Sep 2024 05:35:16 +0200 Subject: [PATCH 113/148] Update Name.php --- .../Magento/Customer/Model/Validator/Name.php | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index fe4a09a5f1682..a782a3d309d49 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -38,26 +38,32 @@ public function __construct(NameValidator $nameValidator) * @return bool */ public function isValid($customer): bool - { + { + if (!$this->isValidName($customer->getFirstname())) { + $firstname = __('Firstname'); + parent::_addMessages([__( + '%1 is not valid! Allowed characters: %2', + $firstname, + $this->nameValidator->allowedCharsDescription + )]); + } - $nameFields = [ - 'Firstname' => $customer->getFirstname(), - 'Lastname' => $customer->getLastname(), - 'Middlename' => $customer->getMiddlename() - ]; + if (!$this->isValidName($customer->getLastname())) { + $lastname = __('Lastname'); + parent::_addMessages([__( + '%1 is not valid! Allowed characters: %2', + $lastname, + $this->nameValidator->allowedCharsDescription + )]); + } - foreach ($nameFields as $fieldName => $fieldValue) { - if (!empty($fieldValue) && !$this->isValidName($fieldValue)) { - parent::_addMessages( - [ - __( - '%1 is not valid! Allowed characters: %2', - $fieldName, - $this->nameValidator->allowedCharsDescription - ), - ] - ); - } + if (!$this->isValidName($customer->getMiddlename())) { + $middlename = __('Middlename'); + parent::_addMessages([__( + '%1 is not valid! Allowed characters: %2', + $middlename, + $this->nameValidator->allowedCharsDescription + )]); } return count($this->_messages) == 0; From 28eca911db8028ef78c467b5a61580b0a3bd0906 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 12 Sep 2024 10:44:56 +0200 Subject: [PATCH 114/148] Update NameTest.php --- .../Customer/Test/Unit/Model/Validator/NameTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 7f43fb7ee946d..473eee855b751 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -23,11 +23,6 @@ class NameTest extends TestCase */ private Name $nameValidator; - /** - * @var NameValidator|MockObject - */ - private MockObject $nameValidatorMock; - /** * @var Customer|MockObject */ @@ -38,8 +33,7 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->nameValidatorMock = $this->createMock(NameValidator::class); - $this->nameValidator = new Name($this->nameValidatorMock); + $this->nameValidator = new Name; $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() From fc3bf8ad88b070f99347b0f67c69f954187d92e4 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 12 Sep 2024 16:09:24 +0200 Subject: [PATCH 115/148] Update Name.php --- .../Magento/Customer/Model/Validator/Name.php | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index a782a3d309d49..8a08d72634f04 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -39,33 +39,26 @@ public function __construct(NameValidator $nameValidator) */ public function isValid($customer): bool { - if (!$this->isValidName($customer->getFirstname())) { - $firstname = __('Firstname'); - parent::_addMessages([__( - '%1 is not valid! Allowed characters: %2', - $firstname, - $this->nameValidator->allowedCharsDescription - )]); + $nameFields = [ + 'Firstname' => $customer->getFirstname(), + 'Lastname' => $customer->getLastname(), + 'Middlename' => $customer->getMiddlename() + ]; + + foreach ($nameFields as $fieldName => $fieldValue) { + if (!empty($fieldValue) && !$this->isValidName($fieldValue)) { + parent::_addMessages( + [ + __( + '%1 is not valid! Allowed characters: %2', + $fieldName, + $this->nameValidator->allowedCharsDescription + ), + ] + ); + } } - - if (!$this->isValidName($customer->getLastname())) { - $lastname = __('Lastname'); - parent::_addMessages([__( - '%1 is not valid! Allowed characters: %2', - $lastname, - $this->nameValidator->allowedCharsDescription - )]); - } - - if (!$this->isValidName($customer->getMiddlename())) { - $middlename = __('Middlename'); - parent::_addMessages([__( - '%1 is not valid! Allowed characters: %2', - $middlename, - $this->nameValidator->allowedCharsDescription - )]); - } - + return count($this->_messages) == 0; } From bd00a9fc5afc00ea900f104d458dd3c981eb6b81 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 12 Sep 2024 16:10:00 +0200 Subject: [PATCH 116/148] Update NameTest.php --- .../Customer/Test/Unit/Model/Validator/NameTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 473eee855b751..7f43fb7ee946d 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -23,6 +23,11 @@ class NameTest extends TestCase */ private Name $nameValidator; + /** + * @var NameValidator|MockObject + */ + private MockObject $nameValidatorMock; + /** * @var Customer|MockObject */ @@ -33,7 +38,8 @@ class NameTest extends TestCase */ protected function setUp(): void { - $this->nameValidator = new Name; + $this->nameValidatorMock = $this->createMock(NameValidator::class); + $this->nameValidator = new Name($this->nameValidatorMock); $this->customerMock = $this ->getMockBuilder(Customer::class) ->disableOriginalConstructor() From 2994442c5d580824959a83c01386b2409adba123 Mon Sep 17 00:00:00 2001 From: in-session Date: Fri, 13 Sep 2024 10:53:14 +0200 Subject: [PATCH 117/148] Update NameValidator.php --- .../Model/Validator/Pattern/NameValidator.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php index 410492b630c23..368571ca2595e 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php @@ -109,17 +109,19 @@ public function isValidationEnabled(): bool */ public function isValid($value): bool { - if ($value === null || $value === '' || !is_string($value)) { - return true; + if ($value === null) { + return true; } $pattern = $this->isValidationEnabled() ? $this->patternName : self::PATTERN_NAME; - $trimmedValue = trim($value); - if (preg_match($pattern, $trimmedValue, $matches)) { - return $matches[0] === $trimmedValue; + if (is_string($value)) { + $trimmedValue = trim($value); + if (preg_match($pattern, $trimmedValue, $matches)) { + return $matches[0] === $trimmedValue; + } } - - return preg_match($pattern, trim($value)) === 1; + + return true; } } From 5270e465f9bdc772aae0b04e362ed9e3da1f204c Mon Sep 17 00:00:00 2001 From: in-session Date: Fri, 13 Sep 2024 15:31:59 +0200 Subject: [PATCH 118/148] Update Name.php --- .../Magento/Customer/Model/Validator/Name.php | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 8a08d72634f04..3cb5a5c856095 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -39,24 +39,16 @@ public function __construct(NameValidator $nameValidator) */ public function isValid($customer): bool { - $nameFields = [ - 'Firstname' => $customer->getFirstname(), - 'Lastname' => $customer->getLastname(), - 'Middlename' => $customer->getMiddlename() - ]; - - foreach ($nameFields as $fieldName => $fieldValue) { - if (!empty($fieldValue) && !$this->isValidName($fieldValue)) { - parent::_addMessages( - [ - __( - '%1 is not valid! Allowed characters: %2', - $fieldName, - $this->nameValidator->allowedCharsDescription - ), - ] - ); - } + 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; @@ -68,7 +60,7 @@ public function isValid($customer): bool * @param string|null $nameValue * @return bool */ - private function isValidName(?string $nameValue): bool + private function isValidName($nameValue): bool { return $this->nameValidator->isValid($nameValue); } From 3220efbb7dbf334934f5148d499daf86ce6ba5b2 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:07:46 +0100 Subject: [PATCH 119/148] Update CityTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/CityTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php index 1e439b00af288..87626308e324d 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/CityTest.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:08:38 +0100 Subject: [PATCH 120/148] Update StreetTest.php --- .../Customer/Test/Unit/Model/Validator/StreetTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php index 64d77d3612c9b..85868689dd87a 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/StreetTest.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:09:09 +0100 Subject: [PATCH 121/148] Update TelephoneTest.php --- .../Customer/Test/Unit/Model/Validator/TelephoneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index ab3f44db2a03a..3da85e97a78ce 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -71,7 +71,7 @@ public function testValidateCorrectPunctuationInTelephone( /** * @return array */ - public function expectedPunctuationInTelephoneDataProvider(): array + public static function expectedPunctuationInNamesDataProvider(): array { return [ [ From c64a3e2aa01f1825b53a2b13d833e7247594150c Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:09:44 +0100 Subject: [PATCH 122/148] Update TelephoneTest.php --- .../Customer/Test/Unit/Model/Validator/TelephoneTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php index 3da85e97a78ce..374622fecd8d3 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/TelephoneTest.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:10:38 +0100 Subject: [PATCH 123/148] Update NameTest.php --- .../Magento/Customer/Test/Unit/Model/Validator/NameTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php index 7f43fb7ee946d..b0d4172eca3da 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Validator/NameTest.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:10:56 +0100 Subject: [PATCH 124/148] Update Mail.php --- app/code/Magento/Contact/Model/Mail.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Contact/Model/Mail.php b/app/code/Magento/Contact/Model/Mail.php index 111b238a7562a..1baa1b7f476e5 100644 --- a/app/code/Magento/Contact/Model/Mail.php +++ b/app/code/Magento/Contact/Model/Mail.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:11:19 +0100 Subject: [PATCH 125/148] Update Email.php --- app/code/Magento/Contact/Model/Validator/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Contact/Model/Validator/Email.php b/app/code/Magento/Contact/Model/Validator/Email.php index a1f6c565c3e07..baf98d62254b0 100644 --- a/app/code/Magento/Contact/Model/Validator/Email.php +++ b/app/code/Magento/Contact/Model/Validator/Email.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:11:44 +0100 Subject: [PATCH 126/148] Update ForbiddenPattern.php --- app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php index 4b1b0a098f945..2bb404c846d16 100644 --- a/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php +++ b/app/code/Magento/Contact/Model/Validator/ForbiddenPattern.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:12:03 +0100 Subject: [PATCH 127/148] Update validation.xml --- app/code/Magento/Contact/etc/validation.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Contact/etc/validation.xml b/app/code/Magento/Contact/etc/validation.xml index 86fb0c7df86d8..6bf33cc0e6217 100644 --- a/app/code/Magento/Contact/etc/validation.xml +++ b/app/code/Magento/Contact/etc/validation.xml @@ -1,8 +1,8 @@ From b03042eee51efca49ba96a5e4671782a274a1288 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:12:24 +0100 Subject: [PATCH 128/148] Update City.php --- app/code/Magento/Customer/Model/Validator/City.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/City.php b/app/code/Magento/Customer/Model/Validator/City.php index 146a3bce4dca7..b2e8aedd8ca3e 100644 --- a/app/code/Magento/Customer/Model/Validator/City.php +++ b/app/code/Magento/Customer/Model/Validator/City.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:12:48 +0100 Subject: [PATCH 129/148] Update Email.php --- app/code/Magento/Customer/Model/Validator/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Email.php b/app/code/Magento/Customer/Model/Validator/Email.php index 598b0a9682cbb..be1d1905104fd 100644 --- a/app/code/Magento/Customer/Model/Validator/Email.php +++ b/app/code/Magento/Customer/Model/Validator/Email.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:13:32 +0100 Subject: [PATCH 130/148] Update ForbiddenPattern.php --- .../Magento/Customer/Model/Validator/ForbiddenPattern.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php index 0b4c0fcf51468..be7377e0e8e4a 100644 --- a/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php +++ b/app/code/Magento/Customer/Model/Validator/ForbiddenPattern.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:13:55 +0100 Subject: [PATCH 131/148] Update Name.php --- app/code/Magento/Customer/Model/Validator/Name.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Name.php b/app/code/Magento/Customer/Model/Validator/Name.php index 3cb5a5c856095..ff714030cadb1 100644 --- a/app/code/Magento/Customer/Model/Validator/Name.php +++ b/app/code/Magento/Customer/Model/Validator/Name.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:14:16 +0100 Subject: [PATCH 132/148] Update CityValidator.php --- .../Customer/Model/Validator/Pattern/CityValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php index 4bd3fb8efae2d..c188ec049533e 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/CityValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:16:03 +0100 Subject: [PATCH 133/148] Update EmailAddressValidator.php --- .../Model/Validator/Pattern/EmailAddressValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php index 9bd9c763870c3..0a6d75505b2aa 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/EmailAddressValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:17:15 +0100 Subject: [PATCH 134/148] Update ForbiddenValidator.php --- .../Customer/Model/Validator/Pattern/ForbiddenValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php index 40d97e6c6af6c..e552676de8f56 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/ForbiddenValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:19:01 +0100 Subject: [PATCH 135/148] Update NameValidator.php --- .../Customer/Model/Validator/Pattern/NameValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php index 368571ca2595e..e0986e9e04d7b 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/NameValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:19:24 +0100 Subject: [PATCH 136/148] Update StreetValidator.php --- .../Customer/Model/Validator/Pattern/StreetValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php index ae3446afb6b11..37b576354655d 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/StreetValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:19:51 +0100 Subject: [PATCH 137/148] Update TelephoneValidator.php --- .../Customer/Model/Validator/Pattern/TelephoneValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php b/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php index 6b73da5184dd2..7bbd04085e720 100644 --- a/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php +++ b/app/code/Magento/Customer/Model/Validator/Pattern/TelephoneValidator.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:20:49 +0100 Subject: [PATCH 138/148] Update Street.php --- app/code/Magento/Customer/Model/Validator/Street.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Street.php b/app/code/Magento/Customer/Model/Validator/Street.php index ef309e7b7a703..5311eb526c2c6 100644 --- a/app/code/Magento/Customer/Model/Validator/Street.php +++ b/app/code/Magento/Customer/Model/Validator/Street.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:21:14 +0100 Subject: [PATCH 139/148] Update Telephone.php --- app/code/Magento/Customer/Model/Validator/Telephone.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Validator/Telephone.php b/app/code/Magento/Customer/Model/Validator/Telephone.php index 61151a2eefbf0..78ba26854669d 100644 --- a/app/code/Magento/Customer/Model/Validator/Telephone.php +++ b/app/code/Magento/Customer/Model/Validator/Telephone.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:21:37 +0100 Subject: [PATCH 140/148] Update system.xml --- app/code/Magento/Customer/etc/adminhtml/system.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/etc/adminhtml/system.xml b/app/code/Magento/Customer/etc/adminhtml/system.xml index 61fbc2358bc58..de12213ba5f4e 100644 --- a/app/code/Magento/Customer/etc/adminhtml/system.xml +++ b/app/code/Magento/Customer/etc/adminhtml/system.xml @@ -1,8 +1,8 @@ From c7e77d221a35daa59b74cc8d875ccbb5d4b65aa4 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:21:56 +0100 Subject: [PATCH 141/148] Update validation.xml --- app/code/Magento/Customer/etc/validation.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/etc/validation.xml b/app/code/Magento/Customer/etc/validation.xml index 5f8539660d2cc..225d22a46ff89 100644 --- a/app/code/Magento/Customer/etc/validation.xml +++ b/app/code/Magento/Customer/etc/validation.xml @@ -1,8 +1,8 @@ From bd3503a55849fff36e5644424814581b9918e5e7 Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:22:16 +0100 Subject: [PATCH 142/148] Update SubscriptionManager.php --- app/code/Magento/Newsletter/Model/SubscriptionManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Newsletter/Model/SubscriptionManager.php b/app/code/Magento/Newsletter/Model/SubscriptionManager.php index c37fa9cdf542f..3af18adaad521 100644 --- a/app/code/Magento/Newsletter/Model/SubscriptionManager.php +++ b/app/code/Magento/Newsletter/Model/SubscriptionManager.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:23:30 +0100 Subject: [PATCH 143/148] Update Email.php --- app/code/Magento/Newsletter/Model/Validator/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Newsletter/Model/Validator/Email.php b/app/code/Magento/Newsletter/Model/Validator/Email.php index a7d1935e0c59b..6d695577eaaea 100644 --- a/app/code/Magento/Newsletter/Model/Validator/Email.php +++ b/app/code/Magento/Newsletter/Model/Validator/Email.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:25:12 +0100 Subject: [PATCH 144/148] Update validation.xml --- app/code/Magento/Newsletter/etc/validation.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Newsletter/etc/validation.xml b/app/code/Magento/Newsletter/etc/validation.xml index d84de2af61ce8..2721621d5509c 100644 --- a/app/code/Magento/Newsletter/etc/validation.xml +++ b/app/code/Magento/Newsletter/etc/validation.xml @@ -1,8 +1,8 @@ From a75c31e790b80c8208d24e6751a9eba73273265b Mon Sep 17 00:00:00 2001 From: in-session Date: Thu, 31 Oct 2024 06:26:00 +0100 Subject: [PATCH 145/148] Update Review.php --- app/code/Magento/Review/Model/Review.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/Model/Review.php b/app/code/Magento/Review/Model/Review.php index f2c0e16603d80..e8f22c8e38da1 100644 --- a/app/code/Magento/Review/Model/Review.php +++ b/app/code/Magento/Review/Model/Review.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:26:38 +0100 Subject: [PATCH 146/148] Update Email.php --- app/code/Magento/Review/Model/Validator/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/Model/Validator/Email.php b/app/code/Magento/Review/Model/Validator/Email.php index 4cde7050ae978..7a66948865705 100644 --- a/app/code/Magento/Review/Model/Validator/Email.php +++ b/app/code/Magento/Review/Model/Validator/Email.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:27:22 +0100 Subject: [PATCH 147/148] Update ForbiddenPattern.php --- app/code/Magento/Review/Model/Validator/ForbiddenPattern.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php b/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php index 0ed63980c816a..36e9f1f70b6ea 100644 --- a/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php +++ b/app/code/Magento/Review/Model/Validator/ForbiddenPattern.php @@ -1,7 +1,7 @@ Date: Thu, 31 Oct 2024 06:30:24 +0100 Subject: [PATCH 148/148] Update validation.xml --- app/code/Magento/Review/etc/validation.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/etc/validation.xml b/app/code/Magento/Review/etc/validation.xml index ed0264790a46f..2e39bd21de89e 100644 --- a/app/code/Magento/Review/etc/validation.xml +++ b/app/code/Magento/Review/etc/validation.xml @@ -1,8 +1,8 @@