forked from XCMer/csrfprotect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSRF_ProtectTest.php
53 lines (42 loc) · 1.08 KB
/
CSRF_ProtectTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
ob_start();
require_once 'CSRF_Protect.php';
class CSRF_ProtectTest extends PHPUnit_Framework_Testcase
{
public function setUp() {}
public function tearDown() {}
public function testTokenValue()
{
$csrf1 = new CSRF_Protect();
$this->assertTrue($csrf1->getToken() !== '');
}
public function testTokenEquality()
{
$csrf1 = new CSRF_Protect();
$csrf2 = new CSRF_Protect();
$this->assertTrue($csrf1->getToken() === $csrf2->getToken());
}
public function testVerifyTrue()
{
$csrf1 = new CSRF_Protect();
$token = $csrf1->getToken();
$this->assertTrue($csrf1->isTokenValid($token));
}
public function testVerifyFalse()
{
$csrf1 = new CSRF_Protect();
$token = $csrf1->getToken();
$this->assertFalse($csrf1->isTokenValid('abcd'));
$this->assertFalse($csrf1->isTokenValid($token . ' '));
}
public function testTokenUniqueness()
{
$csrf1 = new CSRF_Protect();
$token1 = $csrf1->getToken();
session_destroy();
session_start();
$csrf2 = new CSRF_Protect();
$csrf2 = $csrf2->getToken();
$this->assertTrue($csrf1 !== $csrf2);
}
}