aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/plugins.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/check-params/plugins.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/check-params/plugins.ts')
-rw-r--r--server/tests/api/check-params/plugins.ts95
1 files changed, 45 insertions, 50 deletions
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index a833fe6ff..33f84ecbc 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -1,27 +1,22 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
5import { 4import {
6 checkBadCountPagination, 5 checkBadCountPagination,
7 checkBadSortPagination, 6 checkBadSortPagination,
8 checkBadStartPagination, 7 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createUser, 9 createSingleServer,
11 flushAndRunServer,
12 immutableAssign,
13 installPlugin,
14 makeGetRequest, 10 makeGetRequest,
15 makePostBodyRequest, 11 makePostBodyRequest,
16 makePutBodyRequest, 12 makePutBodyRequest,
17 ServerInfo, 13 PeerTubeServer,
18 setAccessTokensToServers, 14 setAccessTokensToServers
19 userLogin
20} from '@shared/extra-utils' 15} from '@shared/extra-utils'
21import { PeerTubePlugin, PluginType } from '@shared/models' 16import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models'
22 17
23describe('Test server plugins API validators', function () { 18describe('Test server plugins API validators', function () {
24 let server: ServerInfo 19 let server: PeerTubeServer
25 let userAccessToken = null 20 let userAccessToken = null
26 21
27 const npmPlugin = 'peertube-plugin-hello-world' 22 const npmPlugin = 'peertube-plugin-hello-world'
@@ -37,7 +32,7 @@ describe('Test server plugins API validators', function () {
37 before(async function () { 32 before(async function () {
38 this.timeout(30000) 33 this.timeout(30000)
39 34
40 server = await flushAndRunServer(1) 35 server = await createSingleServer(1)
41 36
42 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
43 38
@@ -46,17 +41,17 @@ describe('Test server plugins API validators', function () {
46 password: 'password' 41 password: 'password'
47 } 42 }
48 43
49 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 44 await server.users.create({ username: user.username, password: user.password })
50 userAccessToken = await userLogin(server, user) 45 userAccessToken = await server.login.getAccessToken(user)
51 46
52 { 47 {
53 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) 48 const res = await server.plugins.install({ npmName: npmPlugin })
54 const plugin = res.body as PeerTubePlugin 49 const plugin = res.body as PeerTubePlugin
55 npmVersion = plugin.version 50 npmVersion = plugin.version
56 } 51 }
57 52
58 { 53 {
59 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin }) 54 const res = await server.plugins.install({ npmName: themePlugin })
60 const plugin = res.body as PeerTubePlugin 55 const plugin = res.body as PeerTubePlugin
61 themeVersion = plugin.version 56 themeVersion = plugin.version
62 } 57 }
@@ -74,7 +69,7 @@ describe('Test server plugins API validators', function () {
74 ] 69 ]
75 70
76 for (const p of paths) { 71 for (const p of paths) {
77 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 72 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
78 } 73 }
79 }) 74 })
80 75
@@ -82,7 +77,7 @@ describe('Test server plugins API validators', function () {
82 await makeGetRequest({ 77 await makeGetRequest({
83 url: server.url, 78 url: server.url,
84 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', 79 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png',
85 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 80 expectedStatus: HttpStatusCode.NOT_FOUND_404
86 }) 81 })
87 }) 82 })
88 83
@@ -97,7 +92,7 @@ describe('Test server plugins API validators', function () {
97 ] 92 ]
98 93
99 for (const p of paths) { 94 for (const p of paths) {
100 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 95 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
101 } 96 }
102 }) 97 })
103 98
@@ -111,14 +106,14 @@ describe('Test server plugins API validators', function () {
111 ] 106 ]
112 107
113 for (const p of paths) { 108 for (const p of paths) {
114 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 109 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 } 110 }
116 }) 111 })
117 112
118 it('Should fail with an unknown auth name', async function () { 113 it('Should fail with an unknown auth name', async function () {
119 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' 114 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth'
120 115
121 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 116 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
122 }) 117 })
123 118
124 it('Should fail with an unknown static file', async function () { 119 it('Should fail with an unknown static file', async function () {
@@ -130,7 +125,7 @@ describe('Test server plugins API validators', function () {
130 ] 125 ]
131 126
132 for (const p of paths) { 127 for (const p of paths) {
133 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 128 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
134 } 129 }
135 }) 130 })
136 131
@@ -138,7 +133,7 @@ describe('Test server plugins API validators', function () {
138 await makeGetRequest({ 133 await makeGetRequest({
139 url: server.url, 134 url: server.url,
140 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', 135 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css',
141 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 136 expectedStatus: HttpStatusCode.NOT_FOUND_404
142 }) 137 })
143 }) 138 })
144 139
@@ -152,11 +147,11 @@ describe('Test server plugins API validators', function () {
152 ] 147 ]
153 148
154 for (const p of paths) { 149 for (const p of paths) {
155 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 }) 150 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.OK_200 })
156 } 151 }
157 152
158 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' 153 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth'
159 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 }) 154 await makeGetRequest({ url: server.url, path: authPath, expectedStatus: HttpStatusCode.FOUND_302 })
160 }) 155 })
161 }) 156 })
162 157
@@ -174,7 +169,7 @@ describe('Test server plugins API validators', function () {
174 path, 169 path,
175 token: 'fake_token', 170 token: 'fake_token',
176 query: baseQuery, 171 query: baseQuery,
177 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 172 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
178 }) 173 })
179 }) 174 })
180 175
@@ -184,7 +179,7 @@ describe('Test server plugins API validators', function () {
184 path, 179 path,
185 token: userAccessToken, 180 token: userAccessToken,
186 query: baseQuery, 181 query: baseQuery,
187 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 182 expectedStatus: HttpStatusCode.FORBIDDEN_403
188 }) 183 })
189 }) 184 })
190 185
@@ -201,7 +196,7 @@ describe('Test server plugins API validators', function () {
201 }) 196 })
202 197
203 it('Should fail with an invalid plugin type', async function () { 198 it('Should fail with an invalid plugin type', async function () {
204 const query = immutableAssign(baseQuery, { pluginType: 5 }) 199 const query = { ...baseQuery, pluginType: 5 }
205 200
206 await makeGetRequest({ 201 await makeGetRequest({
207 url: server.url, 202 url: server.url,
@@ -212,7 +207,7 @@ describe('Test server plugins API validators', function () {
212 }) 207 })
213 208
214 it('Should fail with an invalid current peertube engine', async function () { 209 it('Should fail with an invalid current peertube engine', async function () {
215 const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) 210 const query = { ...baseQuery, currentPeerTubeEngine: '1.0' }
216 211
217 await makeGetRequest({ 212 await makeGetRequest({
218 url: server.url, 213 url: server.url,
@@ -228,7 +223,7 @@ describe('Test server plugins API validators', function () {
228 path, 223 path,
229 token: server.accessToken, 224 token: server.accessToken,
230 query: baseQuery, 225 query: baseQuery,
231 statusCodeExpected: HttpStatusCode.OK_200 226 expectedStatus: HttpStatusCode.OK_200
232 }) 227 })
233 }) 228 })
234 }) 229 })
@@ -245,7 +240,7 @@ describe('Test server plugins API validators', function () {
245 path, 240 path,
246 token: 'fake_token', 241 token: 'fake_token',
247 query: baseQuery, 242 query: baseQuery,
248 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 243 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
249 }) 244 })
250 }) 245 })
251 246
@@ -255,7 +250,7 @@ describe('Test server plugins API validators', function () {
255 path, 250 path,
256 token: userAccessToken, 251 token: userAccessToken,
257 query: baseQuery, 252 query: baseQuery,
258 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 253 expectedStatus: HttpStatusCode.FORBIDDEN_403
259 }) 254 })
260 }) 255 })
261 256
@@ -272,7 +267,7 @@ describe('Test server plugins API validators', function () {
272 }) 267 })
273 268
274 it('Should fail with an invalid plugin type', async function () { 269 it('Should fail with an invalid plugin type', async function () {
275 const query = immutableAssign(baseQuery, { pluginType: 5 }) 270 const query = { ...baseQuery, pluginType: 5 }
276 271
277 await makeGetRequest({ 272 await makeGetRequest({
278 url: server.url, 273 url: server.url,
@@ -288,7 +283,7 @@ describe('Test server plugins API validators', function () {
288 path, 283 path,
289 token: server.accessToken, 284 token: server.accessToken,
290 query: baseQuery, 285 query: baseQuery,
291 statusCodeExpected: HttpStatusCode.OK_200 286 expectedStatus: HttpStatusCode.OK_200
292 }) 287 })
293 }) 288 })
294 }) 289 })
@@ -302,7 +297,7 @@ describe('Test server plugins API validators', function () {
302 url: server.url, 297 url: server.url,
303 path: path + suffix, 298 path: path + suffix,
304 token: 'fake_token', 299 token: 'fake_token',
305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 300 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
306 }) 301 })
307 } 302 }
308 }) 303 })
@@ -313,7 +308,7 @@ describe('Test server plugins API validators', function () {
313 url: server.url, 308 url: server.url,
314 path: path + suffix, 309 path: path + suffix,
315 token: userAccessToken, 310 token: userAccessToken,
316 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 311 expectedStatus: HttpStatusCode.FORBIDDEN_403
317 }) 312 })
318 } 313 }
319 }) 314 })
@@ -324,7 +319,7 @@ describe('Test server plugins API validators', function () {
324 url: server.url, 319 url: server.url,
325 path: path + suffix, 320 path: path + suffix,
326 token: server.accessToken, 321 token: server.accessToken,
327 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 322 expectedStatus: HttpStatusCode.BAD_REQUEST_400
328 }) 323 })
329 } 324 }
330 325
@@ -333,7 +328,7 @@ describe('Test server plugins API validators', function () {
333 url: server.url, 328 url: server.url,
334 path: path + suffix, 329 path: path + suffix,
335 token: server.accessToken, 330 token: server.accessToken,
336 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 331 expectedStatus: HttpStatusCode.BAD_REQUEST_400
337 }) 332 })
338 } 333 }
339 }) 334 })
@@ -344,7 +339,7 @@ describe('Test server plugins API validators', function () {
344 url: server.url, 339 url: server.url,
345 path: path + suffix, 340 path: path + suffix,
346 token: server.accessToken, 341 token: server.accessToken,
347 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 342 expectedStatus: HttpStatusCode.NOT_FOUND_404
348 }) 343 })
349 } 344 }
350 }) 345 })
@@ -355,7 +350,7 @@ describe('Test server plugins API validators', function () {
355 url: server.url, 350 url: server.url,
356 path: path + suffix, 351 path: path + suffix,
357 token: server.accessToken, 352 token: server.accessToken,
358 statusCodeExpected: HttpStatusCode.OK_200 353 expectedStatus: HttpStatusCode.OK_200
359 }) 354 })
360 } 355 }
361 }) 356 })
@@ -371,7 +366,7 @@ describe('Test server plugins API validators', function () {
371 path: path + npmPlugin + '/settings', 366 path: path + npmPlugin + '/settings',
372 fields: { settings }, 367 fields: { settings },
373 token: 'fake_token', 368 token: 'fake_token',
374 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 369 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
375 }) 370 })
376 }) 371 })
377 372
@@ -381,7 +376,7 @@ describe('Test server plugins API validators', function () {
381 path: path + npmPlugin + '/settings', 376 path: path + npmPlugin + '/settings',
382 fields: { settings }, 377 fields: { settings },
383 token: userAccessToken, 378 token: userAccessToken,
384 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 379 expectedStatus: HttpStatusCode.FORBIDDEN_403
385 }) 380 })
386 }) 381 })
387 382
@@ -391,7 +386,7 @@ describe('Test server plugins API validators', function () {
391 path: path + 'toto/settings', 386 path: path + 'toto/settings',
392 fields: { settings }, 387 fields: { settings },
393 token: server.accessToken, 388 token: server.accessToken,
394 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 389 expectedStatus: HttpStatusCode.BAD_REQUEST_400
395 }) 390 })
396 391
397 await makePutBodyRequest({ 392 await makePutBodyRequest({
@@ -399,7 +394,7 @@ describe('Test server plugins API validators', function () {
399 path: path + 'peertube-plugin-TOTO/settings', 394 path: path + 'peertube-plugin-TOTO/settings',
400 fields: { settings }, 395 fields: { settings },
401 token: server.accessToken, 396 token: server.accessToken,
402 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 397 expectedStatus: HttpStatusCode.BAD_REQUEST_400
403 }) 398 })
404 }) 399 })
405 400
@@ -409,7 +404,7 @@ describe('Test server plugins API validators', function () {
409 path: path + 'peertube-plugin-toto/settings', 404 path: path + 'peertube-plugin-toto/settings',
410 fields: { settings }, 405 fields: { settings },
411 token: server.accessToken, 406 token: server.accessToken,
412 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 407 expectedStatus: HttpStatusCode.NOT_FOUND_404
413 }) 408 })
414 }) 409 })
415 410
@@ -419,7 +414,7 @@ describe('Test server plugins API validators', function () {
419 path: path + npmPlugin + '/settings', 414 path: path + npmPlugin + '/settings',
420 fields: { settings }, 415 fields: { settings },
421 token: server.accessToken, 416 token: server.accessToken,
422 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 417 expectedStatus: HttpStatusCode.NO_CONTENT_204
423 }) 418 })
424 }) 419 })
425 }) 420 })
@@ -434,7 +429,7 @@ describe('Test server plugins API validators', function () {
434 path: path + suffix, 429 path: path + suffix,
435 fields: { npmName: npmPlugin }, 430 fields: { npmName: npmPlugin },
436 token: 'fake_token', 431 token: 'fake_token',
437 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 432 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
438 }) 433 })
439 } 434 }
440 }) 435 })
@@ -446,7 +441,7 @@ describe('Test server plugins API validators', function () {
446 path: path + suffix, 441 path: path + suffix,
447 fields: { npmName: npmPlugin }, 442 fields: { npmName: npmPlugin },
448 token: userAccessToken, 443 token: userAccessToken,
449 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 444 expectedStatus: HttpStatusCode.FORBIDDEN_403
450 }) 445 })
451 } 446 }
452 }) 447 })
@@ -458,7 +453,7 @@ describe('Test server plugins API validators', function () {
458 path: path + suffix, 453 path: path + suffix,
459 fields: { npmName: 'toto' }, 454 fields: { npmName: 'toto' },
460 token: server.accessToken, 455 token: server.accessToken,
461 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 456 expectedStatus: HttpStatusCode.BAD_REQUEST_400
462 }) 457 })
463 } 458 }
464 459
@@ -468,7 +463,7 @@ describe('Test server plugins API validators', function () {
468 path: path + suffix, 463 path: path + suffix,
469 fields: { npmName: 'peertube-plugin-TOTO' }, 464 fields: { npmName: 'peertube-plugin-TOTO' },
470 token: server.accessToken, 465 token: server.accessToken,
471 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 466 expectedStatus: HttpStatusCode.BAD_REQUEST_400
472 }) 467 })
473 } 468 }
474 }) 469 })
@@ -488,7 +483,7 @@ describe('Test server plugins API validators', function () {
488 path: path + obj.suffix, 483 path: path + obj.suffix,
489 fields: { npmName: npmPlugin }, 484 fields: { npmName: npmPlugin },
490 token: server.accessToken, 485 token: server.accessToken,
491 statusCodeExpected: obj.status 486 expectedStatus: obj.status
492 }) 487 })
493 } 488 }
494 }) 489 })