fix: keep the log processors working on a stateless firewall
This commit is contained in:
1 parent
30ad5e8488
commit
f073a2014d
4 files changed
+163
-10
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Logging;
|
||||
|
||||
use App\Logging\UserDataProcessor;
|
||||
use Monolog\Level;
|
||||
use Monolog\LogRecord;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\User\InMemoryUser;
|
||||
|
||||
/**
|
||||
* Same hazard as InjectUserProcessorTest: this one feeds the log table through
|
||||
* App\Logging\DatabaseHandler, and it is registered globally with #[AsMonologProcessor], so a
|
||||
* request on the stateless "api" firewall reaches it with an in-memory user that has no getId().
|
||||
*/
|
||||
class UserDataProcessorTest extends TestCase
|
||||
{
|
||||
public function testAnApiFirewallUserGetsNoIdInsteadOfAnError(): void
|
||||
{
|
||||
$security = $this->createMock(Security::class);
|
||||
$security->method('getUser')->willReturn(new InMemoryUser('api', null, ['ROLE_API']));
|
||||
$security->method('getToken')->willReturn(null);
|
||||
|
||||
$processor = new UserDataProcessor($security, 'fpm-fcgi');
|
||||
|
||||
$record = $processor(new LogRecord(
|
||||
new \DateTimeImmutable(),
|
||||
'api',
|
||||
Level::Info,
|
||||
'Application form submission received'
|
||||
));
|
||||
|
||||
$this->assertSame(
|
||||
['id' => null, 'username' => 'api', 'roles' => ['ROLE_API']],
|
||||
$record->extra['user']
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user