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 testBeforeSave() { $this->eventManagerMock->expects($this->any())->method('dispatch'); $this->model->setIsActive(1); $actualData = $this->model->beforeSave()->getData(); $this->assertArrayHasKey('extra', $actualData); $this->assertArrayHasKey('password', $actualData); $this->assertArrayHasKey('is_active', $actualData); }
/** * 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); }
/** * @expectedException \Magento\Framework\Exception\AuthenticationException * @magentoDbIsolation enabled */ public function testAuthenticateInactiveUser() { $this->_model->load(1); $this->_model->setIsActive(0)->save(); $this->_model->authenticate(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); }