]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Allow user to search through their watch history (#3576)
[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 94 '1080p': false,
b7085c71 95 '1440p': false,
db714ab4 96 '2160p': false
09209296 97 },
d7a25329
C
98 webtorrent: {
99 enabled: true
100 },
09209296
C
101 hls: {
102 enabled: false
fd206f0b 103 }
5d08a6a7 104 },
c6c0fa6c
C
105 live: {
106 enabled: true,
107
fb719404 108 allowReplay: false,
c9bc850e 109 maxDuration: 30,
a056ca48
C
110 maxInstanceLives: -1,
111 maxUserLives: 50,
fb719404 112
c6c0fa6c
C
113 transcoding: {
114 enabled: true,
115 threads: 4,
116 resolutions: {
117 '240p': true,
118 '360p': true,
119 '480p': true,
120 '720p': true,
121 '1080p': true,
b7085c71 122 '1440p': true,
c6c0fa6c
C
123 '2160p': true
124 }
125 }
126 },
5d08a6a7
C
127 import: {
128 videos: {
129 http: {
130 enabled: false
a84b8fa5
C
131 },
132 torrent: {
133 enabled: false
5d08a6a7
C
134 }
135 }
7ccddd7b
JM
136 },
137 autoBlacklist: {
138 videos: {
139 ofUsers: {
140 enabled: false
141 }
142 }
5b9c965d
C
143 },
144 followers: {
145 instance: {
14893eb7
C
146 enabled: false,
147 manualApproval: true
5b9c965d 148 }
8424c402
C
149 },
150 followings: {
151 instance: {
152 autoFollowBack: {
153 enabled: true
154 },
155 autoFollowIndex: {
156 enabled: true,
157 indexUrl: 'https://index.example.com'
158 }
159 }
72c33e71
C
160 },
161 broadcastMessage: {
162 enabled: true,
163 dismissable: true,
164 message: 'super message',
165 level: 'warning'
5fb2e288
C
166 },
167 search: {
168 remoteUri: {
169 users: true,
170 anonymous: true
171 },
172 searchIndex: {
173 enabled: true,
174 url: 'https://search.joinpeertube.org',
175 disableLocalSearch: true,
176 isDefaultSearch: true
177 }
fd206f0b
C
178 }
179 }
180
181 // ---------------------------------------------------------------
182
183 before(async function () {
e212f887 184 this.timeout(30000)
fd206f0b 185
210feb6c 186 server = await flushAndRunServer(1)
fd206f0b
C
187
188 await setAccessTokensToServers([ server ])
189
190 const user = {
191 username: 'user1',
192 password: 'password'
193 }
1eddc9a7 194 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
fd206f0b
C
195 userAccessToken = await userLogin(server, user)
196 })
197
198 describe('When getting the configuration', function () {
199 it('Should fail without token', async function () {
200 await makeGetRequest({
201 url: server.url,
202 path,
2d53be02 203 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
204 })
205 })
206
207 it('Should fail if the user is not an administrator', async function () {
208 await makeGetRequest({
209 url: server.url,
210 path,
211 token: userAccessToken,
2d53be02 212 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
213 })
214 })
215 })
216
217 describe('When updating the configuration', function () {
218 it('Should fail without token', async function () {
219 await makePutBodyRequest({
220 url: server.url,
221 path,
222 fields: updateParams,
2d53be02 223 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
224 })
225 })
226
227 it('Should fail if the user is not an administrator', async function () {
228 await makePutBodyRequest({
229 url: server.url,
230 path,
231 fields: updateParams,
232 token: userAccessToken,
2d53be02 233 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
234 })
235 })
236
237 it('Should fail if it misses a key', async function () {
238 const newUpdateParams = omit(updateParams, 'admin.email')
239
240 await makePutBodyRequest({
241 url: server.url,
242 path,
0883b324
C
243 fields: newUpdateParams,
244 token: server.accessToken,
2d53be02 245 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
0883b324
C
246 })
247 })
248
249 it('Should fail with a bad default NSFW policy', async function () {
250 const newUpdateParams = immutableAssign(updateParams, {
251 instance: {
252 defaultNSFWPolicy: 'hello'
253 }
254 })
255
256 await makePutBodyRequest({
257 url: server.url,
258 path,
576ad67a
JM
259 fields: newUpdateParams,
260 token: server.accessToken,
2d53be02 261 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
262 })
263 })
264
265 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 266 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
576ad67a
JM
267 const newUpdateParams = immutableAssign(updateParams, {
268 signup: {
269 enabled: true,
270 limit: 5,
271 requiresEmailVerification: true
272 }
273 })
274
275 await makePutBodyRequest({
276 url: server.url,
277 path,
fd206f0b
C
278 fields: newUpdateParams,
279 token: server.accessToken,
2d53be02 280 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
281 })
282 })
283
d7a25329
C
284 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
285 const newUpdateParams = immutableAssign(updateParams, {
286 transcoding: {
287 hls: {
288 enabled: false
289 },
290 webtorrent: {
291 enabled: false
292 }
293 }
294 })
295
296 await makePutBodyRequest({
297 url: server.url,
298 path,
299 fields: newUpdateParams,
300 token: server.accessToken,
2d53be02 301 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
302 })
303 })
304
fd206f0b
C
305 it('Should success with the correct parameters', async function () {
306 await makePutBodyRequest({
307 url: server.url,
308 path,
309 fields: updateParams,
310 token: server.accessToken,
2d53be02 311 statusCodeExpected: HttpStatusCode.OK_200
fd206f0b
C
312 })
313 })
314 })
315
316 describe('When deleting the configuration', function () {
317 it('Should fail without token', async function () {
318 await makeDeleteRequest({
319 url: server.url,
320 path,
2d53be02 321 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
322 })
323 })
324
325 it('Should fail if the user is not an administrator', async function () {
326 await makeDeleteRequest({
327 url: server.url,
328 path,
329 token: userAccessToken,
2d53be02 330 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
331 })
332 })
333 })
334
7c3b7976
C
335 after(async function () {
336 await cleanupTests([ server ])
fd206f0b
C
337 })
338})