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