/** * Performs user login */ protected function _login() { \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Backend\\Model\\UrlInterface')->turnOffSecretKey(); $this->_auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Backend\\Model\\Auth'); $this->_auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $this->_session = $this->_auth->getAuthStorage(); }
/** * Disabled form security in order to prevent exit from the app * @magentoConfigFixture current_store admin/security/session_lifetime 59 */ public function testIsLoggedInWithIgnoredLifetime() { $this->_auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $this->assertTrue($this->_model->isLoggedIn()); $this->_model->setUpdatedAt(time() - 101); $this->assertTrue($this->_model->isLoggedIn()); }
/** * @dataProvider loginDataProvider */ public function testIsLoggedIn($loggedIn) { if ($loggedIn) { $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); } $this->assertEquals($loggedIn, $this->authSession->isLoggedIn()); }
/** * @expectedException \Magento\Backend\Model\Auth\Exception * @expectedExceptionMessage Please correct the user name or password. */ public function testLoginFailed() { $this->_modelFactoryMock->expects($this->once())->method('create')->with('Magento\\Backend\\Model\\Auth\\Credential\\StorageInterface')->will($this->returnValue($this->_credentialStorage)); $exceptionMock = new \Magento\Framework\Model\Exception(); $this->_credentialStorage->expects($this->once())->method('login')->with('username', 'password')->will($this->throwException($exceptionMock)); $this->_credentialStorage->expects($this->never())->method('getId'); $this->_eventManagerMock->expects($this->once())->method('dispatch')->with('backend_auth_user_login_failed'); $this->_model->login('username', 'password'); }
/** * @expectedException \Magento\Framework\Exception\AuthenticationException * @expectedExceptionMessage You did not sign in correctly or your account is temporarily disabled. */ public function testLoginFailed() { $this->_modelFactoryMock->expects($this->once())->method('create')->with('Magento\\Backend\\Model\\Auth\\Credential\\StorageInterface')->will($this->returnValue($this->_credentialStorage)); $exceptionMock = new \Magento\Framework\Exception\LocalizedException(__('You did not sign in correctly or your account is temporarily disabled.')); $this->_credentialStorage->expects($this->once())->method('login')->with('username', 'password')->will($this->throwException($exceptionMock)); $this->_credentialStorage->expects($this->never())->method('getId'); $this->_eventManagerMock->expects($this->once())->method('dispatch')->with('backend_auth_user_login_failed'); $this->_model->login('username', 'password'); }
protected function setUp() { parent::setUp(); $this->_objectManager->get('Magento\\Backend\\Model\\UrlInterface')->turnOffSecretKey(); $this->_auth = $this->_objectManager->get('Magento\\Backend\\Model\\Auth'); $this->_session = $this->_auth->getAuthStorage(); $credentials = $this->_getAdminCredentials(); $this->_auth->login($credentials['user'], $credentials['password']); }
/** * Test of prolong user action * * @magentoDbIsolation enabled */ public function testProcessProlong() { $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $sessionId = $this->authSession->getSessionId(); $dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - 100); $this->adminSessionsManager->getCurrentSession()->setData('updated_at', $dateInPast)->save(); $this->adminSessionInfo->load($sessionId, 'session_id'); $oldUpdatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->authSession->prolong(); $this->adminSessionInfo->load($sessionId, 'session_id'); $updatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->assertGreaterThan($oldUpdatedAt, $updatedAt); }
public function testGetUser() { $this->_model->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $this->assertNotNull($this->_model->getUser()); $this->assertGreaterThan(0, $this->_model->getUser()->getId()); $this->assertInstanceOf('Magento\\Backend\\Model\\Auth\\Credential\\StorageInterface', $this->_model->getUser()); }
/** * {@inheritdoc} */ public function login($username, $password) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'login'); if (!$pluginInfo) { return parent::login($username, $password); } else { return $this->___callPlugins('login', func_get_args(), $pluginInfo); } }
/** * Test if other sessions were logged out if logoutOtherUserSessions() action was performed * * @magentoAdminConfigFixture admin/security/session_lifetime 100 * @magentoConfigFixture default_store admin/security/admin_account_sharing 1 * @magentoDbIsolation enabled */ public function testLogoutOtherUserSessions() { /** @var \Magento\Security\Model\AdminSessionInfo $session */ $session = $this->objectManager->create('Magento\\Security\\Model\\AdminSessionInfo'); $session->setSessionId('669e2e3d752e8')->setUserId(1)->setStatus(1)->setCreatedAt(time() - 50)->setUpdatedAt(time() - 49)->save(); $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $collection = $this->getCollectionForLogoutOtherUserSessions($session); $this->assertGreaterThanOrEqual(1, $collection->getSize()); $this->adminSessionsManager->logoutOtherUserSessions(); $collection = $this->getCollectionForLogoutOtherUserSessions($session); $this->assertEquals(0, $collection->getSize()); }
/** * Performs login, if user submitted login form * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ protected function _performLogin(\Magento\Framework\App\RequestInterface $request) { $outputValue = true; $postLogin = $request->getPost('login'); $username = isset($postLogin['username']) ? $postLogin['username'] : ''; $password = isset($postLogin['password']) ? $postLogin['password'] : ''; $request->setPostValue('login', null); try { $this->_auth->login($username, $password); } catch (AuthenticationException $e) { if (!$request->getParam('messageSent')) { $this->messageManager->addError($e->getMessage()); $request->setParam('messageSent', true); $outputValue = false; } } return $outputValue; }