Пример #1
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @return void
  */
 public function testAuthenticateException()
 {
     $username = '******';
     $password = '******';
     $config = 'config';
     $this->configMock->expects($this->once())->method('isSetFlag')->with('admin/security/use_case_sensitive_login')->willReturn($config);
     $this->eventManagerMock->expects($this->any())->method('dispatch');
     $this->resourceMock->expects($this->once())->method('loadByUsername')->willThrowException(new \Magento\Framework\Exception\LocalizedException(__()));
     $this->model->authenticate($username, $password);
 }
Пример #2
0
 public function testCheckPasswordChangeValid()
 {
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(true);
     $newPassword = "******";
     $newPasswordHash = "new password hash";
     $oldPassword = "******";
     $this->model->setPassword($newPassword)->setId(1)->setOrigData('password', $oldPassword);
     $this->encryptorMock->expects($this->once())->method('isValidHash')->with($newPassword, $oldPassword)->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->with($newPassword, false)->willReturn($newPasswordHash);
     $this->resourceMock->expects($this->once())->method('getOldPasswords')->willReturn(['hash1', 'hash2']);
     $result = $this->model->validate();
     $this->assertTrue($result);
 }
 /**
  * Test for performIdentityCheck method
  *
  * @param bool $verifyIdentityResult
  * @param bool $lockExpires
  * @dataProvider dataProviderPerformIdentityCheck
  */
 public function testPerformIdentityCheck($verifyIdentityResult, $lockExpires)
 {
     $password = '******';
     $userName = '******';
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->model->getPassword())->willReturn($verifyIdentityResult);
     $this->model->setIsActive(true);
     $this->resourceMock->expects($this->any())->method('hasAssigned2Role')->willReturn(true);
     $this->model->setUserName($userName);
     $this->model->setLockExpires($lockExpires);
     $this->eventManagerMock->expects($this->any())->method('dispatch')->with('admin_user_authenticate_after', ['username' => $userName, 'password' => $password, 'user' => $this->model, 'result' => $verifyIdentityResult])->willReturnSelf();
     if ($lockExpires) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\State\\UserLockedException', __('Your account is temporarily disabled.'));
     }
     if (!$verifyIdentityResult) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\AuthenticationException', __('You have entered an invalid password for current user.'));
     }
     $this->model->performIdentityCheck($password);
 }
Пример #4
0
 public function testAdminAuthenticateUpdateLockingInfo()
 {
     $password = "******";
     $uid = 123;
     $authResult = false;
     $firstFailure = '1965-07-08 11:14:15.638276';
     $numOfFailures = 5;
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock();
     /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getFailuresNum', 'getFirstFailure'])->getMock();
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getPassword')->willReturn($password);
     $eventMock->expects($this->once())->method('getUser')->willReturn($userMock);
     $eventMock->expects($this->once())->method('getResult')->willReturn($authResult);
     $userMock->expects($this->once())->method('getId')->willReturn($uid);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     $userMock->expects($this->once())->method('getFailuresNum')->willReturn($numOfFailures);
     $userMock->expects($this->once())->method('getFirstFailure')->willReturn($firstFailure);
     $this->userMock->expects($this->once())->method('updateFailure');
     $this->model->execute($eventObserverMock);
 }
 public function testAfterSave()
 {
     $this->userResourceModelMock->expects($this->once())->method('updateRoleUsersAcl')->with($this->roleMock);
     $this->assertInstanceOf('\\Magento\\Authorization\\Model\\Role', $this->model->afterSave($this->roleMock, $this->roleMock));
 }