1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Validates the behavior of the AuthenticationLogger event listener. |
4
|
|
|
*/ |
5
|
|
|
namespace Graviton\SecurityBundle\Tests\Listener; |
6
|
|
|
|
7
|
|
|
use Graviton\SecurityBundle\Service\SecurityUtils; |
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
12
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
13
|
|
|
* @link http://swisscom.ch |
14
|
|
|
*/ |
15
|
|
|
class SecurityUtilsTest extends RestTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var SecurityUtils |
19
|
|
|
*/ |
20
|
|
|
private $securityUtils; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Start up the test |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->securityUtils = $this->getContainer()->get('graviton.security.service.utils'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Test correct generation of UUID |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function testGenerateUuid() |
39
|
|
|
{ |
40
|
|
|
$method = $this->getPrivateClassMethod(get_class($this->securityUtils), 'generateUuid'); |
41
|
|
|
$resultA = $method->invokeArgs($this->securityUtils, []); |
42
|
|
|
$this->assertRegExp('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', $resultA); |
43
|
|
|
|
44
|
|
|
$resultB = $method->invokeArgs($this->securityUtils, []); |
45
|
|
|
$this->assertRegExp('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', $resultB); |
46
|
|
|
|
47
|
|
|
$resultC = $method->invokeArgs($this->securityUtils, []); |
48
|
|
|
$this->assertRegExp('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', $resultC); |
49
|
|
|
|
50
|
|
|
$this->assertNotEquals($resultA, $resultB); |
51
|
|
|
$this->assertNotEquals($resultA, $resultC); |
52
|
|
|
$this->assertNotEquals($resultB, $resultC); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Test that UUID is the same on each request |
57
|
|
|
* We do not make a real request, just the function |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function testGetRequestId() |
62
|
|
|
{ |
63
|
|
|
$resultA = $this->securityUtils->getRequestId(); |
64
|
|
|
$resultB = $this->securityUtils->getRequestId(); |
65
|
|
|
|
66
|
|
|
$this->assertRegExp('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', $resultA); |
67
|
|
|
$this->assertEquals($resultA, $resultB); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|