From 29ec66179b9cba416d0ac7ac6b0e15f200671d29 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Thu, 15 Aug 2024 15:19:59 -0400 Subject: [PATCH 1/5] Removed unused exceptions Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- src/Exception/UnauthorizedException.php | 38 ------------------- .../UnauthorizedExceptionInterface.php | 32 ---------------- 2 files changed, 70 deletions(-) delete mode 100644 src/Exception/UnauthorizedException.php delete mode 100644 src/Exception/UnauthorizedExceptionInterface.php diff --git a/src/Exception/UnauthorizedException.php b/src/Exception/UnauthorizedException.php deleted file mode 100644 index 69ce3fd..0000000 --- a/src/Exception/UnauthorizedException.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @licence MIT - */ -class UnauthorizedException extends BaseRuntimeException implements UnauthorizedExceptionInterface -{ - /** - * @var string - */ - protected $message = 'You are not authorized to access this resource'; -} diff --git a/src/Exception/UnauthorizedExceptionInterface.php b/src/Exception/UnauthorizedExceptionInterface.php deleted file mode 100644 index ee0077c..0000000 --- a/src/Exception/UnauthorizedExceptionInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @licence MIT - */ -interface UnauthorizedExceptionInterface extends ExceptionInterface -{ -} From a2ff629e19298326b338ec53fa18c78f7a8cf4f6 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Fri, 16 Aug 2024 09:32:46 -0400 Subject: [PATCH 2/5] Removed redundant suffix Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7633616..5d45b11 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ - ./src + ./src From 8870dccecaa43e97e2891fdff4430f12e45acb35 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Fri, 16 Aug 2024 09:33:06 -0400 Subject: [PATCH 3/5] Fixed namespace issues Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- test/ConfigProviderTest.php | 2 +- test/ModuleTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index bc56e82..5583314 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -19,7 +19,7 @@ declare(strict_types=1); -namespace LmcRbacTest; +namespace LmcTest; use Lmc\Rbac\ConfigProvider; use PHPUnit\Framework\Attributes\CoversClass; diff --git a/test/ModuleTest.php b/test/ModuleTest.php index 4df59bc..d887b57 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -19,7 +19,7 @@ declare(strict_types=1); -namespace LmcRbacTest; +namespace LmcTest; use Lmc\Rbac\ConfigProvider; use Lmc\Rbac\Module; From 43d1c387507f71e5e68e06d41125ef8168cb4a80 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Fri, 16 Aug 2024 09:33:28 -0400 Subject: [PATCH 4/5] Extra testing for invalid RoleProviders Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- src/Service/RoleServiceFactory.php | 7 ++++++- test/Service/RoleServiceFactoryTest.php | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Service/RoleServiceFactory.php b/src/Service/RoleServiceFactory.php index cfaae74..7e86215 100644 --- a/src/Service/RoleServiceFactory.php +++ b/src/Service/RoleServiceFactory.php @@ -23,6 +23,7 @@ use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Lmc\Rbac\Options\ModuleOptions; +use Lmc\Rbac\Role\RoleProviderInterface; use Psr\Container\ContainerInterface; /** @@ -44,9 +45,13 @@ public function __invoke(ContainerInterface $container): RoleService } $roleProviderName = key($roleProvider); + $roleProvider = $container->get($roleProviderName); + if (! $roleProvider instanceof RoleProviderInterface) { + throw new ServiceNotCreatedException(sprintf('Class %s does not implement LmcRbac\Role\RoleProviderInterface', $roleProviderName)); + } return new RoleService( - $container->get($roleProviderName), + $roleProvider, $moduleOptions->getGuestRole() ); } diff --git a/test/Service/RoleServiceFactoryTest.php b/test/Service/RoleServiceFactoryTest.php index 309576f..2bf23ac 100644 --- a/test/Service/RoleServiceFactoryTest.php +++ b/test/Service/RoleServiceFactoryTest.php @@ -72,4 +72,26 @@ public function testThrowExceptionIfNoRoleProvider(): void $factory = new RoleServiceFactory(); $factory($container); } + + public function testThrowExceptionIfInvalidRoleProvider(): void + { + $this->expectException(\Laminas\ServiceManager\Exception\ServiceNotCreatedException::class); + + $options = new ModuleOptions([ + 'guest_role' => 'guest', + 'role_provider' => [ + 'InvalidRoleProvider' => [], + ], + ]); + + $container = new ServiceManager(['services' => [ + ModuleOptions::class => $options, + 'InvalidRoleProvider' => function () { + return new \stdClass(); + } + ]]); + + $factory = new RoleServiceFactory(); + $factory($container); + } } From e32a75a41fe3987e00cce371c9771c65d21ee315 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Fri, 16 Aug 2024 09:34:32 -0400 Subject: [PATCH 5/5] Removed redundant values Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- phpunit.xml.dist | 4 ---- 1 file changed, 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5d45b11..f14c842 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,12 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" - stopOnFailure="false" - processIsolation="false" - backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" - displayDetailsOnTestsThatTriggerDeprecations="false" > ./test