|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tests\KI\PublicationBundle; |
|
3
|
|
|
|
|
4
|
|
|
use Tests\KI\CoreBundle\WebTestCase; |
|
5
|
|
|
|
|
6
|
|
|
class SecurityTest extends WebTestCase |
|
7
|
|
|
{ |
|
8
|
|
|
// Vérifie que les routes non firewallées sont utilisables |
|
9
|
|
View Code Duplication |
public function testFirewall() |
|
10
|
|
|
{ |
|
11
|
|
|
$this->client = static::createClient(); |
|
12
|
|
|
$routes = [ |
|
13
|
|
|
[401, 'GET', '/newsitems'], |
|
14
|
|
|
[404, 'GET', '/courses/mecanique-des-structures/exercices/test/download'], |
|
15
|
|
|
[200, 'GET', '/users/VpqtuEGC/calendar'], |
|
16
|
|
|
[401, 'POST', '/newsitems/le-beton-c-est-bon/comments'], |
|
17
|
|
|
]; |
|
18
|
|
|
$this->checkRoutes($routes); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testClubMembership() |
|
22
|
|
|
{ |
|
23
|
|
|
// On se présente comme un trouffion de base |
|
24
|
|
|
$this->connect('donat-bb', 'password'); |
|
25
|
|
|
|
|
26
|
|
|
// Maintenant on teste quelques trucs |
|
27
|
|
|
$this->client->request('POST', '/newsitems/le-beton-c-est-bon/comments'); |
|
28
|
|
|
$response = $this->client->getResponse(); |
|
29
|
|
|
$this->assertJsonResponse($response, 400); |
|
30
|
|
|
|
|
31
|
|
|
$this->client->request('POST', '/newsitems', ['name' => 'La Porte', 'text' => 'C\'est comme perdre']); |
|
32
|
|
|
$response = $this->client->getResponse(); |
|
33
|
|
|
$this->assertJsonResponse($response, 201); |
|
34
|
|
|
|
|
35
|
|
|
$this->client->request('DELETE', '/newsitems/la-porte'); |
|
36
|
|
|
$response = $this->client->getResponse(); |
|
37
|
|
|
$this->assertJsonResponse($response, 204); |
|
38
|
|
|
|
|
39
|
|
|
$this->client->request('POST', '/newsitems', ['name' => 'La Porte', 'text' => 'C\'est comme perdre', 'authorClub' => 'bde']); |
|
40
|
|
|
$response = $this->client->getResponse(); |
|
41
|
|
|
$this->assertJsonResponse($response, 403); |
|
42
|
|
|
|
|
43
|
|
|
$this->client->request('DELETE', '/newsitems/le-jeu'); |
|
44
|
|
|
$response = $this->client->getResponse(); |
|
45
|
|
|
$this->assertJsonResponse($response, 403); |
|
46
|
|
|
|
|
47
|
|
|
$this->client->request('POST', '/newsitems', ['name' => 'Manger', 'text' => 'C\'est comme perdre', 'authorClub' => 'bda']); |
|
48
|
|
|
$response = $this->client->getResponse(); |
|
49
|
|
|
$this->assertJsonResponse($response, 201); |
|
50
|
|
|
|
|
51
|
|
|
$this->client->request('DELETE', '/newsitems/manger'); |
|
52
|
|
|
$response = $this->client->getResponse(); |
|
53
|
|
|
$this->assertJsonResponse($response, 204); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
View Code Duplication |
public function testRoleAdmissible() |
|
57
|
|
|
{ |
|
58
|
|
|
// On se présente comme un admissible |
|
59
|
|
|
$this->connect('admissibles', 'password'); |
|
60
|
|
|
$routes = [ |
|
61
|
|
|
[200, 'GET', '/newsitems'], |
|
62
|
|
|
[200, 'GET', '/courses'], |
|
63
|
|
|
[403, 'POST', '/newsitems'], |
|
64
|
|
|
[403, 'POST', '/events'], |
|
65
|
|
|
[403, 'PATCH', '/events/don-giovanni'], |
|
66
|
|
|
[403, 'PATCH', '/newsitems/pulls'], |
|
67
|
|
|
]; |
|
68
|
|
|
$this->checkRoutes($routes); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
View Code Duplication |
public function testRoleExterieur() |
|
72
|
|
|
{ |
|
73
|
|
|
// On se présente comme un extérieur de l'administration |
|
74
|
|
|
$this->connect('gcc', 'password'); |
|
75
|
|
|
$routes = [ |
|
76
|
|
|
[200, 'GET', '/newsitems'], |
|
77
|
|
|
[403, 'GET', '/courses'], |
|
78
|
|
|
[403, 'POST', '/newsitems/le-beton-c-est-bon/comments'], |
|
79
|
|
|
[200, 'GET', '/newsitems/le-beton-c-est-bon/comments'] |
|
80
|
|
|
]; |
|
81
|
|
|
$this->checkRoutes($routes); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|