Create fake session to write csp nonces to it

`Csp::createnonces()` writes to a window aware session and hence a fake base session
is created in `BaseTestCase::setUp()` method
This commit is contained in:
raviks789 2023-08-17 15:25:41 +02:00
parent 282b4d564a
commit 33b6c01fe2
3 changed files with 35 additions and 0 deletions

View File

@ -75,6 +75,7 @@ class Test extends Cli
// Conflicts with `Tests\Icinga\Module\...\Lib`. But it seems it's not needed anyway... // Conflicts with `Tests\Icinga\Module\...\Lib`. But it seems it's not needed anyway...
//$this->getLoader()->registerNamespace('Tests', $this->getBaseDir('test/php/library')); //$this->getLoader()->registerNamespace('Tests', $this->getBaseDir('test/php/library'));
$this->getLoader()->registerNamespace('Tests\\Icinga\\Lib', $this->getBaseDir('test/php/Lib'));
return $this; return $this;
} }

View File

@ -4,8 +4,10 @@
namespace Icinga\Test { namespace Icinga\Test {
use Exception; use Exception;
use Icinga\Util\Csp;
use Icinga\Web\Request; use Icinga\Web\Request;
use Icinga\Web\Response; use Icinga\Web\Response;
use Icinga\Web\Session;
use ipl\I18n\NoopTranslator; use ipl\I18n\NoopTranslator;
use ipl\I18n\StaticTranslator; use ipl\I18n\StaticTranslator;
use RuntimeException; use RuntimeException;
@ -14,6 +16,7 @@ namespace Icinga\Test {
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory; use Icinga\Data\ResourceFactory;
use Icinga\Data\Db\DbConnection; use Icinga\Data\Db\DbConnection;
use Tests\Icinga\Lib\FakeSession;
/** /**
* Class BaseTestCase * Class BaseTestCase
@ -108,6 +111,8 @@ namespace Icinga\Test {
parent::setUp(); parent::setUp();
$this->setupRequestMock(); $this->setupRequestMock();
$this->setupResponseMock(); $this->setupResponseMock();
Session::create(new FakeSession());
Csp::createNonce();
StaticTranslator::$instance = new NoopTranslator(); StaticTranslator::$instance = new NoopTranslator();
} }

View File

@ -0,0 +1,29 @@
<?php
namespace Tests\Icinga\Lib;
use Icinga\Web\Session\Session;
class FakeSession extends Session
{
public function read()
{
}
public function exists()
{
}
public function purge()
{
}
public function refreshId()
{
}
public function getId()
{
return '1234567890';
}
}