106 lines
2.4 KiB
PHP
106 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Csrf;
|
|
|
|
/**
|
|
* Test the Csrf.php file
|
|
*/
|
|
class CsrfTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCsrf1()
|
|
{
|
|
$csrf = new Csrf();
|
|
$res = $csrf->createToken();
|
|
$GLOBALS["CSRFTEST-Token"] = $res;
|
|
$this->assertSame(30, strlen($res));
|
|
}
|
|
|
|
public function testCsrf2()
|
|
{
|
|
$csrf = new Csrf();
|
|
$res = $csrf->createToken();
|
|
$this->assertSame(
|
|
strspn(
|
|
$res,
|
|
"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
),
|
|
strlen($res)
|
|
);
|
|
}
|
|
|
|
public function testCsrf3()
|
|
{
|
|
$csrf = new Csrf();
|
|
$this->setExpectedException("Exception");
|
|
$res = $csrf->checkToken("NOT VALID TOKEN");
|
|
}
|
|
|
|
public function testCsrf4()
|
|
{
|
|
$csrf = new Csrf();
|
|
$token = $csrf->createToken();
|
|
$res = $csrf->checkToken($token);
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testCsrf5()
|
|
{
|
|
$csrf = new Csrf();
|
|
$token = $csrf->createToken();
|
|
$res = $csrf->extendToken($token);
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testCsrf6()
|
|
{
|
|
$csrf = new Csrf();
|
|
$token = $csrf->createToken();
|
|
$res = $csrf->getToken();
|
|
$this->assertSame($token, $res);
|
|
}
|
|
|
|
public function testCsrf7()
|
|
{
|
|
$csrf = new Csrf();
|
|
$res = $csrf->getToken();
|
|
$this->assertSame(30, strlen($res));
|
|
}
|
|
|
|
public function testCsrfMultiple1()
|
|
{
|
|
$csrf1 = new Csrf();
|
|
$token1 = $csrf1->createToken();
|
|
$csrf2 = new Csrf();
|
|
$token2 = $csrf2->createToken();
|
|
$this->assertSame(
|
|
true,
|
|
$csrf2->checkToken($token1) && $csrf2->checkToken($token2)
|
|
);
|
|
}
|
|
|
|
public function testCsrfMultipleExtend2()
|
|
{
|
|
$csrf = new Csrf();
|
|
$res = $csrf->extendToken($GLOBALS["CSRFTEST-Token"]);
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testCsrfMultipleGet()
|
|
{
|
|
$csrf1 = new Csrf();
|
|
$token1 = $csrf1->createToken();
|
|
$csrf2 = new Csrf();
|
|
$token2 = $csrf2->getToken();
|
|
$this->assertSame($token1, $token2);
|
|
}
|
|
}
|