Skip to content

Commit f9c8746

Browse files
author
Hayder Sharhan
committed
MAGETWO-40274: Merge Branches and Stabilize Builds
- Changed AuthObserver to accomodate new changes to the Observer.php class (cause by change of framework class Encryptor). - Updated its unit test.
1 parent 8781bf0 commit f9c8746

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

app/code/Magento/User/Model/Backend/Observer/AuthObserver.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Event\Observer as EventObserver;
1010
use Magento\Framework\Exception\State\UserLockedException;
1111
use Magento\Framework\Encryption\Encryptor;
12+
use Magento\User\Model\User;
1213

1314
/**
1415
* User backend observer model for authentication
@@ -101,6 +102,7 @@ public function __construct(
101102
public function adminAuthenticate($observer)
102103
{
103104
$password = $observer->getEvent()->getPassword();
105+
/** @var User $user */
104106
$user = $observer->getEvent()->getUser();
105107
$authResult = $observer->getEvent()->getResult();
106108

@@ -129,16 +131,9 @@ public function adminAuthenticate($observer)
129131
$latestPassword = $this->userResource->getLatestPassword($user->getId());
130132
$this->_checkExpiredPassword($latestPassword);
131133

132-
// upgrade admin password
133-
$isValidHash = $this->encryptor->isValidHash(
134-
$password,
135-
$user->getPassword()
136-
);
137-
if (!$isValidHash) {
138-
$this->userFactory->create()
139-
->load($user->getId())
140-
->setNewPassword($password)
141-
->setForceNewPassword(true)
134+
if (!$this->encryptor->validateHashVersion($user->getPassword(), true)) {
135+
$user->setPassword($password)
136+
->setData('force_new_password', true)
142137
->save();
143138
}
144139
}

app/code/Magento/User/Test/Unit/Model/Backend/Observer/AuthObserverTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testAdminAuthenticate()
151151
/** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */
152152
$userMock = $this->getMockBuilder('Magento\User\Model\User')
153153
->disableOriginalConstructor()
154-
->setMethods(['getId', 'getLockExpires', 'getPassword'])
154+
->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])
155155
->getMock();
156156

157157
$eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
@@ -180,8 +180,7 @@ public function testAdminAuthenticate()
180180
->willReturn($this->messageInterfaceMock);
181181
$this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf();
182182
$this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired');
183-
$this->encryptorMock->expects($this->once())->method('isValidHashByVersion')->willReturn(true);
184-
$userMock->expects($this->once())->method('getPassword')->willReturn($userPassword);
183+
$this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false);
185184

186185
$this->model->adminAuthenticate($eventObserverMock);
187186
}

0 commit comments

Comments
 (0)