Skip to content

Commit d8e4ce6

Browse files
merge magento/2.4.1-develop into magento-honey-badgers/MC-36838
2 parents 814396f + ac45071 commit d8e4ce6

File tree

19 files changed

+849
-112
lines changed

19 files changed

+849
-112
lines changed

app/code/Magento/LoginAsCustomer/Model/ResourceModel/GetAuthenticationDataBySecret.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\LoginAsCustomer\Model\ResourceModel;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\App\ResourceConnection;
11-
use Magento\Framework\Stdlib\DateTime\DateTime;
12+
use Magento\Framework\Encryption\EncryptorInterface;
1213
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Stdlib\DateTime\DateTime;
1315
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1416
use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterface;
1517
use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterfaceFactory;
@@ -40,22 +42,30 @@ class GetAuthenticationDataBySecret implements GetAuthenticationDataBySecretInte
4042
*/
4143
private $authenticationDataFactory;
4244

45+
/**
46+
* @var EncryptorInterface
47+
*/
48+
private $encryptor;
49+
4350
/**
4451
* @param ResourceConnection $resourceConnection
4552
* @param DateTime $dateTime
4653
* @param ConfigInterface $config
4754
* @param AuthenticationDataInterfaceFactory $authenticationDataFactory
55+
* @param EncryptorInterface|null $encryptor
4856
*/
4957
public function __construct(
5058
ResourceConnection $resourceConnection,
5159
DateTime $dateTime,
5260
ConfigInterface $config,
53-
AuthenticationDataInterfaceFactory $authenticationDataFactory
61+
AuthenticationDataInterfaceFactory $authenticationDataFactory,
62+
?EncryptorInterface $encryptor = null
5463
) {
5564
$this->resourceConnection = $resourceConnection;
5665
$this->dateTime = $dateTime;
5766
$this->config = $config;
5867
$this->authenticationDataFactory = $authenticationDataFactory;
68+
$this->encryptor = $encryptor ?? ObjectManager::getInstance()->get(EncryptorInterface::class);
5969
}
6070

6171
/**
@@ -71,9 +81,11 @@ public function execute(string $secret): AuthenticationDataInterface
7181
$this->dateTime->gmtTimestamp() - $this->config->getAuthenticationDataExpirationTime()
7282
);
7383

84+
$hash = $this->encryptor->hash($secret);
85+
7486
$select = $connection->select()
7587
->from(['main_table' => $tableName])
76-
->where('main_table.secret = ?', $secret)
88+
->where('main_table.secret = ?', $hash)
7789
->where('main_table.created_at > ?', $timePoint);
7890

7991
$data = $connection->fetchRow($select);

app/code/Magento/LoginAsCustomer/Model/ResourceModel/SaveAuthenticationData.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\LoginAsCustomer\Model\ResourceModel;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\App\ResourceConnection;
11-
use Magento\Framework\Stdlib\DateTime\DateTime;
12+
use Magento\Framework\Encryption\EncryptorInterface;
1213
use Magento\Framework\Math\Random;
14+
use Magento\Framework\Stdlib\DateTime\DateTime;
1315
use Magento\LoginAsCustomerApi\Api\Data\AuthenticationDataInterface;
1416
use Magento\LoginAsCustomerApi\Api\SaveAuthenticationDataInterface;
1517

@@ -18,6 +20,11 @@
1820
*/
1921
class SaveAuthenticationData implements SaveAuthenticationDataInterface
2022
{
23+
/**
24+
* @var EncryptorInterface
25+
*/
26+
private $encryptor;
27+
2128
/**
2229
* @var ResourceConnection
2330
*/
@@ -37,15 +44,18 @@ class SaveAuthenticationData implements SaveAuthenticationDataInterface
3744
* @param ResourceConnection $resourceConnection
3845
* @param DateTime $dateTime
3946
* @param Random $random
47+
* @param EncryptorInterface $encryptor
4048
*/
4149
public function __construct(
4250
ResourceConnection $resourceConnection,
4351
DateTime $dateTime,
44-
Random $random
52+
Random $random,
53+
?EncryptorInterface $encryptor = null
4554
) {
4655
$this->resourceConnection = $resourceConnection;
4756
$this->dateTime = $dateTime;
4857
$this->random = $random;
58+
$this->encryptor = $encryptor ?? ObjectManager::getInstance()->get(EncryptorInterface::class);
4959
}
5060

5161
/**
@@ -57,16 +67,18 @@ public function execute(AuthenticationDataInterface $authenticationData): string
5767
$tableName = $this->resourceConnection->getTableName('login_as_customer');
5868

5969
$secret = $this->random->getRandomString(64);
70+
$hash = $this->encryptor->hash($secret);
6071

6172
$connection->insert(
6273
$tableName,
6374
[
6475
'customer_id' => $authenticationData->getCustomerId(),
6576
'admin_id' => $authenticationData->getAdminId(),
66-
'secret' => $secret,
77+
'secret' => $hash,
6778
'created_at' => $this->dateTime->gmtDate(),
6879
]
6980
);
81+
7082
return $secret;
7183
}
7284
}

app/code/Magento/LoginAsCustomer/Test/Mftf/ActionGroup/AdminLoginAsCustomerLoginFromCustomerPageManualChooseActionGroup.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
</annotations>
1515
<arguments>
1616
<argument name="customerId" type="string"/>
17-
<argument name="storeViewName" type="string" defaultValue="default"/>
17+
<argument name="storeName" type="string" defaultValue="default"/>
1818
</arguments>
1919

2020
<amOnPage url="{{AdminEditCustomerPage.url(customerId)}}" stepKey="gotoCustomerPage"/>
2121
<waitForPageLoad stepKey="waitForCustomerPageLoad"/>
2222
<click selector="{{AdminCustomerMainActionsSection.loginAsCustomer}}" stepKey="clickLoginAsCustomerLink"/>
23-
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store View" stepKey="seeModal"/>
24-
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25-
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.storeView}}" userInput="{{storeViewName}}" stepKey="selectStoreView"/>
23+
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store" stepKey="seeModal"/>
24+
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25+
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.store}}" userInput="{{storeName}}" stepKey="selectStore"/>
2626
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="clickLogin"/>
2727
<switchToNextTab stepKey="switchToNewTab"/>
2828
<waitForPageLoad stepKey="waitForPageLoad"/>

app/code/Magento/LoginAsCustomer/Test/Mftf/Section/AdminLoginAsCustomerConfirmationModalSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminLoginAsCustomerConfirmationModalSection">
12-
<element name="storeView" type="select" selector="//select[@id='lac-confirmation-popup-store-id']"/>
12+
<element name="store" type="select" selector="//select[@id='lac-confirmation-popup-store-id']"/>
1313
</section>
1414
</sections>

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerAutoDetectionTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<test name="AdminLoginAsCustomerAutoDetectionTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Auto detection"/>
1717
<description

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerManualChooseStoreCodeInUrlTest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<test name="AdminLoginAsCustomerManualChooseStoreCodeInUrlTest" extends="AdminLoginAsCustomerManualChooseTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Manual Choose when store code is added to url"/>
1717
<description
@@ -29,8 +29,8 @@
2929
command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}"
3030
stepKey="disableAddStoreCodeToUrls" after="enableLoginAsCustomerAutoDetection"/>
3131
</after>
32-
<actionGroup ref="AssertStorefrontStoreCodeInUrlActionGroup" stepKey="seeCustomStoreCodeInUrl" after="assertCustomStoreView">
33-
<argument name="storeCode" value="{{customStore.code}}"/>
32+
<actionGroup ref="AssertStorefrontStoreCodeInUrlActionGroup" stepKey="seeCustomStoreViewCodeInUrl" after="assertCustomStoreView">
33+
<argument name="storeCode" value="{{customStoreEN.code}}"/>
3434
</actionGroup>
3535
</test>
3636
</tests>

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerManualChooseTest.xml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
<test name="AdminLoginAsCustomerManualChooseTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Manual Choose"/>
1717
<description
1818
value="Verify admin user can directly login into customer account to Custom store view when Store View To Login In = Manual Choose"/>
1919
<severity value="CRITICAL"/>
2020
<group value="login_as_customer"/>
21-
<skip>
22-
<issueId value="https://github.com/magento/magento2-login-as-customer/issues/58"/>
23-
</skip>
2421
</annotations>
2522
<before>
2623
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
@@ -30,11 +27,23 @@
3027
stepKey="enableLoginAsCustomerManualChoose"/>
3128
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
3229
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
33-
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createCustomStoreView"/>
30+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createCustomStore">
31+
<argument name="website" value="{{_defaultWebsite.name}}"/>
32+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
33+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
34+
</actionGroup>
35+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createFirstCustomStoreView">
36+
<argument name="StoreGroup" value="customStoreGroup"/>
37+
<argument name="customStore" value="customStoreEN"/>
38+
</actionGroup>
39+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondCustomStoreView">
40+
<argument name="StoreGroup" value="customStoreGroup"/>
41+
<argument name="customStore" value="customStoreFR"/>
42+
</actionGroup>
3443
</before>
3544
<after>
36-
<actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteCustomStoreView">
37-
<argument name="customStore" value="customStore"/>
45+
<actionGroup ref="DeleteCustomStoreActionGroup" stepKey="deleteCustomStore">
46+
<argument name="storeGroupName" value="customStoreGroup.name"/>
3847
</actionGroup>
3948
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
4049
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
@@ -49,7 +58,7 @@
4958
<actionGroup ref="AdminLoginAsCustomerLoginFromCustomerPageManualChooseActionGroup"
5059
stepKey="loginAsCustomerFromCustomerPage">
5160
<argument name="customerId" value="$$createCustomer.id$$"/>
52-
<argument name="storeViewName" value="{{customStore.name}}"/>
61+
<argument name="storeName" value="{{customStoreGroup.name}}"/>
5362
</actionGroup>
5463

5564
<!-- Assert Customer logged on on custom store view -->
@@ -58,7 +67,7 @@
5867
<argument name="customerEmail" value="$$createCustomer.email$$"/>
5968
</actionGroup>
6069
<actionGroup ref="StorefrontAssertCustomerOnStoreViewActionGroup" stepKey="assertCustomStoreView">
61-
<argument name="storeViewName" value="{{customStore.name}}"/>
70+
<argument name="storeViewName" value="{{customStoreEN.name}}"/>
6271
</actionGroup>
6372

6473
<!-- Log out Customer and close tab -->

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/StorefrontLoginAsCustomerSeeSpecialPriceOnCategoryTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<description value="Login as customer sees special prices on category"/>
1717
<severity value="CRITICAL"/>
1818
<group value="login_as_customer"/>
19-
<skip>
20-
<issueId value="https://github.com/magento/magento2-login-as-customer/pull/193"/>
21-
</skip>
2219
</annotations>
2320
<before>
2421
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 1"

app/code/Magento/LoginAsCustomerAdminUi/Block/Adminhtml/ConfirmationPopup.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Magento\LoginAsCustomerAdminUi\Block\Adminhtml;
99

1010
use Magento\Backend\Block\Template;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\ConfirmationPopup\Options;
1214
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1315
use Magento\Store\Ui\Component\Listing\Column\Store\Options as StoreOptions;
1416

@@ -35,24 +37,32 @@ class ConfirmationPopup extends Template
3537
*/
3638
private $json;
3739

40+
/**
41+
* @var Options
42+
*/
43+
private $options;
44+
3845
/**
3946
* @param Template\Context $context
4047
* @param StoreOptions $storeOptions
4148
* @param ConfigInterface $config
4249
* @param Json $json
4350
* @param array $data
51+
* @param Options|null $options
4452
*/
4553
public function __construct(
4654
Template\Context $context,
4755
StoreOptions $storeOptions,
4856
ConfigInterface $config,
4957
Json $json,
50-
array $data = []
58+
array $data = [],
59+
?Options $options = null
5160
) {
5261
parent::__construct($context, $data);
5362
$this->storeOptions = $storeOptions;
5463
$this->config = $config;
5564
$this->json = $json;
65+
$this->options = $options ?? ObjectManager::getInstance()->get(Options::class);
5666
}
5767

5868
/**
@@ -65,14 +75,14 @@ public function getJsLayout()
6575
$showStoreViewOptions = $this->config->isStoreManualChoiceEnabled();
6676

6777
$layout['components']['lac-confirmation-popup']['title'] = $showStoreViewOptions
68-
? __('Login as Customer: Select Store View')
78+
? __('Login as Customer: Select Store')
6979
: __('You are about to Login as Customer');
7080
$layout['components']['lac-confirmation-popup']['content'] =
7181
__('Actions taken while in "Login as Customer" will affect actual customer data.');
7282

7383
$layout['components']['lac-confirmation-popup']['showStoreViewOptions'] = $showStoreViewOptions;
7484
$layout['components']['lac-confirmation-popup']['storeViewOptions'] = $showStoreViewOptions
75-
? $this->storeOptions->toOptionArray()
85+
? $this->options->toOptionArray()
7686
: [];
7787

7888
return $this->json->serialize($layout);

0 commit comments

Comments
 (0)