]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
3c558d4eaf586bbefcafe845dfefe853c1b7c18d
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import { omit } from 'lodash'
4 import 'mocha'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
6
7 import {
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
20 describe('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 '240p': false,
89 '360p': true,
90 '480p': true,
91 '720p': false,
92 '1080p': false,
93 '2160p': false
94 },
95 webtorrent: {
96 enabled: true
97 },
98 hls: {
99 enabled: false
100 }
101 },
102 import: {
103 videos: {
104 http: {
105 enabled: false
106 },
107 torrent: {
108 enabled: false
109 }
110 }
111 },
112 autoBlacklist: {
113 videos: {
114 ofUsers: {
115 enabled: false
116 }
117 }
118 },
119 followers: {
120 instance: {
121 enabled: false,
122 manualApproval: true
123 }
124 },
125 followings: {
126 instance: {
127 autoFollowBack: {
128 enabled: true
129 },
130 autoFollowIndex: {
131 enabled: true,
132 indexUrl: 'https://index.example.com'
133 }
134 }
135 }
136 }
137
138 // ---------------------------------------------------------------
139
140 before(async function () {
141 this.timeout(30000)
142
143 server = await flushAndRunServer(1)
144
145 await setAccessTokensToServers([ server ])
146
147 const user = {
148 username: 'user1',
149 password: 'password'
150 }
151 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
152 userAccessToken = await userLogin(server, user)
153 })
154
155 describe('When getting the configuration', function () {
156 it('Should fail without token', async function () {
157 await makeGetRequest({
158 url: server.url,
159 path,
160 statusCodeExpected: 401
161 })
162 })
163
164 it('Should fail if the user is not an administrator', async function () {
165 await makeGetRequest({
166 url: server.url,
167 path,
168 token: userAccessToken,
169 statusCodeExpected: 403
170 })
171 })
172 })
173
174 describe('When updating the configuration', function () {
175 it('Should fail without token', async function () {
176 await makePutBodyRequest({
177 url: server.url,
178 path,
179 fields: updateParams,
180 statusCodeExpected: 401
181 })
182 })
183
184 it('Should fail if the user is not an administrator', async function () {
185 await makePutBodyRequest({
186 url: server.url,
187 path,
188 fields: updateParams,
189 token: userAccessToken,
190 statusCodeExpected: 403
191 })
192 })
193
194 it('Should fail if it misses a key', async function () {
195 const newUpdateParams = omit(updateParams, 'admin.email')
196
197 await makePutBodyRequest({
198 url: server.url,
199 path,
200 fields: newUpdateParams,
201 token: server.accessToken,
202 statusCodeExpected: 400
203 })
204 })
205
206 it('Should fail with a bad default NSFW policy', async function () {
207 const newUpdateParams = immutableAssign(updateParams, {
208 instance: {
209 defaultNSFWPolicy: 'hello'
210 }
211 })
212
213 await makePutBodyRequest({
214 url: server.url,
215 path,
216 fields: newUpdateParams,
217 token: server.accessToken,
218 statusCodeExpected: 400
219 })
220 })
221
222 it('Should fail if email disabled and signup requires email verification', async function () {
223 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
224 const newUpdateParams = immutableAssign(updateParams, {
225 signup: {
226 enabled: true,
227 limit: 5,
228 requiresEmailVerification: true
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 with a disabled webtorrent & hls transcoding', async function () {
242 const newUpdateParams = immutableAssign(updateParams, {
243 transcoding: {
244 hls: {
245 enabled: false
246 },
247 webtorrent: {
248 enabled: false
249 }
250 }
251 })
252
253 await makePutBodyRequest({
254 url: server.url,
255 path,
256 fields: newUpdateParams,
257 token: server.accessToken,
258 statusCodeExpected: 400
259 })
260 })
261
262 it('Should success with the correct parameters', async function () {
263 await makePutBodyRequest({
264 url: server.url,
265 path,
266 fields: updateParams,
267 token: server.accessToken,
268 statusCodeExpected: 200
269 })
270 })
271 })
272
273 describe('When deleting the configuration', function () {
274 it('Should fail without token', async function () {
275 await makeDeleteRequest({
276 url: server.url,
277 path,
278 statusCodeExpected: 401
279 })
280 })
281
282 it('Should fail if the user is not an administrator', async function () {
283 await makeDeleteRequest({
284 url: server.url,
285 path,
286 token: userAccessToken,
287 statusCodeExpected: 403
288 })
289 })
290 })
291
292 after(async function () {
293 await cleanupTests([ server ])
294 })
295 })