Skip to content

Commit 0d79b65

Browse files
committed
ACP2E-3501: VAPT: Business Logic Error - future date as customer date of birth
1 parent a3375ba commit 0d79b65

File tree

2 files changed

+27
-10
lines changed
  • app/code/Magento/Customer/Model/Validator
  • dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export

2 files changed

+27
-10
lines changed

app/code/Magento/Customer/Model/Validator/Dob.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,28 @@
99

1010
use DateTimeZone;
1111
use Magento\Customer\Model\Customer;
12+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1213
use Magento\Framework\Validator\AbstractValidator;
14+
use Magento\Store\Model\ScopeInterface;
1315

1416
/**
1517
* Customer dob field validator.
1618
*/
1719
class Dob extends AbstractValidator
1820
{
21+
/**
22+
* @var TimezoneInterface
23+
*/
24+
private $timezone;
25+
26+
/**
27+
* @param TimezoneInterface $timezone
28+
*/
29+
public function __construct(TimezoneInterface $timezone)
30+
{
31+
$this->timezone = $timezone;
32+
}
33+
1934
/**
2035
* Validate dob field.
2136
*
@@ -24,7 +39,9 @@ class Dob extends AbstractValidator
2439
*/
2540
public function isValid($customer): bool
2641
{
27-
$timezone = new DateTimeZone($customer->getStore()->getConfig('general/locale/timezone'));
42+
$storeId = (int)$customer->getStoreId();
43+
$timezone = new DateTimeZone($this->timezone->getConfigTimezone(ScopeInterface::SCOPE_STORE, $storeId));
44+
2845
if (!$this->isValidDob($customer->getDob(), $timezone)) {
2946
$this->_addMessages([['dob' => 'The Date of Birth should not be greater than today.']]);
3047
}
@@ -36,7 +53,7 @@ public function isValid($customer): bool
3653
* Check if specified dob is not in the future
3754
*
3855
* @param string|null $dobValue
39-
* @param DateTimeZone $timezone
56+
* @param DateTimeZone|null $timezone
4057
* @return bool
4158
*/
4259
private function isValidDob(?string $dobValue, ?DateTimeZone $timezone = null): bool

dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright 2012 Adobe
4-
* All Rights Reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*/
66

77
namespace Magento\CustomerImportExport\Model\Export;
@@ -69,12 +69,12 @@ protected function setUp(): void
6969
}
7070

7171
/**
72-
* Export with Multi Websites "Customer Main File".
72+
* Export "Customer Main File".
7373
*
74-
* @magentoDataFixture Magento/Customer/_files/import_export/customers_with_websites.php
74+
* @magentoDataFixture Magento/Customer/_files/import_export/customers.php
7575
* @return void
7676
*/
77-
public function testExportWithMultiWebsites(): void
77+
public function testExport()
7878
{
7979
$this->processCustomerAttribute();
8080
$expectedAttributes = $this->getExpectedAttributes();
@@ -83,12 +83,12 @@ public function testExportWithMultiWebsites(): void
8383
}
8484

8585
/**
86-
* Export "Customer Main File".
86+
* Export with Multi Websites "Customer Main File".
8787
*
88-
* @magentoDataFixture Magento/Customer/_files/import_export/customers.php
88+
* @magentoDataFixture Magento/Customer/_files/import_export/customers_with_websites.php
8989
* @return void
9090
*/
91-
public function testExport()
91+
public function testExportWithMultiWebsites(): void
9292
{
9393
$this->processCustomerAttribute();
9494
$expectedAttributes = $this->getExpectedAttributes();

0 commit comments

Comments
 (0)