1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Acceptance; |
4
|
|
|
|
5
|
|
|
use App\DataFixtures\UserReferenceTrait; |
6
|
|
|
use App\DataFixtures\Users; |
7
|
|
|
use App\Entity\User; |
8
|
|
|
|
9
|
|
|
class AccessRightsTest extends BaseAcceptanceTest |
10
|
|
|
{ |
11
|
|
|
use UserReferenceTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
protected function getFixtureClasses() |
17
|
|
|
{ |
18
|
|
|
return [Users::class]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testAnonymousRights() |
22
|
|
|
{ |
23
|
|
|
$user = $this->getReference(Users::COMMITTER); |
24
|
|
|
|
25
|
|
|
$this->assertAccessRights('/login/', 200); |
26
|
|
|
$this->assertAccessRights('/loggedout', 200); |
27
|
|
|
$this->assertAccessRights('/user/profile/'); |
28
|
|
|
$this->assertAccessRights('/user/profile/edit'); |
29
|
|
|
|
30
|
|
|
$this->assertAccessRights('/history'); |
31
|
|
|
|
32
|
|
|
$this->assertAccessRights('/browse/'); |
33
|
|
|
$this->assertAccessRights('/browse/?action=list'); |
34
|
|
|
$this->assertAccessRights('/browse/?action=file.upload'); |
35
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=txt'); |
36
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=md'); |
37
|
|
|
$this->assertAccessRights('/browse/?action=subdirectory.create'); |
38
|
|
|
$this->assertAccessRights('/browse/examples/?action=remove'); |
39
|
|
|
|
40
|
|
|
$this->assertAccessRights('/browse/index.md'); |
41
|
|
|
$this->assertAccessRights('/browse/index.md?action=history'); |
42
|
|
|
$this->assertAccessRights('/browse/index.md?action=edit'); |
43
|
|
|
$this->assertAccessRights('/browse/index.md?action=move'); |
44
|
|
|
$this->assertAccessRights('/browse/index.md?action=remove'); |
45
|
|
|
|
46
|
|
|
$this->assertAccessRights('/users/'); |
47
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/edit'); |
48
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/delete'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testWatcherRights() |
52
|
|
|
{ |
53
|
|
|
$user = $this->getReference(Users::COMMITTER); |
54
|
|
|
|
55
|
|
|
$this->assertAccessRights('/user/profile/', 200, $this->getUser(Users::WATCHER)); |
56
|
|
|
$this->assertAccessRights('/user/profile/edit', 200, $this->getUser(Users::WATCHER)); |
57
|
|
|
|
58
|
|
|
$this->assertAccessRights('/history', 200, $this->getUser(Users::WATCHER)); |
59
|
|
|
|
60
|
|
|
$this->assertAccessRights('/browse/', 302, $this->getUser(Users::WATCHER)); |
61
|
|
|
$this->assertAccessRights('/browse/?action=list', 200, $this->getUser(Users::WATCHER)); |
62
|
|
|
$this->assertAccessRights('/browse/?action=file.upload', null, $this->getUser(Users::WATCHER)); |
63
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=txt', null, $this->getUser(Users::WATCHER)); |
64
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=md', null, $this->getUser(Users::WATCHER)); |
65
|
|
|
$this->assertAccessRights('/browse/?action=subdirectory.create', null, $this->getUser(Users::WATCHER)); |
66
|
|
|
$this->assertAccessRights('/browse/examples/?action=remove', null, $this->getUser(Users::WATCHER)); |
67
|
|
|
|
68
|
|
|
$this->assertAccessRights('/browse/index.md', 200, $this->getUser(Users::WATCHER)); |
69
|
|
|
$this->assertAccessRights('/browse/index.md?action=history', 200, $this->getUser(Users::WATCHER)); |
70
|
|
|
$this->assertAccessRights('/browse/index.md?action=edit', null, $this->getUser(Users::WATCHER)); |
71
|
|
|
$this->assertAccessRights('/browse/index.md?action=move', null, $this->getUser(Users::WATCHER)); |
72
|
|
|
$this->assertAccessRights('/browse/index.md?action=remove', null, $this->getUser(Users::WATCHER)); |
73
|
|
|
|
74
|
|
|
$this->assertAccessRights('/users/', null, $this->getUser(Users::WATCHER)); |
75
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/edit', null, $this->getUser(Users::WATCHER)); |
76
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/delete', null, $this->getUser(Users::WATCHER)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testCommitterRights() |
80
|
|
|
{ |
81
|
|
|
$user = $this->getReference(Users::COMMITTER); |
82
|
|
|
|
83
|
|
|
$this->assertAccessRights('/history', 200, $this->getUser(Users::COMMITTER)); |
84
|
|
|
|
85
|
|
|
$this->assertAccessRights('/browse/', 302, $this->getUser(Users::COMMITTER)); |
86
|
|
|
$this->assertAccessRights('/browse/?action=list', 200, $this->getUser(Users::COMMITTER)); |
87
|
|
|
$this->assertAccessRights('/browse/?action=file.upload', 200, $this->getUser(Users::COMMITTER)); |
88
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=txt', 200, $this->getUser(Users::COMMITTER)); |
89
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=md', 200, $this->getUser(Users::COMMITTER)); |
90
|
|
|
$this->assertAccessRights('/browse/?action=subdirectory.create', 200, $this->getUser(Users::COMMITTER)); |
91
|
|
|
$this->assertAccessRights('/browse/examples/?action=remove', 200, $this->getUser(Users::COMMITTER)); |
92
|
|
|
|
93
|
|
|
$this->assertAccessRights('/browse/index.md', 200, $this->getUser(Users::COMMITTER)); |
94
|
|
|
$this->assertAccessRights('/browse/index.md?action=history', 200, $this->getUser(Users::COMMITTER)); |
95
|
|
|
$this->assertAccessRights('/browse/index.md?action=edit', 200, $this->getUser(Users::COMMITTER)); |
96
|
|
|
$this->assertAccessRights('/browse/index.md?action=move', 200, $this->getUser(Users::COMMITTER)); |
97
|
|
|
$this->assertAccessRights('/browse/index.md?action=remove', 302, $this->getUser(Users::COMMITTER)); |
98
|
|
|
|
99
|
|
|
$this->assertAccessRights('/users/', null, $this->getUser(Users::COMMITTER)); |
100
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/edit', null, $this->getUser(Users::COMMITTER)); |
101
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/delete', null, $this->getUser(Users::COMMITTER)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testAdminRights() |
105
|
|
|
{ |
106
|
|
|
$user = $this->getReference(Users::COMMITTER); |
107
|
|
|
|
108
|
|
|
$this->assertAccessRights('/history', 200, $this->getUser(Users::ADMIN)); |
109
|
|
|
|
110
|
|
|
$this->assertAccessRights('/browse/', 302, $this->getUser(Users::ADMIN)); |
111
|
|
|
$this->assertAccessRights('/browse/?action=list', 200, $this->getUser(Users::ADMIN)); |
112
|
|
|
$this->assertAccessRights('/browse/?action=file.upload', 200, $this->getUser(Users::ADMIN)); |
113
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=txt', 200, $this->getUser(Users::ADMIN)); |
114
|
|
|
$this->assertAccessRights('/browse/?action=file.create&extension=md', 200, $this->getUser(Users::ADMIN)); |
115
|
|
|
$this->assertAccessRights('/browse/?action=subdirectory.create', 200, $this->getUser(Users::ADMIN)); |
116
|
|
|
$this->assertAccessRights('/browse/examples/?action=remove', 200, $this->getUser(Users::ADMIN)); |
117
|
|
|
|
118
|
|
|
$this->assertAccessRights('/browse/index.md', 200, $this->getUser(Users::ADMIN)); |
119
|
|
|
$this->assertAccessRights('/browse/index.md?action=history', 200, $this->getUser(Users::ADMIN)); |
120
|
|
|
$this->assertAccessRights('/browse/index.md?action=edit', 200, $this->getUser(Users::ADMIN)); |
121
|
|
|
$this->assertAccessRights('/browse/index.md?action=move', 200, $this->getUser(Users::ADMIN)); |
122
|
|
|
$this->assertAccessRights('/browse/index.md?action=remove', 302, $this->getUser(Users::ADMIN)); |
123
|
|
|
|
124
|
|
|
$this->assertAccessRights('/users/', 200, $this->getUser(Users::ADMIN)); |
125
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/edit', 200, $this->getUser(Users::ADMIN)); |
126
|
|
|
$this->assertAccessRights('/users/' . $user->getId() . '/delete', 302, $this->getUser(Users::ADMIN)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $url The url to test. |
131
|
|
|
* @param null $expectedStatus The expected status code. Null if login is expected. |
132
|
|
|
* @param User $user The user to test or null for anonymous. |
133
|
|
|
*/ |
134
|
|
|
protected function assertAccessRights($url, $expectedStatus = null, User $user = null) |
135
|
|
|
{ |
136
|
|
|
$this->logOut(); |
137
|
|
|
if (null !== $user) { |
138
|
|
|
$this->logIn($user); |
139
|
|
|
} |
140
|
|
|
$this->client->request('GET', $url); |
141
|
|
|
$response = $this->client->getResponse(); |
142
|
|
|
$statusCode = $response->getStatusCode(); |
143
|
|
|
|
144
|
|
|
if (500 === $statusCode) { |
145
|
|
|
echo $this->client->getResponse()->getContent(); |
146
|
|
|
$this->fail(sprintf('Status code was 500 for %s', $url)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if (null === $expectedStatus) { |
150
|
|
|
$this->assertEquals(302, $statusCode, sprintf('%s: Login expected', $url)); |
151
|
|
|
$this->assertEquals('http://localhost/login/', $response->headers->get('Location')); |
152
|
|
|
|
153
|
|
|
return; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
$this->assertEquals( |
157
|
|
|
$expectedStatus, |
158
|
|
|
$statusCode, |
159
|
|
|
sprintf('%s [%s]', $url, $user !== null ? $user->getUsername() : null) |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|