]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd206f0b
C
2
3import { omit } from 'lodash'
4import 'mocha'
09cababd 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
fd206f0b
C
6
7import {
8424c402
C
8 cleanupTests,
9 createUser,
10 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest,
13 makeGetRequest,
14 makePutBodyRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 userLogin
94565d52 18} from '../../../../shared/extra-utils'
2d53be02 19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
fd206f0b
C
20
21describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom'
23 let server: ServerInfo
24 let userAccessToken: string
25 const updateParams: CustomConfig = {
66b16caf
C
26 instance: {
27 name: 'PeerTube updated',
2e3a0215 28 shortDescription: 'my short description',
66b16caf 29 description: 'my super description',
00b5556c 30 terms: 'my super terms',
ccc00cb2
C
31 codeOfConduct: 'my super coc',
32
8ae03c37 33 creationReason: 'my super reason',
ccc00cb2
C
34 moderationInformation: 'my super moderation information',
35 administrator: 'Kuja',
36 maintenanceLifetime: 'forever',
37 businessModel: 'my super business model',
be04c6fd 38 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
39
40 languages: [ 'en', 'es' ],
41 categories: [ 1, 2 ],
42
f8802489 43 isNSFW: true,
901637bb 44 defaultClientRoute: '/videos/recently-added',
0883b324 45 defaultNSFWPolicy: 'blur',
00b5556c
C
46 customizations: {
47 javascript: 'alert("coucou")',
48 css: 'body { background-color: red; }'
49 }
66b16caf 50 },
7cd4d2ba
C
51 theme: {
52 default: 'default'
53 },
8be1afa1
C
54 services: {
55 twitter: {
56 username: '@MySuperUsername',
57 whitelisted: true
58 }
59 },
fd206f0b
C
60 cache: {
61 previews: {
62 size: 2
40e87e9e
C
63 },
64 captions: {
65 size: 3
fd206f0b
C
66 }
67 },
68 signup: {
69 enabled: false,
d9eaee39
JM
70 limit: 5,
71 requiresEmailVerification: false
fd206f0b
C
72 },
73 admin: {
74 email: 'superadmin1@example.com'
75 },
a4101923
C
76 contactForm: {
77 enabled: false
78 },
fd206f0b 79 user: {
bee0abff
FA
80 videoQuota: 5242881,
81 videoQuotaDaily: 318742
fd206f0b
C
82 },
83 transcoding: {
84 enabled: true,
14e2014a 85 allowAdditionalExtensions: true,
536598cf 86 allowAudioFiles: true,
fd206f0b
C
87 threads: 1,
88 resolutions: {
5c7d6508 89 '0p': false,
fd206f0b
C
90 '240p': false,
91 '360p': true,
92 '480p': true,
93 '720p': false,
db714ab4
C
94 '1080p': false,
95 '2160p': false
09209296 96 },
d7a25329
C
97 webtorrent: {
98 enabled: true
99 },
09209296
C
100 hls: {
101 enabled: false
fd206f0b 102 }
5d08a6a7 103 },
c6c0fa6c
C
104 live: {
105 enabled: true,
106
fb719404
C
107 allowReplay: false,
108 maxDuration: null,
a056ca48
C
109 maxInstanceLives: -1,
110 maxUserLives: 50,
fb719404 111
c6c0fa6c
C
112 transcoding: {
113 enabled: true,
114 threads: 4,
115 resolutions: {
116 '240p': true,
117 '360p': true,
118 '480p': true,
119 '720p': true,
120 '1080p': true,
121 '2160p': true
122 }
123 }
124 },
5d08a6a7
C
125 import: {
126 videos: {
127 http: {
128 enabled: false
a84b8fa5
C
129 },
130 torrent: {
131 enabled: false
5d08a6a7
C
132 }
133 }
7ccddd7b
JM
134 },
135 autoBlacklist: {
136 videos: {
137 ofUsers: {
138 enabled: false
139 }
140 }
5b9c965d
C
141 },
142 followers: {
143 instance: {
14893eb7
C
144 enabled: false,
145 manualApproval: true
5b9c965d 146 }
8424c402
C
147 },
148 followings: {
149 instance: {
150 autoFollowBack: {
151 enabled: true
152 },
153 autoFollowIndex: {
154 enabled: true,
155 indexUrl: 'https://index.example.com'
156 }
157 }
72c33e71
C
158 },
159 broadcastMessage: {
160 enabled: true,
161 dismissable: true,
162 message: 'super message',
163 level: 'warning'
5fb2e288
C
164 },
165 search: {
166 remoteUri: {
167 users: true,
168 anonymous: true
169 },
170 searchIndex: {
171 enabled: true,
172 url: 'https://search.joinpeertube.org',
173 disableLocalSearch: true,
174 isDefaultSearch: true
175 }
fd206f0b
C
176 }
177 }
178
179 // ---------------------------------------------------------------
180
181 before(async function () {
e212f887 182 this.timeout(30000)
fd206f0b 183
210feb6c 184 server = await flushAndRunServer(1)
fd206f0b
C
185
186 await setAccessTokensToServers([ server ])
187
188 const user = {
189 username: 'user1',
190 password: 'password'
191 }
1eddc9a7 192 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
fd206f0b
C
193 userAccessToken = await userLogin(server, user)
194 })
195
196 describe('When getting the configuration', function () {
197 it('Should fail without token', async function () {
198 await makeGetRequest({
199 url: server.url,
200 path,
2d53be02 201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
202 })
203 })
204
205 it('Should fail if the user is not an administrator', async function () {
206 await makeGetRequest({
207 url: server.url,
208 path,
209 token: userAccessToken,
2d53be02 210 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
211 })
212 })
213 })
214
215 describe('When updating the configuration', function () {
216 it('Should fail without token', async function () {
217 await makePutBodyRequest({
218 url: server.url,
219 path,
220 fields: updateParams,
2d53be02 221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
222 })
223 })
224
225 it('Should fail if the user is not an administrator', async function () {
226 await makePutBodyRequest({
227 url: server.url,
228 path,
229 fields: updateParams,
230 token: userAccessToken,
2d53be02 231 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
232 })
233 })
234
235 it('Should fail if it misses a key', async function () {
236 const newUpdateParams = omit(updateParams, 'admin.email')
237
238 await makePutBodyRequest({
239 url: server.url,
240 path,
0883b324
C
241 fields: newUpdateParams,
242 token: server.accessToken,
2d53be02 243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
0883b324
C
244 })
245 })
246
247 it('Should fail with a bad default NSFW policy', async function () {
248 const newUpdateParams = immutableAssign(updateParams, {
249 instance: {
250 defaultNSFWPolicy: 'hello'
251 }
252 })
253
254 await makePutBodyRequest({
255 url: server.url,
256 path,
576ad67a
JM
257 fields: newUpdateParams,
258 token: server.accessToken,
2d53be02 259 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
260 })
261 })
262
263 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 264 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
576ad67a
JM
265 const newUpdateParams = immutableAssign(updateParams, {
266 signup: {
267 enabled: true,
268 limit: 5,
269 requiresEmailVerification: true
270 }
271 })
272
273 await makePutBodyRequest({
274 url: server.url,
275 path,
fd206f0b
C
276 fields: newUpdateParams,
277 token: server.accessToken,
2d53be02 278 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
279 })
280 })
281
d7a25329
C
282 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
283 const newUpdateParams = immutableAssign(updateParams, {
284 transcoding: {
285 hls: {
286 enabled: false
287 },
288 webtorrent: {
289 enabled: false
290 }
291 }
292 })
293
294 await makePutBodyRequest({
295 url: server.url,
296 path,
297 fields: newUpdateParams,
298 token: server.accessToken,
2d53be02 299 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
300 })
301 })
302
fd206f0b
C
303 it('Should success with the correct parameters', async function () {
304 await makePutBodyRequest({
305 url: server.url,
306 path,
307 fields: updateParams,
308 token: server.accessToken,
2d53be02 309 statusCodeExpected: HttpStatusCode.OK_200
fd206f0b
C
310 })
311 })
312 })
313
314 describe('When deleting the configuration', function () {
315 it('Should fail without token', async function () {
316 await makeDeleteRequest({
317 url: server.url,
318 path,
2d53be02 319 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
320 })
321 })
322
323 it('Should fail if the user is not an administrator', async function () {
324 await makeDeleteRequest({
325 url: server.url,
326 path,
327 token: userAccessToken,
2d53be02 328 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
329 })
330 })
331 })
332
7c3b7976
C
333 after(async function () {
334 await cleanupTests([ server ])
fd206f0b
C
335 })
336})