Skip to content

Commit

Permalink
Merge branch 'pr882' into b-6.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieg committed Nov 10, 2021
2 parents d98f938 + 012429d commit 2ce41dc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Configuration option `deactivateSmartyForCmsContent` to prevent Smarty from processing content added via CMS
- Method `OxidEsales\EshopCommunity\Core\Model\BaseModel::getRawFieldData()`
- Allows to throw own exception messages in admin login [PR-882](https://github.com/OXID-eSales/oxideshop_ce/pull/882)

### Changed
- Update `symfony/expression-language` component
Expand Down
13 changes: 3 additions & 10 deletions source/Application/Controller/Admin/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OxidEsales\EshopCommunity\Application\Controller\Admin;

use OxidEsales\Eshop\Core\Exception\CookieException;
use OxidEsales\Eshop\Core\Exception\UserException;
use OxidEsales\Eshop\Core\ShopVersion;

Expand Down Expand Up @@ -119,16 +120,8 @@ public function checklogin()
\OxidEsales\Eshop\Core\Registry::getSession()->setVariable('currentadminshop', $iSubshop);
\OxidEsales\Eshop\Core\Registry::getConfig()->setShopId($iSubshop);
}
} catch (UserException $oEx) {
$myUtilsView->addErrorToDisplay('LOGIN_ERROR');
$oStr = getStr();
$this->addTplParam('user', $oStr->htmlspecialchars($sUser));
$this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
$this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));

return;
} catch (\OxidEsales\Eshop\Core\Exception\CookieException $oEx) {
$myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
} catch (UserException|CookieException $oEx) {
$myUtilsView->addErrorToDisplay($oEx);
$oStr = getStr();
$this->addTplParam('user', $oStr->htmlspecialchars($sUser));
$this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
Expand Down
4 changes: 4 additions & 0 deletions source/Application/views/admin/de/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,12 @@
// END deprecated
'SETUP_CONFIGPERMISSIONS_WARNING' => 'WICHTIG: Aus Sicherheitsgründen setzen Sie Ihre config.inc.php Datei auf read-only-Modus!',
'LOGIN_TITLE' => 'OXID eShop Login',
// @deprecated 6.10.0
'LOGIN_ERROR' => 'Fehler! Falscher Benutzername und/oder Passwort.',
'LOGIN_NO_COOKIE_SUPPORT' => 'Fehler! Ihr Browser unterstützt keine Cookies.',
// END deprecated
'ERROR_MESSAGE_USER_NOVALIDLOGIN' => 'Fehler! Falscher Benutzername und/oder Passwort.',
'ERROR_MESSAGE_COOKIE_NOCOOKIE' => 'Fehler! Ihr Browser unterstützt keine Cookies.',
'LOGIN_LANGUAGE' => 'Sprache',
'LOGIN_PROFILE' => 'Profil',
'LOGIN_START' => 'OXID eShop Admin starten',
Expand Down
4 changes: 4 additions & 0 deletions source/Application/views/admin/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,12 @@
// END deprecated
'SETUP_CONFIGPERMISSIONS_WARNING' => 'Due to security reasons put your config.inc.php file to read-only mode!',
'LOGIN_TITLE' => 'OXID eShop Login',
// @deprecated 6.10.0
'LOGIN_ERROR' => 'Error! Incorrect username and/or password!',
'LOGIN_NO_COOKIE_SUPPORT' => 'Error! Your browser does not support cookies!',
// END deprecated
'ERROR_MESSAGE_USER_NOVALIDLOGIN' => 'Error! Incorrect username and/or password!',
'ERROR_MESSAGE_COOKIE_NOCOOKIE' => 'Error! Your browser does not support cookies!',
'LOGIN_LANGUAGE' => 'Language',
'LOGIN_PROFILE' => 'Profile',
'LOGIN_START' => 'Start OXID eShop Admin',
Expand Down
39 changes: 16 additions & 23 deletions tests/Unit/Application/Controller/Admin/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testLogin()
public function testLoginNotAdmin()
{
$this->expectException('oxException');
$this->expectExceptionMessage('LOGIN_ERROR');
$this->expectExceptionMessage('ERROR_MESSAGE_USER_NOVALIDLOGIN');

$oUser = oxNew("oxUser");
$oUser->setId("_testUserId");
Expand Down Expand Up @@ -286,13 +286,19 @@ public function testCheckloginSettingProfile()
}

/**
* Testing login::checklogin()
* Testing login::checklogin() exception cases
*
* @return null
* @dataProvider checkLoginExceptionDataProvider
*/
public function testCheckloginUserException()
public function testCheckloginException($exception)
{
oxTestModules::addFunction('oxuser', 'login', '{ throw new oxUserException(); }');
$userMock = $this->createPartialMock(User::class, ['login']);
$userMock->expects($this->once())->method('login')->willThrowException($exception);
\OxidEsales\Eshop\Core\Registry::getUtilsObject()::setClassInstance(User::class, $userMock);

$utilsViewMock = $this->createPartialMock(\OxidEsales\Eshop\Core\UtilsView::class, ['addErrorToDisplay']);
$utilsViewMock->expects($this->atLeastOnce())->method('addErrorToDisplay')->with($exception);
\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\UtilsView::class, $utilsViewMock);

$this->setRequestParameter('user', '\'"<^%&*aaa>');
$this->setRequestParameter('pwd', '<^%&*aaa>\'"');
Expand All @@ -306,25 +312,12 @@ public function testCheckloginUserException()
$this->assertNull($oView->checklogin());
}

/**
* Testing login::checklogin()
*
* @return null
*/
public function testCheckloginCookieException()
public function checkLoginExceptionDataProvider()
{
oxTestModules::addFunction('oxuser', 'login', '{ throw new oxCookieException(); }');

$this->setRequestParameter('user', '\'"<^%&*aaa>');
$this->setRequestParameter('pwd', '<^%&*aaa>\'"');
$this->setRequestParameter('profile', '<^%&*aaa>\'"');
$this->setAdminMode(true);
$this->getSession()->setVariable("blIsAdmin", true);
$oView = $this->getMock(\OxidEsales\Eshop\Application\Controller\Admin\LoginController::class, array("addTplParam"));
$oView->expects($this->at(0))->method('addTplParam')->with($this->equalTo("user"), $this->equalTo('&#039;&quot;&lt;^%&amp;*aaa&gt;'));
$oView->expects($this->at(1))->method('addTplParam')->with($this->equalTo("pwd"), $this->equalTo('&lt;^%&amp;*aaa&gt;&#039;&quot;'));
$oView->expects($this->at(2))->method('addTplParam')->with($this->equalTo("profile"), $this->equalTo('&lt;^%&amp;*aaa&gt;&#039;&quot;'));
$this->assertNull($oView->checklogin());
return [
[new \OxidEsales\Eshop\Core\Exception\UserException('Message1')],
[new \OxidEsales\Eshop\Core\Exception\CookieException('Message2')]
];
}

/**
Expand Down

0 comments on commit 2ce41dc

Please sign in to comment.