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