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