|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Handling authentication for clients in the same network. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\SecurityBundle\Authentication\Strategies; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\WebTestCase; |
|
9
|
|
|
use Symfony\Component\BrowserKit\Cookie; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class MultiStrategyTest |
|
13
|
|
|
* |
|
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
16
|
|
|
* @link http://swisscom.ch |
|
17
|
|
|
*/ |
|
18
|
|
|
class MultiStrategyTest extends WebTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
protected $strategy; |
|
21
|
|
|
protected $client; |
|
22
|
|
|
protected $propertyKey; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* UnitTest Starts this on reach test |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
|
|
32
|
|
|
/** @var \Symfony\Bundle\FrameworkBundle\Client client */ |
|
33
|
|
|
$this->client = static::createClient(); |
|
34
|
|
|
$propertyKey = $this->client->getKernel() |
|
35
|
|
|
->getContainer() |
|
36
|
|
|
->getParameter('graviton.security.authentication.strategy.subnet.key'); |
|
37
|
|
|
$SameSubnetStrategy = new SameSubnetStrategy( |
|
|
|
|
|
|
38
|
|
|
$propertyKey |
|
39
|
|
|
); |
|
40
|
|
|
$this->propertyKey = $this->client->getKernel() |
|
41
|
|
|
->getContainer() |
|
42
|
|
|
->getParameter('graviton.security.authentication.strategy.cookie.key'); |
|
43
|
|
|
$CookieFieldStrategy = new CookieFieldStrategy( |
|
|
|
|
|
|
44
|
|
|
$this->propertyKey |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->strategy = new MultiStrategy([ |
|
48
|
|
|
$SameSubnetStrategy, |
|
|
|
|
|
|
49
|
|
|
$CookieFieldStrategy, |
|
|
|
|
|
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @covers \Graviton\SecurityBundle\Authentication\Strategies\MultiStrategy::apply |
|
55
|
|
|
* @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::extractFieldInfo |
|
56
|
|
|
* @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::validateField |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
View Code Duplication |
public function testApply() |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
$fieldValue = 'exampleAuthenticationHeader'; |
|
63
|
|
|
|
|
64
|
|
|
$cookie = new Cookie( |
|
65
|
|
|
$this->propertyKey, |
|
66
|
|
|
$fieldValue, |
|
67
|
|
|
time() + 3600 * 24 * 7, |
|
68
|
|
|
'/', |
|
69
|
|
|
null, |
|
70
|
|
|
false, |
|
71
|
|
|
false |
|
72
|
|
|
); |
|
73
|
|
|
$this->client->getCookieJar()->set($cookie); |
|
74
|
|
|
$this->client->request( |
|
75
|
|
|
'GET', //method |
|
76
|
|
|
'/', //uri |
|
77
|
|
|
array(), //parameters |
|
78
|
|
|
array(), //files |
|
79
|
|
|
array() //server |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertSame($fieldValue, $this->strategy->apply($this->client->getRequest())); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
} |
|
|
|
|
|
|
85
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.