/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $mockName = 'Test Product Name'; $mockVersion = '0.0.0'; $mockEdition = 'Test Edition'; $mockUrl = 'http://test-url'; $this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName); $this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion); $this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition); $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl); $configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl]; $lastUpdate = 0; $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf(); $this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * Retrieve area front name * * @return string */ public function getFrontName() { $isCustomPathUsed = (bool) (string) $this->config->getValue(self::XML_PATH_USE_CUSTOM_ADMIN_PATH); if ($isCustomPathUsed) { return (string) $this->config->getValue(self::XML_PATH_CUSTOM_ADMIN_PATH); } return $this->defaultFrontName; }
public function __construct(\Magento\Backend\App\ConfigInterface $backendConfig, \Symfony\Component\Yaml\Parser $yamlParser, \Magento\Framework\Filesystem $filesystem, \Magento\Config\Model\Config\Factory $configFactory) { $this->_yamlParser = $yamlParser; $this->_backendConfig = $backendConfig; $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $this->_folderLocation = str_replace('###MAGE_BASE###', $this->_getBaseDir(), $this->_backendConfig->getValue(self::XML_SYSTEM_PATH)); $this->_configFactory = $configFactory; }
/** * Retrieve area front name * * @param bool $checkHost If true, verify front name is valid for this url (hostname is correct) * @return string|bool */ public function getFrontName($checkHost = false) { if ($checkHost && !$this->isHostBackend()) { return false; } $isCustomPathUsed = (bool)(string)$this->config->getValue(self::XML_PATH_USE_CUSTOM_ADMIN_PATH); if ($isCustomPathUsed) { return (string)$this->config->getValue(self::XML_PATH_CUSTOM_ADMIN_PATH); } return $this->defaultFrontName; }
/** * Check verification result and return true if system must to show notification message * * @return bool */ private function _canShowNotification() { if ($this->_cache->load(self::VERIFICATION_RESULT_CACHE_KEY)) { return false; } if ($this->_isFileAccessible()) { return true; } $adminSessionLifetime = (int) $this->_backendConfig->getValue('admin/security/session_lifetime'); $this->_cache->save(true, self::VERIFICATION_RESULT_CACHE_KEY, [], $adminSessionLifetime); return false; }
/** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\ObjectManager\ConfigInterface $config */ public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\ObjectManager\ConfigInterface $config, \Magento\Backend\App\ConfigInterface $backendConfig, \Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Module\ResourceInterface $moduleResource, \Magento\Framework\Module\ModuleList\Loader $loader, \Magento\Framework\Xml\Parser $parser, \Magento\Framework\Filesystem\Driver\File $driver, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\ObjectManagerInterface $objectManager) { $this->_backendConfig = $backendConfig; $this->moduleList = $moduleList; $this->moduleResource = $moduleResource; $this->_loader = $loader; $this->parser = $parser; $this->driver = $driver; $this->_objectManager = $objectManager; $this->urlBuilder = $urlBuilder; $this->productMetadata = $productMetadata; $this->_allowedFeedType = explode(',', $backendConfig->getValue(\Ced\DevTool\Model\Feed::XML_FEED_TYPES)); parent::__construct($context); }
/** * Authenticate user name and password and save loaded record * * @param string $username * @param string $password * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function authenticate($username, $password) { $config = $this->_config->isSetFlag('admin/security/use_case_sensitive_login'); $result = false; try { $this->_eventManager->dispatch( 'admin_user_authenticate_before', ['username' => $username, 'user' => $this] ); $this->loadByUsername($username); $sensitive = $config ? $username == $this->getUsername() : true; if ($sensitive && $this->getId()) { $result = $this->verifyIdentity($password); } $this->_eventManager->dispatch( 'admin_user_authenticate_after', ['username' => $username, 'password' => $password, 'user' => $this, 'result' => $result] ); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->unsetData(); throw $e; } if (!$result) { $this->unsetData(); } return $result; }
/** * @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); }
/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $lastUpdate = 1410121748; $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->any())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->deploymentConfig->expects($this->once())->method('get')->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * Set session UpdatedAt to current time and update cookie expiration time * * @return void */ public function prolong() { $lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME); $currentTime = time(); $this->setUpdatedAt($currentTime); $cookieValue = $this->_cookie->get($this->getName()); if ($cookieValue) { $this->_cookie->set($this->getName(), $cookieValue, $lifetime, $this->sessionConfig->getCookiePath(), $this->sessionConfig->getCookieDomain(), $this->sessionConfig->getCookieSecure(), $this->sessionConfig->getCookieHttpOnly()); } }
/** * Set session UpdatedAt to current time and update cookie expiration time * * @return void */ public function prolong() { $lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME); $currentTime = time(); $this->setUpdatedAt($currentTime); $cookieValue = $this->cookieManager->getCookie($this->getName()); if ($cookieValue) { $cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration($lifetime)->setPath($this->sessionConfig->getCookiePath())->setDomain($this->sessionConfig->getCookieDomain())->setSecure($this->sessionConfig->getCookieSecure())->setHttpOnly($this->sessionConfig->getCookieHttpOnly()); $this->cookieManager->setPublicCookie($this->getName(), $cookieValue, $cookieMetadata); } }
public function testTrackAdminPassword() { $newPW = "mYn3wpassw0rd"; $uid = 123; /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */ $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock(); /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */ $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getObject'])->getMock(); /** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */ $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getPassword', 'getForceNewPassword'])->getMock(); $eventObserverMock->expects($this->once())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getObject')->willReturn($userMock); $userMock->expects($this->once())->method('getId')->willReturn($uid); $userMock->expects($this->once())->method('getPassword')->willReturn($newPW); $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1); $userMock->expects($this->once())->method('getForceNewPassword')->willReturn(false); /** @var \Magento\Framework\Message\Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */ $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock(); $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock); $this->authSessionMock->expects($this->once())->method('unsPciAdminUserIsPasswordExpired')->willReturn(null); $this->model->execute($eventObserverMock); }
/** * Check if user is logged in * * @return boolean */ public function isLoggedIn() { $lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME); $currentTime = time(); /* Validate admin session lifetime that should be more than 60 seconds */ if ($lifetime >= 60 && $this->getUpdatedAt() < $currentTime - $lifetime) { return false; } if ($this->getUser() && $this->getUser()->getId()) { return true; } return false; }
/** * @return void */ public function testCustomerHasFailedMaxNumberOfAttempts() { $customerId = 1; $date = new \DateTime(); $date->modify('-500 second'); $formattedDate = $date->format('Y-m-d H:i:s'); $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Helper\AccountManagement::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Helper\AccountManagement::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(10, 5); $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->customerSecure->expects($this->once())->method('getFailuresNum')->willReturn(5); $this->customerSecure->expects($this->once())->method('getFirstFailure')->willReturn($formattedDate); $this->customerSecure->expects($this->once())->method('setLockExpires'); $this->customerSecure->expects($this->once())->method('setFailuresNum'); $this->helper->processCustomerLockoutData($customerId); }
public function testForceAdminPasswordChange() { /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */ $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock(); /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */ $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getControllerAction', 'getRequest'])->getMock(); $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1); $this->authSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true); $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock); /** @var \Magento\Framework\App\Action\Action $controllerMock */ $controllerMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\AbstractAction')->disableOriginalConstructor()->setMethods(['getRedirect', 'getRequest'])->getMockForAbstractClass(); /** @var \Magento\Framework\App\RequestInterface $requestMock */ $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getFullActionName', 'setDispatched'])->getMockForAbstractClass(); $eventMock->expects($this->once())->method('getControllerAction')->willReturn($controllerMock); $eventMock->expects($this->once())->method('getRequest')->willReturn($requestMock); $this->authSessionMock->expects($this->once())->method('getPciAdminUserIsPasswordExpired')->willReturn(true); $requestMock->expects($this->once())->method('getFullActionName')->willReturn('not_in_array'); $this->authSessionMock->expects($this->once())->method('clearStorage'); $this->sessionMock->expects($this->once())->method('clearStorage'); $this->managerInterfaceMock->expects($this->once())->method('addErrorMessage'); $controllerMock->expects($this->once())->method('getRequest')->willReturn($requestMock); $requestMock->expects($this->once())->method('setDispatched')->willReturn(false); $this->model->execute($eventObserverMock); }
public function testSendPasswordResetConfirmationEmail() { $storeId = 0; $email = '*****@*****.**'; $firstName = 'Foo'; $lastName = 'Bar'; $this->_model->setEmail($email); $this->_model->setFirstname($firstName); $this->_model->setLastname($lastName); $this->_configMock->expects($this->at(0))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE)->will($this->returnValue('templateId')); $this->_configMock->expects($this->at(1))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY)->will($this->returnValue('sender')); $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(['user' => $this->_model, 'store' => $this->_storetMock])->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('addTo')->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName))->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setFrom')->with('sender')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with('templateId')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transportMock)); $this->_transportMock->expects($this->once())->method('sendMessage'); $this->_storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($this->_storetMock)); $this->assertInstanceOf('\\Magento\\User\\Model\\User', $this->_model->sendPasswordResetConfirmationEmail()); }
/** * @param bool $result * @dataProvider validateCustomerPassword */ public function testValidateCustomerPassword($result) { $customerId = 7; $password = '******'; $hash = '1b2af329dd0'; $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturn($customerMock); $this->customerSecure->expects($this->any())->method('getId')->willReturn($customerId); $this->customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($hash); $this->customerRegistryMock->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $hash)->willReturn($result); if ($result) { $this->assertTrue($this->authentication->authenticate($customerId, $password)); } else { $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(1, 1); $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(false); $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure); $this->customerRepositoryMock->expects($this->once())->method('save')->willReturn($customerMock); $this->setExpectedException('\\Magento\\Framework\\Exception\\InvalidEmailOrPasswordException'); $this->authentication->authenticate($customerId, $password); } }
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); }
/** * Get admin maxiumum security failures from config * * @return int */ public function getMaxFailures() { return (int) $this->backendConfig->getValue('admin/security/lockout_failures'); }
/** * Authenticate user name and password and save loaded record * * @param string $username * @param string $password * @return bool * @throws \Magento\Framework\Model\Exception * @throws \Magento\Backend\Model\Auth\Exception * @throws \Magento\Backend\Model\Auth\Plugin\Exception */ public function authenticate($username, $password) { $config = $this->_config->isSetFlag('admin/security/use_case_sensitive_login'); $result = false; try { $this->_eventManager->dispatch('admin_user_authenticate_before', array('username' => $username, 'user' => $this)); $this->loadByUsername($username); $sensitive = $config ? $username == $this->getUsername() : true; if ($sensitive && $this->getId() && $this->_encryptor->validateHash($password, $this->getPassword())) { if ($this->getIsActive() != '1') { throw new \Magento\Backend\Model\Auth\Exception(__('This account is inactive.')); } if (!$this->hasAssigned2Role($this->getId())) { throw new \Magento\Backend\Model\Auth\Exception(__('Access denied.')); } $result = true; } $this->_eventManager->dispatch('admin_user_authenticate_after', array('username' => $username, 'password' => $password, 'user' => $this, 'result' => $result)); } catch (\Magento\Framework\Model\Exception $e) { $this->unsetData(); throw $e; } if (!$result) { $this->unsetData(); } return $result; }
/** * Check whether URL for corresponding path should use https protocol * * @param string $path * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function _shouldBeSecure($path) { return substr((string) $this->_coreConfig->getValue('web/unsecure/base_url', 'default'), 0, 5) === 'https' || $this->_backendConfig->isSetFlag('web/secure/use_in_adminhtml') && substr((string) $this->_coreConfig->getValue('web/secure/base_url', 'default'), 0, 5) === 'https'; }
/** * Get general interface locale * * @return string */ public function getGeneralLocale() { return $this->_backendConfig->getValue('general/locale/code'); }
public function testGetResetPasswordLinkExpirationPeriod() { $value = '123'; $this->configMock->expects($this->once())->method('getValue')->with(\Magento\User\Helper\Data::XML_PATH_ADMIN_RESET_PASSWORD_LINK_EXPIRATION_PERIOD)->willReturn($value); $this->assertEquals((int) $value, $this->model->getResetPasswordLinkExpirationPeriod()); }
/** * Retrieve customer reset password link expiration period in days * * @return int */ public function getResetPasswordLinkExpirationPeriod() { return (int) $this->_config->getValue(self::XML_PATH_ADMIN_RESET_PASSWORD_LINK_EXPIRATION_PERIOD); }
/** * {@inheritdoc} * * @return string */ public function getDefaultPath() { return $this->backendConfig->getValue('web/default/admin'); }
/** * @param \Magento\Backend\App\ConfigInterface $config * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __construct(\Magento\Backend\App\ConfigInterface $config) { $pathParts = explode('/', $config->getValue('web/default/admin')); $this->_parts = ['area' => isset($pathParts[0]) ? $pathParts[0] : '', 'module' => isset($pathParts[1]) ? $pathParts[1] : 'admin', 'controller' => isset($pathParts[2]) ? $pathParts[2] : 'index', 'action' => isset($pathParts[3]) ? $pathParts[3] : 'index']; }
/** * Returns URL to controller action which returns new captcha image * * @return string */ public function getRefreshUrl() { return $this->_url->getUrl('adminhtml/refresh/refresh', ['_secure' => $this->_config->isSetFlag('web/secure/use_in_adminhtml'), '_nosecret' => true]); }
/** * Retrieve Update Frequency * * @return int */ public function getFrequency() { return $this->_backendConfig->getValue(self::XML_FREQUENCY_PATH) * 3600; }
/** * {@inheritdoc} */ public function isActive($scope = null) { return $this->config->isSetFlag('dev/translate_inline/active_admin'); }
/** * Returns config value for admin captcha * * @param string $key The last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive) * @param \Magento\Store\Model\Store $store * @return \Magento\Framework\App\Config\Element */ public function getConfig($key, $store = null) { return $this->_backendConfig->getValue('admin/captcha/' . $key); }