-
Notifications
You must be signed in to change notification settings - Fork 1
IBX-11507: Critical errors logged when browsing BackOffice as user with limited permissions #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sztig
wants to merge
7
commits into
4.6
Choose a base branch
from
IBX-11507-log-pollution-fix
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b5d841
added new listener and log channel to handle ArgumentsException logging
Sztig 5b5b9b3
refactored fix after review
Sztig 6682263
implemented tests for the ArgumentsExceptionListener
Sztig aa41274
fixed test for php7.4
Sztig 6e8df37
added phpunit components to the bundle
Sztig f01ac25
refactored the test into phpunit
Sztig b10e812
implemented suggested changes
Sztig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ composer.lock | |
| vendor | ||
| .php_cs.cache | ||
| .php-cs-fixer.cache | ||
| .phpunit.result.cache | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
| beStrictAboutOutputDuringTests="true" | ||
| beStrictAboutTodoAnnotatedTests="true" | ||
| failOnWarning="true" | ||
| verbose="true"> | ||
| <testsuites> | ||
| <testsuite name="lib"> | ||
| <directory>tests/lib</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| namespace Ibexa\GraphQL\EventListener; | ||
|
|
||
| use Ibexa\GraphQL\DataLoader\Exception\ArgumentsException; | ||
| use Overblog\GraphQLBundle\Event\ErrorFormattingEvent; | ||
| use Overblog\GraphQLBundle\Event\Events; | ||
| use Psr\Log\LoggerInterface; | ||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
|
||
| final class ArgumentsExceptionListener implements EventSubscriberInterface | ||
| { | ||
| private LoggerInterface $logger; | ||
|
|
||
| public function __construct(LoggerInterface $logger) | ||
| { | ||
| $this->logger = $logger; | ||
| } | ||
|
|
||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [ | ||
| Events::ERROR_FORMATTING => ['onErrorFormatting', 10], | ||
| ]; | ||
| } | ||
|
|
||
| public function onErrorFormatting(ErrorFormattingEvent $event): void | ||
| { | ||
| $exception = $event->getError()->getPrevious(); | ||
|
|
||
| if (!$exception instanceof ArgumentsException) { | ||
| return; | ||
| } | ||
|
|
||
| $this->logger->debug( | ||
| sprintf('[GraphQL] %s: %s', ArgumentsException::class, $exception->getMessage()), | ||
| ['exception' => $exception] | ||
| ); | ||
|
|
||
| $event->stopPropagation(); | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
tests/lib/EventListener/ArgumentsExceptionListenerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Tests\GraphQL\EventListener; | ||
|
|
||
| use GraphQL\Error\Error; | ||
| use Ibexa\GraphQL\DataLoader\Exception\ArgumentsException; | ||
| use Ibexa\GraphQL\EventListener\ArgumentsExceptionListener; | ||
| use Overblog\GraphQLBundle\Event\ErrorFormattingEvent; | ||
| use Overblog\GraphQLBundle\Event\Events; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Log\LoggerInterface; | ||
| use RuntimeException; | ||
|
|
||
| final class ArgumentsExceptionListenerTest extends TestCase | ||
| { | ||
| /** @var \Psr\Log\LoggerInterface&\PHPUnit\Framework\MockObject\MockObject */ | ||
| private LoggerInterface $logger; | ||
|
|
||
| private ArgumentsExceptionListener $listener; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->logger = $this->createMock(LoggerInterface::class); | ||
| $this->listener = new ArgumentsExceptionListener($this->logger); | ||
| } | ||
|
|
||
| public function testGetSubscribedEvents(): void | ||
| { | ||
| self::assertSame( | ||
| [Events::ERROR_FORMATTING => ['onErrorFormatting', 10]], | ||
| ArgumentsExceptionListener::getSubscribedEvents(), | ||
| ); | ||
| } | ||
|
|
||
| public function testOnErrorFormattingLogsAndStopsPropagationForArgumentsException(): void | ||
| { | ||
| $exception = new ArgumentsException('invalid arguments'); | ||
| $event = $this->createErrorFormattingEvent($exception); | ||
|
|
||
| $this->logger | ||
| ->expects(self::once()) | ||
| ->method('debug') | ||
| ->with( | ||
| sprintf('[GraphQL] %s: %s', ArgumentsException::class, 'invalid arguments'), | ||
| ['exception' => $exception], | ||
| ); | ||
|
|
||
| $this->listener->onErrorFormatting($event); | ||
|
|
||
| self::assertTrue($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| public function testOnErrorFormattingIgnoresExceptionsThatAreNotArgumentsExceptions(): void | ||
| { | ||
| $exception = new RuntimeException('some other error'); | ||
| $event = $this->createErrorFormattingEvent($exception); | ||
|
|
||
| $this->logger | ||
| ->expects(self::never()) | ||
| ->method('debug'); | ||
|
|
||
| $this->listener->onErrorFormatting($event); | ||
|
|
||
| self::assertFalse($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| private function createErrorFormattingEvent(\Throwable $exception): ErrorFormattingEvent | ||
| { | ||
| return new ErrorFormattingEvent( | ||
| new Error('Internal server error', null, null, [], null, $exception), | ||
| [], | ||
| ); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage.