1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the silex-annotation-provider package. |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @license MIT License |
8
|
|
|
* @copyright (c) 2018, Dana Desrosiers <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace DDesrosiers\Test\SilexAnnotations\Annotations; |
12
|
|
|
|
13
|
|
|
use DDesrosiers\Test\SilexAnnotations\AnnotationTestBase; |
14
|
|
|
use Silex\Provider\SecurityServiceProvider; |
15
|
|
|
|
16
|
|
|
class SecureTest extends AnnotationTestBase |
17
|
|
|
{ |
18
|
|
|
protected $authRequestOptions = array('PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => 'foo'); |
19
|
|
|
|
20
|
|
|
public function setup() |
21
|
|
|
{ |
22
|
|
|
parent::setup(); |
23
|
|
|
|
24
|
|
|
$this->app->register( |
25
|
|
|
new SecurityServiceProvider(), |
26
|
|
|
array( |
27
|
|
|
'security.firewalls' => array( |
28
|
|
|
'admin' => array( |
29
|
|
|
'pattern' => '^/test', |
30
|
|
|
'http' => true, |
31
|
|
|
'users' => array( |
32
|
|
|
// raw password is foo |
33
|
|
|
'admin' => array( |
34
|
|
|
'ROLE_ADMIN', |
35
|
|
|
'$2y$15$lzUNsTegNXvZW3qtfucV0erYBcEqWVeyOmjolB7R1uodsAVJ95vvu' |
36
|
|
|
), |
37
|
|
|
), |
38
|
|
|
), |
39
|
|
|
) |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testAuthorizedUser() |
45
|
|
|
{ |
46
|
|
|
$this->requestOptions = $this->authRequestOptions; |
47
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/test/secure", self::STATUS_OK); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testUnauthorizedUser() |
51
|
|
|
{ |
52
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/test/secure", self::STATUS_UNAUTHORIZED); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testAuthorizedUserCollection() |
56
|
|
|
{ |
57
|
|
|
$this->requestOptions = $this->authRequestOptions; |
58
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/testSecure/test", self::STATUS_OK); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testUnauthorizedUserCollection() |
62
|
|
|
{ |
63
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/testSecure/test", self::STATUS_UNAUTHORIZED); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|