Security hardening

This commit is contained in:
jf-cbd
2024-04-23 11:55:39 +02:00
parent 16ff6341d0
commit eeec57536b
4 changed files with 82 additions and 5 deletions

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Combodo\iTop\Test\UnitTest\Module\LaunchTest;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use TokenValidation;
class TokenValidationTest extends ItopDataTestCase
{
/**
* @param string $sSetupToken
*
* @return string
*/
public function createSetupTokenFile(string $sSetupToken): string
{
$sSetupTokenFile = APPROOT.'data/.setup';
file_put_contents($sSetupTokenFile, $sSetupToken);
return $sSetupTokenFile;
}protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('datamodels/2.x/itop-hub-connector/TokenValidation.php');
}
public function testLaunch()
{
$oTokenValidation = new TokenValidation();
$sSetupToken = bin2hex(random_bytes(12));
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->assertFalse($oTokenValidation->isSetupTokenValid($sSetupToken));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->createSetupTokenFile($sSetupToken);
$this->assertTrue($oTokenValidation->isSetupTokenValid($sSetupToken));
}
}