Skip to content
Permalink
Browse files Browse the repository at this point in the history
SW-26913 - improve backend
  • Loading branch information
PascalThesing committed Sep 8, 2022
1 parent cc87efc commit de92d3a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
30 changes: 0 additions & 30 deletions .phpstan-baseline.neon
Expand Up @@ -39225,11 +39225,6 @@ parameters:
count: 1
path: engine/Shopware/Models/Widget/Widget.php

-
message: "#^Call to an undefined method Enlight_Event_EventArgs\\:\\:getSubject\\(\\)\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Call to an undefined method Enlight_Template_Default\\:\\:setCompileId\\(\\)\\.$#"
count: 1
Expand All @@ -39245,36 +39240,11 @@ parameters:
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:initLocale\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:isAllowed\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:onPreDispatchBackend\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:registerAclPlugin\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:setNoAcl\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_Auth_Bootstrap\\:\\:setNoAuth\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php

-
message: "#^Method Shopware_Plugins_Backend_SwagUpdate_Bootstrap\\:\\:afterInit\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
14 changes: 13 additions & 1 deletion engine/Shopware/Plugins/Default/Backend/Auth/Bootstrap.php
Expand Up @@ -149,6 +149,8 @@ public function isAllowed($params)
* Set local no auth property
*
* @param bool $flag
*
* @return void
*/
public function setNoAuth($flag = true)
{
Expand All @@ -159,6 +161,8 @@ public function setNoAuth($flag = true)
* Set local no acl property
*
* @param bool $flag
*
* @return void
*/
public function setNoAcl($flag = true)
{
Expand Down Expand Up @@ -188,13 +192,17 @@ public function shouldUseAcl()
/**
* This pre-dispatch event-hook checks backend permissions
*
* @param Enlight_Controller_ActionEventArgs $args
*
* @throws Enlight_Controller_Exception
*
* @return void
*/
public function onPreDispatchBackend(Enlight_Event_EventArgs $args)
{
$this->action = $args->getSubject();
$this->request = $this->action->Request();
$this->aclResource = strtolower($this->request->getControllerName());
$this->aclResource = strtolower(str_replace('_', '', $this->request->getControllerName()));

if ($this->aclResource === 'error' || $this->request->getModuleName() !== 'backend') {
return;
Expand Down Expand Up @@ -264,6 +272,8 @@ public function checkAuth()
*
* @throws Exception
* @throws SmartyException
*
* @return void
*/
public function registerAclPlugin($auth)
{
Expand Down Expand Up @@ -436,6 +446,8 @@ public function getCapabilities()
* Init backend locales
*
* @throws Exception
*
* @return void
*/
protected function initLocale()
{
Expand Down
54 changes: 54 additions & 0 deletions tests/Unit/Plugin/Backend/Auth/BootstrapTest.php
@@ -0,0 +1,54 @@
<?php
/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/

namespace Shopware\Tests\Unit\Plugins\Backend\Auth;

use Enlight_Controller_Action;
use Enlight_Controller_ActionEventArgs;
use Enlight_Controller_Request_RequestTestCase;
use PHPUnit\Framework\TestCase;
use Shopware\Tests\Functional\Helper\Utils;
use Shopware_Plugins_Backend_Auth_Bootstrap;

class BootstrapTest extends TestCase
{
public function testValidatesAlsoSnakeCaseControllers(): void
{
/** @var Shopware_Plugins_Backend_Auth_Bootstrap $authPlugin */
$authPlugin = $this->createPartialMock(Shopware_Plugins_Backend_Auth_Bootstrap::class, ['initLocale', 'checkAuth']);
$authPlugin->setNoAcl(true);

$action = $this->getMockBuilder(Enlight_Controller_Action::class)->disableOriginalConstructor()->getMock();
$testRequest = new Enlight_Controller_Request_RequestTestCase();
$testRequest->setControllerName('user_manager');
$testRequest->setModuleName('Backend');
$action->method('Request')->willReturn($testRequest);
$eventArgs = new Enlight_Controller_ActionEventArgs();
$eventArgs->set('subject', $action);

$authPlugin->onPreDispatchBackend($eventArgs);

static::assertEquals('usermanager', Utils::hijackAndReadProperty($authPlugin, 'aclResource'));
}
}

0 comments on commit de92d3a

Please sign in to comment.