File tree Expand file tree Collapse file tree 2 files changed +7
-13
lines changed
Test/Unit/Model/Backend/Observer Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Original file line number Diff line number Diff line change 9
9
use Magento \Framework \Event \Observer as EventObserver ;
10
10
use Magento \Framework \Exception \State \UserLockedException ;
11
11
use Magento \Framework \Encryption \Encryptor ;
12
+ use Magento \User \Model \User ;
12
13
13
14
/**
14
15
* User backend observer model for authentication
@@ -101,6 +102,7 @@ public function __construct(
101
102
public function adminAuthenticate ($ observer )
102
103
{
103
104
$ password = $ observer ->getEvent ()->getPassword ();
105
+ /** @var User $user */
104
106
$ user = $ observer ->getEvent ()->getUser ();
105
107
$ authResult = $ observer ->getEvent ()->getResult ();
106
108
@@ -129,16 +131,9 @@ public function adminAuthenticate($observer)
129
131
$ latestPassword = $ this ->userResource ->getLatestPassword ($ user ->getId ());
130
132
$ this ->_checkExpiredPassword ($ latestPassword );
131
133
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 )
142
137
->save ();
143
138
}
144
139
}
Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ public function testAdminAuthenticate()
151
151
/** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */
152
152
$ userMock = $ this ->getMockBuilder ('Magento\User\Model\User ' )
153
153
->disableOriginalConstructor ()
154
- ->setMethods (['getId ' , 'getLockExpires ' , 'getPassword ' ])
154
+ ->setMethods (['getId ' , 'getLockExpires ' , 'getPassword ' , ' save ' ])
155
155
->getMock ();
156
156
157
157
$ eventObserverMock ->expects ($ this ->atLeastOnce ())->method ('getEvent ' )->willReturn ($ eventMock );
@@ -180,8 +180,7 @@ public function testAdminAuthenticate()
180
180
->willReturn ($ this ->messageInterfaceMock );
181
181
$ this ->messageInterfaceMock ->expects ($ this ->once ())->method ('setIdentifier ' )->willReturnSelf ();
182
182
$ 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 );
185
184
186
185
$ this ->model ->adminAuthenticate ($ eventObserverMock );
187
186
}
You can’t perform that action at this time.
0 commit comments