]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
f716dc673ce277063a0a6eec73fe995e73d091b9
[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 moderationInformation: 'my super moderation information',
33 administrator: 'Kuja',
34 maintenanceLifetime: 'forever',
35 businessModel: 'my super business model',
36
37 languages: [ 'en', 'es' ],
38 categories: [ 1, 2 ],
39
40 isNSFW: true,
41 defaultClientRoute: '/videos/recently-added',
42 defaultNSFWPolicy: 'blur',
43 customizations: {
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
46 }
47 },
48 theme: {
49 default: 'default'
50 },
51 services: {
52 twitter: {
53 username: '@MySuperUsername',
54 whitelisted: true
55 }
56 },
57 cache: {
58 previews: {
59 size: 2
60 },
61 captions: {
62 size: 3
63 }
64 },
65 signup: {
66 enabled: false,
67 limit: 5,
68 requiresEmailVerification: false
69 },
70 admin: {
71 email: 'superadmin1@example.com'
72 },
73 contactForm: {
74 enabled: false
75 },
76 user: {
77 videoQuota: 5242881,
78 videoQuotaDaily: 318742
79 },
80 transcoding: {
81 enabled: true,
82 allowAdditionalExtensions: true,
83 allowAudioFiles: true,
84 threads: 1,
85 resolutions: {
86 '240p': false,
87 '360p': true,
88 '480p': true,
89 '720p': false,
90 '1080p': false,
91 '2160p': false
92 },
93 hls: {
94 enabled: false
95 }
96 },
97 import: {
98 videos: {
99 http: {
100 enabled: false
101 },
102 torrent: {
103 enabled: false
104 }
105 }
106 },
107 autoBlacklist: {
108 videos: {
109 ofUsers: {
110 enabled: false
111 }
112 }
113 },
114 followers: {
115 instance: {
116 enabled: false,
117 manualApproval: true
118 }
119 },
120 followings: {
121 instance: {
122 autoFollowBack: {
123 enabled: true
124 },
125 autoFollowIndex: {
126 enabled: true,
127 indexUrl: 'https://index.example.com'
128 }
129 }
130 }
131 }
132
133 // ---------------------------------------------------------------
134
135 before(async function () {
136 this.timeout(30000)
137
138 server = await flushAndRunServer(1)
139
140 await setAccessTokensToServers([ server ])
141
142 const user = {
143 username: 'user1',
144 password: 'password'
145 }
146 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
147 userAccessToken = await userLogin(server, user)
148 })
149
150 describe('When getting the configuration', function () {
151 it('Should fail without token', async function () {
152 await makeGetRequest({
153 url: server.url,
154 path,
155 statusCodeExpected: 401
156 })
157 })
158
159 it('Should fail if the user is not an administrator', async function () {
160 await makeGetRequest({
161 url: server.url,
162 path,
163 token: userAccessToken,
164 statusCodeExpected: 403
165 })
166 })
167 })
168
169 describe('When updating the configuration', function () {
170 it('Should fail without token', async function () {
171 await makePutBodyRequest({
172 url: server.url,
173 path,
174 fields: updateParams,
175 statusCodeExpected: 401
176 })
177 })
178
179 it('Should fail if the user is not an administrator', async function () {
180 await makePutBodyRequest({
181 url: server.url,
182 path,
183 fields: updateParams,
184 token: userAccessToken,
185 statusCodeExpected: 403
186 })
187 })
188
189 it('Should fail if it misses a key', async function () {
190 const newUpdateParams = omit(updateParams, 'admin.email')
191
192 await makePutBodyRequest({
193 url: server.url,
194 path,
195 fields: newUpdateParams,
196 token: server.accessToken,
197 statusCodeExpected: 400
198 })
199 })
200
201 it('Should fail with a bad default NSFW policy', async function () {
202 const newUpdateParams = immutableAssign(updateParams, {
203 instance: {
204 defaultNSFWPolicy: 'hello'
205 }
206 })
207
208 await makePutBodyRequest({
209 url: server.url,
210 path,
211 fields: newUpdateParams,
212 token: server.accessToken,
213 statusCodeExpected: 400
214 })
215 })
216
217 it('Should fail if email disabled and signup requires email verification', async function () {
218 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
219 const newUpdateParams = immutableAssign(updateParams, {
220 signup: {
221 enabled: true,
222 limit: 5,
223 requiresEmailVerification: true
224 }
225 })
226
227 await makePutBodyRequest({
228 url: server.url,
229 path,
230 fields: newUpdateParams,
231 token: server.accessToken,
232 statusCodeExpected: 400
233 })
234 })
235
236 it('Should success with the correct parameters', async function () {
237 await makePutBodyRequest({
238 url: server.url,
239 path,
240 fields: updateParams,
241 token: server.accessToken,
242 statusCodeExpected: 200
243 })
244 })
245 })
246
247 describe('When deleting the configuration', function () {
248 it('Should fail without token', async function () {
249 await makeDeleteRequest({
250 url: server.url,
251 path,
252 statusCodeExpected: 401
253 })
254 })
255
256 it('Should fail if the user is not an administrator', async function () {
257 await makeDeleteRequest({
258 url: server.url,
259 path,
260 token: userAccessToken,
261 statusCodeExpected: 403
262 })
263 })
264 })
265
266 after(async function () {
267 await cleanupTests([ server ])
268 })
269 })