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