public function testVerifyIdentityNoAssignedRoles() { $password = '******'; $this->_encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->_model->getPassword())->will($this->returnValue(true)); $this->_model->setIsActive(true); $this->_resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false)); $this->setExpectedException('Magento\\Framework\\Exception\\AuthenticationException', 'Access denied.'); $this->_model->verifyIdentity($password); }
/** * @return void */ public function testVerifyIdentityNoAssignedRoles() { $password = '******'; $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->model->getPassword())->willReturn(true); $this->model->setIsActive(true); $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->willReturn(false); $this->setExpectedException('Magento\\Framework\\Exception\\AuthenticationException', 'You need more permissions to access this.'); $this->model->verifyIdentity($password); }
/** * @magentoDbIsolation enabled */ public function testBeforeSavePasswordHash() { $this->_model->setUsername('john.doe')->setFirstname('John')->setLastname('Doe')->setEmail('*****@*****.**')->setPassword('123123q'); $this->_model->save(); $this->assertNotContains('123123q', $this->_model->getPassword(), 'Password is expected to be hashed'); $this->assertRegExp('/^[0-9a-f]+:[0-9a-zA-Z]{32}$/', $this->_model->getPassword(), 'Salt is expected to be saved along with the password'); /** @var \Magento\User\Model\User $model */ $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\User\\Model\\User'); $model->load($this->_model->getId()); $this->assertEquals($this->_model->getPassword(), $model->getPassword(), 'Password data has been corrupted during saving'); }
/** * 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); }