Skip to content

Commit

Permalink
CC-17181 Fixed login page redirection issue in Merchant Portal. (#9655)
Browse files Browse the repository at this point in the history
CC-17181 Fixed login page redirection issue in Merchant Portal.
  • Loading branch information
hitesh-kumar-metacube authored Oct 10, 2023
1 parent 747170f commit 8eaf424
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 62 deletions.
56 changes: 0 additions & 56 deletions architecture-baseline.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,4 @@
[
{
"fileName": "src/Spryker/Glue/Router/Resolver/RequestRequestValueResolver.php",
"description": "Method `Spryker\\Glue\\Router\\Resolver\\RequestRequestValueResolver::supports()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Glue/Router/Resolver/RequestRequestValueResolver.php",
"description": "Method `Spryker\\Glue\\Router\\Resolver\\RequestRequestValueResolver::resolve()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Yves/Router/Generator/UrlGenerator.php",
"description": "Method `Spryker\\Yves\\Router\\Generator\\UrlGenerator::generate()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Yves/Router/Resolver/RequestRequestValueResolver.php",
"description": "Method `Spryker\\Yves\\Router\\Resolver\\RequestRequestValueResolver::supports()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Yves/Router/Resolver/RequestRequestValueResolver.php",
"description": "Method `Spryker\\Yves\\Router\\Resolver\\RequestRequestValueResolver::resolve()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Yves/Router/Router/Router.php",
"description": "Method `Spryker\\Yves\\Router\\Router\\Router::getGenerator()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Zed/Router/Business/Generator/UrlGenerator.php",
"description": "Method `Spryker\\Zed\\Router\\Business\\Generator\\UrlGenerator::generate()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Zed/Router/Business/Router/Router.php",
"description": "Method `Spryker\\Zed\\Router\\Business\\Router\\Router::getGenerator()` must have return type.",
"rule": "ExternalMethodExtensionReturnTypeRule",
"ruleset": "Spryker",
"priority": "1"
},
{
"fileName": "src/Spryker/Zed/Router/Business/RouterFacade.php",
"description": "Zed Business Layer - Facade: The method `Spryker\\Zed\\Router\\Business\\RouterFacade::getRouter()()` is using an invalid return type `\\Spryker\\Zed\\Router\\Business\\Router\\ChainRouter` which violates the rule \"Every Facade should only return native types or transfer objects.\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ abstract class AbstractRouterResource implements ResourceInterface
*/
public const CONTROLLER_NAME_POSITION = 5;

/**
* @var string
*/
protected const APPLICATION_MODULE_NAME = 'application';

/**
* @var \Spryker\Zed\Router\RouterConfig
*/
Expand Down Expand Up @@ -208,7 +213,7 @@ protected function getPathCandidates(string $module, string $controller, string
$pathCandidates[] = sprintf('/%s', $module);
}

if ($module === 'application' && $controller === 'index' && $action === 'index') {
if ($module === static::APPLICATION_MODULE_NAME && $controller === 'index' && $action === 'index') {
$pathCandidates[] = '/';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Spryker\Zed\Router\Business\Router\RouterResource;

use SplFileInfo;
use Symfony\Component\Finder\Finder;

class BackofficeRouterResource extends AbstractRouterResource
Expand All @@ -20,7 +21,18 @@ protected function getFinder(): Finder
$finder->files()
->in($this->config->getControllerDirectories())
->name('*Controller.php')
->notName('GatewayController.php');
->notName('GatewayController.php')
->filter(function (SplFileInfo $splFileInfo) {
$pathToController = $splFileInfo->getPathname();
foreach ($this->config->getNotAllowedBackofficeControllerDirectories() as $notAllowedBackofficeControllerDirectory) {
$notAllowedBackofficeControllerDirectoryPath = sprintf('%s%s%s', DIRECTORY_SEPARATOR, $notAllowedBackofficeControllerDirectory, DIRECTORY_SEPARATOR);
if (strpos($pathToController, $notAllowedBackofficeControllerDirectoryPath) !== false) {
return false;
}
}

return true;
});

return $finder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace Spryker\Zed\Router\Business\Router\RouterResource;

use ReflectionMethod;
use SplFileInfo;
use Spryker\Zed\Router\Business\Route\Route;
use Spryker\Zed\Router\Business\Route\RouteCollection;
use Symfony\Component\Finder\Finder;

class MerchantPortalRouterResource extends AbstractRouterResource
Expand All @@ -17,6 +20,21 @@ class MerchantPortalRouterResource extends AbstractRouterResource
*/
protected const MERCHANT_PORTAL_FOLDER_FILTER = 'MerchantPortal';

/**
* @var string
*/
protected const APPLICATION_MODULE_NAME = 'merchant-portal-application';

/**
* @var string
*/
protected const ROUTE_NAME_SECURITY_MERCHANT_PORTAL_GUI_LOGIN = 'security-merchant-portal-gui:login';

/**
* @var string
*/
protected const ROUTE_NAME_SECURITY_GUI_LOGIN = 'security-gui:login';

/**
* @return \Symfony\Component\Finder\Finder
*/
Expand All @@ -33,4 +51,38 @@ protected function getFinder(): Finder

return $finder;
}

/**
* @param \ReflectionMethod $method
* @param \Spryker\Zed\Router\Business\Route\RouteCollection $routeCollection
* @param string $pathCandidate
* @param string $controllerClassName
* @param string $template
*
* @return \Spryker\Zed\Router\Business\Route\RouteCollection
*/
protected function addRouteToCollection(
ReflectionMethod $method,
RouteCollection $routeCollection,
string $pathCandidate,
string $controllerClassName,
string $template
): RouteCollection {
$route = new Route($pathCandidate);

$route->addDefaults([
'_controller' => [$controllerClassName, $method->getName()],
'_template' => $template,
]);

$routeName = str_replace('/', ':', trim($pathCandidate, '/'));

$routeCollection->add($routeName, $route, 0);

if ($routeName === static::ROUTE_NAME_SECURITY_MERCHANT_PORTAL_GUI_LOGIN) {
$routeCollection->add(static::ROUTE_NAME_SECURITY_GUI_LOGIN, $route, 0);
}

return $routeCollection;
}
}
20 changes: 20 additions & 0 deletions src/Spryker/Zed/Router/RouterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
class RouterConfig extends AbstractBundleConfig
{
/**
* @var string
*/
protected const DIRECTORY_NAME_MERCHANT_PORTAL_APPLICATION = 'MerchantPortalApplication';

/**
* Specification:
* - Returns a Router configuration which makes use of a Router cache.
Expand Down Expand Up @@ -288,4 +293,19 @@ public function getSslExcludedRouteNames(): array
{
return $this->get(RouterConstants::ZED_SSL_EXCLUDED_ROUTE_NAMES, []);
}

/**
* Specification:
* - Returns a list of directories that are not allowed for Backoffice controllers.
*
* @api
*
* @return list<string>
*/
public function getNotAllowedBackofficeControllerDirectories(): array
{
return [
static::DIRECTORY_NAME_MERCHANT_PORTAL_APPLICATION,
];
}
}
2 changes: 1 addition & 1 deletion tests/SprykerTest/Shared/Router/_support/RouterTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
* @SuppressWarnings(\SprykerTest\Shared\Router\PHPMD)
*/
class RouterTester extends Actor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
* @SuppressWarnings(\SprykerTest\Yves\Router\PHPMD)
*/
class RouterYvesTester extends Actor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerTest\Zed\Router\Business\Router\RouterResource;

use Codeception\Test\Unit;
use Spryker\Zed\Router\Business\Router\RouterResource\BackofficeRouterResource;
use Spryker\Zed\Router\Business\RouterResource\ResourceInterface;
use Spryker\Zed\Router\RouterConfig;
use SprykerTest\Zed\Router\RouterBusinessTester;
use Symfony\Component\Finder\Finder;

/**
* Auto-generated group annotations
*
* @group SprykerTest
* @group Zed
* @group Router
* @group Business
* @group Router
* @group RouterResource
* @group BackofficeRouterResourceTest
* Add your own group annotations below this line
*/
class BackofficeRouterResourceTest extends Unit
{
/**
* @var \SprykerTest\Zed\Router\RouterBusinessTester
*/
protected RouterBusinessTester $tester;

/**
* @dataProvider getGetFinderDataProvider
*
* @param list<string> $notAllowedBackofficeControllerDirectories
* @param int $expectedCount
*
* @return void
*/
public function testGetFinder(array $notAllowedBackofficeControllerDirectories, int $expectedCount): void
{
// Arrange
$this->tester->mockConfigMethod('getControllerDirectories', [codecept_data_dir('Fixtures/Controller/')]);

/** @var \Spryker\Zed\Router\RouterConfig $routerConfig */
$routerConfig = $this->tester->mockConfigMethod('getNotAllowedBackofficeControllerDirectories', $notAllowedBackofficeControllerDirectories);

// Act
$finder = $this->createBackofficeRouterResource($routerConfig)->getFinder();

// Assert
$this->assertCount($expectedCount, $finder);
}

/**
* @return array<array<list<string>|int>>
*/
protected function getGetFinderDataProvider(): array
{
return [
'Should not filter out files when all directories are allowed.' => [[], 1],
'Should not filter out files when a directory does not exist.' => [['Mock'], 1],
'Should filter out files when a directory does not exist.' => [['Fixtures'], 0],
];
}

/**
* @param \Spryker\Zed\Router\RouterConfig $config
*
* @return \Spryker\Zed\Router\Business\RouterResource\ResourceInterface
*/
protected function createBackofficeRouterResource(RouterConfig $config): ResourceInterface
{
return new class ($config) extends BackofficeRouterResource
{
/**
* @return \Symfony\Component\Finder\Finder
*/
public function getFinder(): Finder
{
return parent::getFinder();
}
};
}
}
Loading

0 comments on commit 8eaf424

Please sign in to comment.