]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Upgrade server dep
[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 '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 }
138
139 // ---------------------------------------------------------------
140
141 before(async function () {
142 this.timeout(30000)
143
144 server = await flushAndRunServer(1)
145
146 await setAccessTokensToServers([ server ])
147
148 const user = {
149 username: 'user1',
150 password: 'password'
151 }
152 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
153 userAccessToken = await userLogin(server, user)
154 })
155
156 describe('When getting the configuration', function () {
157 it('Should fail without token', async function () {
158 await makeGetRequest({
159 url: server.url,
160 path,
161 statusCodeExpected: 401
162 })
163 })
164
165 it('Should fail if the user is not an administrator', async function () {
166 await makeGetRequest({
167 url: server.url,
168 path,
169 token: userAccessToken,
170 statusCodeExpected: 403
171 })
172 })
173 })
174
175 describe('When updating the configuration', function () {
176 it('Should fail without token', async function () {
177 await makePutBodyRequest({
178 url: server.url,
179 path,
180 fields: updateParams,
181 statusCodeExpected: 401
182 })
183 })
184
185 it('Should fail if the user is not an administrator', async function () {
186 await makePutBodyRequest({
187 url: server.url,
188 path,
189 fields: updateParams,
190 token: userAccessToken,
191 statusCodeExpected: 403
192 })
193 })
194
195 it('Should fail if it misses a key', async function () {
196 const newUpdateParams = omit(updateParams, 'admin.email')
197
198 await makePutBodyRequest({
199 url: server.url,
200 path,
201 fields: newUpdateParams,
202 token: server.accessToken,
203 statusCodeExpected: 400
204 })
205 })
206
207 it('Should fail with a bad default NSFW policy', async function () {
208 const newUpdateParams = immutableAssign(updateParams, {
209 instance: {
210 defaultNSFWPolicy: 'hello'
211 }
212 })
213
214 await makePutBodyRequest({
215 url: server.url,
216 path,
217 fields: newUpdateParams,
218 token: server.accessToken,
219 statusCodeExpected: 400
220 })
221 })
222
223 it('Should fail if email disabled and signup requires email verification', async function () {
224 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
225 const newUpdateParams = immutableAssign(updateParams, {
226 signup: {
227 enabled: true,
228 limit: 5,
229 requiresEmailVerification: true
230 }
231 })
232
233 await makePutBodyRequest({
234 url: server.url,
235 path,
236 fields: newUpdateParams,
237 token: server.accessToken,
238 statusCodeExpected: 400
239 })
240 })
241
242 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
243 const newUpdateParams = immutableAssign(updateParams, {
244 transcoding: {
245 hls: {
246 enabled: false
247 },
248 webtorrent: {
249 enabled: false
250 }
251 }
252 })
253
254 await makePutBodyRequest({
255 url: server.url,
256 path,
257 fields: newUpdateParams,
258 token: server.accessToken,
259 statusCodeExpected: 400
260 })
261 })
262
263 it('Should success with the correct parameters', async function () {
264 await makePutBodyRequest({
265 url: server.url,
266 path,
267 fields: updateParams,
268 token: server.accessToken,
269 statusCodeExpected: 200
270 })
271 })
272 })
273
274 describe('When deleting the configuration', function () {
275 it('Should fail without token', async function () {
276 await makeDeleteRequest({
277 url: server.url,
278 path,
279 statusCodeExpected: 401
280 })
281 })
282
283 it('Should fail if the user is not an administrator', async function () {
284 await makeDeleteRequest({
285 url: server.url,
286 path,
287 token: userAccessToken,
288 statusCodeExpected: 403
289 })
290 })
291 })
292
293 after(async function () {
294 await cleanupTests([ server ])
295 })
296 })