]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9a27cdc2 | 2 | |
9a27cdc2 | 3 | import 'mocha' |
9a27cdc2 | 4 | import { |
c0e8b12e C |
5 | checkBadCountPagination, |
6 | checkBadSortPagination, | |
7 | checkBadStartPagination, | |
7c3b7976 | 8 | cleanupTests, |
254d3579 | 9 | createSingleServer, |
c0e8b12e C |
10 | makeDeleteRequest, |
11 | makeGetRequest, | |
7c3b7976 | 12 | makePostBodyRequest, |
254d3579 | 13 | PeerTubeServer, |
41d1d075 | 14 | setAccessTokensToServers |
c0e8b12e C |
15 | } from '@shared/extra-utils' |
16 | import { HttpStatusCode } from '@shared/models' | |
9a27cdc2 C |
17 | |
18 | describe('Test server follows API validators', function () { | |
254d3579 | 19 | let server: PeerTubeServer |
9a27cdc2 C |
20 | |
21 | // --------------------------------------------------------------- | |
22 | ||
23 | before(async function () { | |
e212f887 | 24 | this.timeout(30000) |
9a27cdc2 | 25 | |
254d3579 | 26 | server = await createSingleServer(1) |
9a27cdc2 C |
27 | |
28 | await setAccessTokensToServers([ server ]) | |
29 | }) | |
30 | ||
31 | describe('When managing following', function () { | |
32 | let userAccessToken = null | |
33 | ||
34 | before(async function () { | |
4d029ef8 | 35 | userAccessToken = await server.users.generateUserAndToken('user1') |
9a27cdc2 C |
36 | }) |
37 | ||
38 | describe('When adding follows', function () { | |
39 | const path = '/api/v1/server/following' | |
9a27cdc2 | 40 | |
4d029ef8 | 41 | it('Should fail with nothing', async function () { |
eec63bbc C |
42 | await makePostBodyRequest({ |
43 | url: server.url, | |
44 | path, | |
45 | token: server.accessToken, | |
c0e8b12e | 46 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
eec63bbc | 47 | }) |
9a27cdc2 C |
48 | }) |
49 | ||
4d029ef8 | 50 | it('Should fail if hosts is not composed by hosts', async function () { |
eec63bbc C |
51 | await makePostBodyRequest({ |
52 | url: server.url, | |
53 | path, | |
4d029ef8 | 54 | fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, |
eec63bbc | 55 | token: server.accessToken, |
c0e8b12e | 56 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
eec63bbc | 57 | }) |
9a27cdc2 C |
58 | }) |
59 | ||
4d029ef8 | 60 | it('Should fail if hosts is composed with http schemes', async function () { |
eec63bbc C |
61 | await makePostBodyRequest({ |
62 | url: server.url, | |
63 | path, | |
4d029ef8 | 64 | fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, |
eec63bbc | 65 | token: server.accessToken, |
c0e8b12e | 66 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
eec63bbc | 67 | }) |
9a27cdc2 C |
68 | }) |
69 | ||
4d029ef8 | 70 | it('Should fail if hosts are not unique', async function () { |
eec63bbc C |
71 | await makePostBodyRequest({ |
72 | url: server.url, | |
73 | path, | |
4d029ef8 | 74 | fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, |
eec63bbc | 75 | token: server.accessToken, |
c0e8b12e | 76 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
eec63bbc | 77 | }) |
9a27cdc2 C |
78 | }) |
79 | ||
4d029ef8 | 80 | it('Should fail if handles is not composed by handles', async function () { |
eec63bbc C |
81 | await makePostBodyRequest({ |
82 | url: server.url, | |
83 | path, | |
4d029ef8 C |
84 | fields: { handles: [ 'hello@example.com', 'localhost:9001' ] }, |
85 | token: server.accessToken, | |
86 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
87 | }) | |
88 | }) | |
89 | ||
90 | it('Should fail if handles are not unique', async function () { | |
91 | await makePostBodyRequest({ | |
92 | url: server.url, | |
93 | path, | |
94 | fields: { urls: [ 'hello@example.com', 'hello@example.com' ] }, | |
eec63bbc | 95 | token: server.accessToken, |
c0e8b12e | 96 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
eec63bbc | 97 | }) |
9a27cdc2 C |
98 | }) |
99 | ||
100 | it('Should fail with an invalid token', async function () { | |
eec63bbc C |
101 | await makePostBodyRequest({ |
102 | url: server.url, | |
103 | path, | |
104 | fields: { hosts: [ 'localhost:9002' ] }, | |
105 | token: 'fake_token', | |
c0e8b12e | 106 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
eec63bbc | 107 | }) |
9a27cdc2 C |
108 | }) |
109 | ||
110 | it('Should fail if the user is not an administrator', async function () { | |
eec63bbc C |
111 | await makePostBodyRequest({ |
112 | url: server.url, | |
113 | path, | |
114 | fields: { hosts: [ 'localhost:9002' ] }, | |
115 | token: userAccessToken, | |
c0e8b12e | 116 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
eec63bbc | 117 | }) |
9a27cdc2 C |
118 | }) |
119 | }) | |
120 | ||
121 | describe('When listing followings', function () { | |
122 | const path = '/api/v1/server/following' | |
123 | ||
124 | it('Should fail with a bad start pagination', async function () { | |
eec63bbc | 125 | await checkBadStartPagination(server.url, path) |
9a27cdc2 C |
126 | }) |
127 | ||
128 | it('Should fail with a bad count pagination', async function () { | |
eec63bbc | 129 | await checkBadCountPagination(server.url, path) |
9a27cdc2 C |
130 | }) |
131 | ||
132 | it('Should fail with an incorrect sort', async function () { | |
eec63bbc | 133 | await checkBadSortPagination(server.url, path) |
9a27cdc2 | 134 | }) |
b8f4167f C |
135 | |
136 | it('Should fail with an incorrect state', async function () { | |
137 | await makeGetRequest({ | |
138 | url: server.url, | |
139 | path, | |
140 | query: { | |
141 | state: 'blabla' | |
142 | } | |
143 | }) | |
144 | }) | |
145 | ||
97ecddae C |
146 | it('Should fail with an incorrect actor type', async function () { |
147 | await makeGetRequest({ | |
148 | url: server.url, | |
149 | path, | |
150 | query: { | |
151 | actorType: 'blabla' | |
152 | } | |
153 | }) | |
154 | }) | |
155 | ||
b8f4167f C |
156 | it('Should fail succeed with the correct params', async function () { |
157 | await makeGetRequest({ | |
158 | url: server.url, | |
159 | path, | |
c0e8b12e | 160 | expectedStatus: HttpStatusCode.OK_200, |
b8f4167f | 161 | query: { |
97ecddae C |
162 | state: 'accepted', |
163 | actorType: 'Application' | |
b8f4167f C |
164 | } |
165 | }) | |
166 | }) | |
9a27cdc2 C |
167 | }) |
168 | ||
169 | describe('When listing followers', function () { | |
170 | const path = '/api/v1/server/followers' | |
171 | ||
172 | it('Should fail with a bad start pagination', async function () { | |
eec63bbc | 173 | await checkBadStartPagination(server.url, path) |
9a27cdc2 C |
174 | }) |
175 | ||
176 | it('Should fail with a bad count pagination', async function () { | |
eec63bbc | 177 | await checkBadCountPagination(server.url, path) |
9a27cdc2 C |
178 | }) |
179 | ||
180 | it('Should fail with an incorrect sort', async function () { | |
eec63bbc | 181 | await checkBadSortPagination(server.url, path) |
9a27cdc2 | 182 | }) |
b8f4167f | 183 | |
97ecddae C |
184 | it('Should fail with an incorrect actor type', async function () { |
185 | await makeGetRequest({ | |
186 | url: server.url, | |
187 | path, | |
188 | query: { | |
189 | actorType: 'blabla' | |
190 | } | |
191 | }) | |
192 | }) | |
193 | ||
b8f4167f C |
194 | it('Should fail with an incorrect state', async function () { |
195 | await makeGetRequest({ | |
196 | url: server.url, | |
197 | path, | |
198 | query: { | |
97ecddae C |
199 | state: 'blabla', |
200 | actorType: 'Application' | |
b8f4167f C |
201 | } |
202 | }) | |
203 | }) | |
204 | ||
205 | it('Should fail succeed with the correct params', async function () { | |
206 | await makeGetRequest({ | |
207 | url: server.url, | |
208 | path, | |
c0e8b12e | 209 | expectedStatus: HttpStatusCode.OK_200, |
b8f4167f C |
210 | query: { |
211 | state: 'accepted' | |
212 | } | |
213 | }) | |
214 | }) | |
9a27cdc2 C |
215 | }) |
216 | ||
5b9c965d C |
217 | describe('When removing a follower', function () { |
218 | const path = '/api/v1/server/followers' | |
219 | ||
220 | it('Should fail with an invalid token', async function () { | |
221 | await makeDeleteRequest({ | |
222 | url: server.url, | |
223 | path: path + '/toto@localhost:9002', | |
224 | token: 'fake_token', | |
c0e8b12e | 225 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
5b9c965d C |
226 | }) |
227 | }) | |
228 | ||
229 | it('Should fail if the user is not an administrator', async function () { | |
230 | await makeDeleteRequest({ | |
231 | url: server.url, | |
232 | path: path + '/toto@localhost:9002', | |
233 | token: userAccessToken, | |
c0e8b12e | 234 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
5b9c965d C |
235 | }) |
236 | }) | |
237 | ||
238 | it('Should fail with an invalid follower', async function () { | |
239 | await makeDeleteRequest({ | |
240 | url: server.url, | |
241 | path: path + '/toto', | |
242 | token: server.accessToken, | |
c0e8b12e | 243 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
5b9c965d C |
244 | }) |
245 | }) | |
246 | ||
247 | it('Should fail with an unknown follower', async function () { | |
248 | await makeDeleteRequest({ | |
249 | url: server.url, | |
250 | path: path + '/toto@localhost:9003', | |
251 | token: server.accessToken, | |
c0e8b12e | 252 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
5b9c965d C |
253 | }) |
254 | }) | |
255 | }) | |
256 | ||
14893eb7 C |
257 | describe('When accepting a follower', function () { |
258 | const path = '/api/v1/server/followers' | |
259 | ||
260 | it('Should fail with an invalid token', async function () { | |
261 | await makePostBodyRequest({ | |
262 | url: server.url, | |
263 | path: path + '/toto@localhost:9002/accept', | |
264 | token: 'fake_token', | |
c0e8b12e | 265 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
14893eb7 C |
266 | }) |
267 | }) | |
268 | ||
269 | it('Should fail if the user is not an administrator', async function () { | |
270 | await makePostBodyRequest({ | |
271 | url: server.url, | |
272 | path: path + '/toto@localhost:9002/accept', | |
273 | token: userAccessToken, | |
c0e8b12e | 274 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
14893eb7 C |
275 | }) |
276 | }) | |
277 | ||
278 | it('Should fail with an invalid follower', async function () { | |
279 | await makePostBodyRequest({ | |
280 | url: server.url, | |
281 | path: path + '/toto/accept', | |
282 | token: server.accessToken, | |
c0e8b12e | 283 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
14893eb7 C |
284 | }) |
285 | }) | |
286 | ||
287 | it('Should fail with an unknown follower', async function () { | |
288 | await makePostBodyRequest({ | |
289 | url: server.url, | |
290 | path: path + '/toto@localhost:9003/accept', | |
291 | token: server.accessToken, | |
c0e8b12e | 292 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
14893eb7 C |
293 | }) |
294 | }) | |
295 | }) | |
296 | ||
297 | describe('When rejecting a follower', function () { | |
298 | const path = '/api/v1/server/followers' | |
299 | ||
300 | it('Should fail with an invalid token', async function () { | |
301 | await makePostBodyRequest({ | |
302 | url: server.url, | |
303 | path: path + '/toto@localhost:9002/reject', | |
304 | token: 'fake_token', | |
c0e8b12e | 305 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
14893eb7 C |
306 | }) |
307 | }) | |
308 | ||
309 | it('Should fail if the user is not an administrator', async function () { | |
310 | await makePostBodyRequest({ | |
311 | url: server.url, | |
312 | path: path + '/toto@localhost:9002/reject', | |
313 | token: userAccessToken, | |
c0e8b12e | 314 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
14893eb7 C |
315 | }) |
316 | }) | |
317 | ||
318 | it('Should fail with an invalid follower', async function () { | |
319 | await makePostBodyRequest({ | |
320 | url: server.url, | |
321 | path: path + '/toto/reject', | |
322 | token: server.accessToken, | |
c0e8b12e | 323 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
14893eb7 C |
324 | }) |
325 | }) | |
326 | ||
327 | it('Should fail with an unknown follower', async function () { | |
328 | await makePostBodyRequest({ | |
329 | url: server.url, | |
330 | path: path + '/toto@localhost:9003/reject', | |
331 | token: server.accessToken, | |
c0e8b12e | 332 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
14893eb7 C |
333 | }) |
334 | }) | |
335 | }) | |
336 | ||
9a27cdc2 | 337 | describe('When removing following', function () { |
0f91ae62 C |
338 | const path = '/api/v1/server/following' |
339 | ||
340 | it('Should fail with an invalid token', async function () { | |
eec63bbc C |
341 | await makeDeleteRequest({ |
342 | url: server.url, | |
343 | path: path + '/localhost:9002', | |
344 | token: 'fake_token', | |
c0e8b12e | 345 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
eec63bbc | 346 | }) |
0f91ae62 C |
347 | }) |
348 | ||
349 | it('Should fail if the user is not an administrator', async function () { | |
eec63bbc C |
350 | await makeDeleteRequest({ |
351 | url: server.url, | |
352 | path: path + '/localhost:9002', | |
353 | token: userAccessToken, | |
c0e8b12e | 354 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
eec63bbc C |
355 | }) |
356 | }) | |
357 | ||
358 | it('Should fail if we do not follow this server', async function () { | |
359 | await makeDeleteRequest({ | |
360 | url: server.url, | |
361 | path: path + '/example.com', | |
362 | token: server.accessToken, | |
c0e8b12e | 363 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
eec63bbc C |
364 | }) |
365 | }) | |
9a27cdc2 C |
366 | }) |
367 | }) | |
368 | ||
7c3b7976 C |
369 | after(async function () { |
370 | await cleanupTests([ server ]) | |
9a27cdc2 C |
371 | }) |
372 | }) |