mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 05:00:08 +02:00
Add log entries on user login or logout.
This commit is contained in:
parent
d6c6b973bf
commit
c8375bfa8b
9 changed files with 323 additions and 5 deletions
69
tests/Services/LogSystem/EventLoggerTest.php
Normal file
69
tests/Services/LogSystem/EventLoggerTest.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\LogSystem;
|
||||
|
||||
use App\Entity\LogSystem\AbstractLogEntry;
|
||||
use App\Entity\LogSystem\UserLoginLogEntry;
|
||||
use App\Entity\LogSystem\UserLogoutLogEntry;
|
||||
use App\Services\LogSystem\EventLogger;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class EventLoggerTest extends WebTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EventLogger
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(EventLogger::class);
|
||||
}
|
||||
|
||||
public function testShouldBeAdded()
|
||||
{
|
||||
$event1 = new UserLoginLogEntry('127.0.0.1');
|
||||
$event2 = new UserLogoutLogEntry('127.0.0.1');
|
||||
$event2->setLevel(AbstractLogEntry::LEVEL_CRITICAL);
|
||||
|
||||
|
||||
//Test without restrictions
|
||||
$this->assertTrue($this->service->shouldBeAdded($event1, 7, [], []));
|
||||
|
||||
//Test minimum log level
|
||||
$this->assertFalse($this->service->shouldBeAdded($event1, 2, [], []));
|
||||
$this->assertTrue($this->service->shouldBeAdded($event2, 2, [], []));
|
||||
|
||||
//Test blacklist
|
||||
$this->assertFalse($this->service->shouldBeAdded($event1, 7, [UserLoginLogEntry::class], []));
|
||||
$this->assertTrue($this->service->shouldBeAdded($event2, 7, [UserLoginLogEntry::class], []));
|
||||
|
||||
//Test whitelist
|
||||
$this->assertFalse($this->service->shouldBeAdded($event1, 7, [], [UserLogoutLogEntry::class]));
|
||||
$this->assertTrue($this->service->shouldBeAdded($event2, 7, [], [UserLogoutLogEntry::class]));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue